shithub: aubio

Download patch

ref: 916f898309181aaf2c5a1b6280737816b84b6dcf
parent: 258195f8cf3aff3e626f5482e6a7a5c07f3e5692
author: Paul Brossier <piem@piem.org>
date: Mon Sep 28 17:09:22 EDT 2009

src/vecutils.{c,h}: add a bunch of function to modify fvec and cvec, defined with some magic macros

--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@
 	lvec.h \
 	cvec.h \
 	mathutils.h \
+	vecutils.h \
 	utils/hist.h \
 	utils/scale.h \
 	temporal/resample.h \
@@ -43,6 +44,7 @@
 	lvec.c \
 	cvec.c \
 	mathutils.c \
+	vecutils.c \
 	utils/hist.c \
 	utils/scale.c \
 	temporal/resample.c \
--- /dev/null
+++ b/src/vecutils.c
@@ -1,0 +1,44 @@
+#include "config.h"
+#include "types.h"
+#include "fvec.h"
+#include "cvec.h"
+#include "aubio_priv.h"
+#include "vecutils.h"
+
+#define AUBIO_OP(OPNAME, OP, TYPE, OBJ) \
+void TYPE ## _ ## OPNAME (TYPE ## _t *o) \
+{ \
+  uint_t i,j; \
+  for (i = 0; i < o->channels; i++) { \
+    for (j = 0; j < o->length; j++) { \
+      o->OBJ[i][j] = OP (o->OBJ[i][j]); \
+    } \
+  } \
+}
+
+#define AUBIO_OP_C_AND_F(OPNAME, OP) \
+  AUBIO_OP(OPNAME, OP, fvec, data) \
+  AUBIO_OP(OPNAME, OP, cvec, norm)
+
+AUBIO_OP_C_AND_F(exp, EXP)
+AUBIO_OP_C_AND_F(cos, COS)
+AUBIO_OP_C_AND_F(sin, SIN)
+AUBIO_OP_C_AND_F(abs, ABS)
+AUBIO_OP_C_AND_F(sqrt, SQRT)
+AUBIO_OP_C_AND_F(log10, SAFELOG10)
+AUBIO_OP_C_AND_F(log, SAFELOG)
+AUBIO_OP_C_AND_F(floor, FLOOR)
+AUBIO_OP_C_AND_F(ceil, CEIL)
+AUBIO_OP_C_AND_F(round, ROUND)
+
+//AUBIO_OP_C_AND_F(pow, POW)
+void fvec_pow (fvec_t *s, smpl_t power)
+{
+  uint_t i,j;
+  for (i = 0; i < s->channels; i++) {
+    for (j = 0; j < s->length; j++) {
+      s->data[i][j] = POW(s->data[i][j], power);
+    }
+  }
+}
+
--- /dev/null
+++ b/src/vecutils.h
@@ -1,0 +1,66 @@
+/*
+  Copyright (C) 2009 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+/** @file
+ *  various utilities functions for fvec and cvec objects
+ *
+ */
+
+#ifndef _VECUTILS_H
+#define _VECUTILS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define AUBIO_OP_PROTO(OPNAME, TYPE) \
+void TYPE ## _ ## OPNAME (TYPE ## _t *o);
+
+#define AUBIO_OP_C_AND_F_PROTO(OPNAME) \
+  AUBIO_OP_PROTO(OPNAME, fvec) \
+  AUBIO_OP_PROTO(OPNAME, cvec)
+
+AUBIO_OP_C_AND_F_PROTO(exp)
+AUBIO_OP_C_AND_F_PROTO(cos)
+AUBIO_OP_C_AND_F_PROTO(sin)
+AUBIO_OP_C_AND_F_PROTO(abs)
+//AUBIO_OP_C_AND_F_PROTO(pow)
+AUBIO_OP_C_AND_F_PROTO(sqrt)
+AUBIO_OP_C_AND_F_PROTO(log10)
+AUBIO_OP_C_AND_F_PROTO(log)
+AUBIO_OP_C_AND_F_PROTO(floor)
+AUBIO_OP_C_AND_F_PROTO(ceil)
+AUBIO_OP_C_AND_F_PROTO(round)
+
+/** raise each vector elements to the power pow
+
+  \param s vector to modify
+  \param pow power to raise to
+
+*/
+void fvec_pow (fvec_t *s, smpl_t pow);
+
+//void fvec_log10 (fvec_t *s);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_VECUTILS_H*/