From 916f898309181aaf2c5a1b6280737816b84b6dcf Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Mon, 28 Sep 2009 21:09:22 +0200 Subject: [PATCH] src/vecutils.{c,h}: add a bunch of function to modify fvec and cvec, defined with some magic macros --- src/Makefile.am | 2 ++ src/vecutils.c | 44 +++++++++++++++++++++++++++++++++ src/vecutils.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 src/vecutils.c create mode 100644 src/vecutils.h diff --git a/src/Makefile.am b/src/Makefile.am index 4363fdf5..cb89ee44 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,6 +9,7 @@ nobase_pkginclude_HEADERS = \ lvec.h \ cvec.h \ mathutils.h \ + vecutils.h \ utils/hist.h \ utils/scale.h \ temporal/resample.h \ @@ -43,6 +44,7 @@ libaubio_la_SOURCES = \ lvec.c \ cvec.c \ mathutils.c \ + vecutils.c \ utils/hist.c \ utils/scale.c \ temporal/resample.c \ diff --git a/src/vecutils.c b/src/vecutils.c new file mode 100644 index 00000000..2ac65270 --- /dev/null +++ b/src/vecutils.c @@ -0,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); + } + } +} + diff --git a/src/vecutils.h b/src/vecutils.h new file mode 100644 index 00000000..ecc69131 --- /dev/null +++ b/src/vecutils.h @@ -0,0 +1,66 @@ +/* + Copyright (C) 2009 Paul Brossier + + 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 . + +*/ + +/** @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*/ -- 2.26.2