From 5d10ac1882948152e9628c6fea144137274d607c Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 17 Dec 2013 11:11:35 -0500 Subject: [PATCH] src/cvec.h: clean up cvec api --- src/cvec.c | 41 ++++++++++++--------- src/cvec.h | 83 ++++++++++++++++++++++++------------------ tests/src/spectral/test-mfcc.c | 4 +- tests/src/test-cvec.c | 12 +++--- 4 files changed, 79 insertions(+), 61 deletions(-) diff --git a/src/cvec.c b/src/cvec.c index 3439810b..1b60ed49 100644 --- a/src/cvec.c +++ b/src/cvec.c @@ -38,22 +38,27 @@ void del_cvec(cvec_t *s) { AUBIO_FREE(s); } -void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position) { +void cvec_norm_set_sample (cvec_t *s, smpl_t data, uint_t position) { s->norm[position] = data; } -void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position) { + +void cvec_phas_set_sample (cvec_t *s, smpl_t data, uint_t position) { s->phas[position] = data; } -smpl_t cvec_read_norm(cvec_t *s, uint_t position) { + +smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position) { return s->norm[position]; } -smpl_t cvec_read_phas(cvec_t *s, uint_t position) { + +smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position) { return s->phas[position]; } -smpl_t * cvec_get_norm(cvec_t *s) { + +smpl_t * cvec_norm_get_data (cvec_t *s) { return s->norm; } -smpl_t * cvec_get_phas(cvec_t *s) { + +smpl_t * cvec_phas_get_data (cvec_t *s) { return s->phas; } @@ -91,45 +96,45 @@ void cvec_copy(cvec_t *s, cvec_t *t) { #endif } -void cvec_set_all_norm(cvec_t *s, smpl_t val) { +void cvec_norm_set_all (cvec_t *s, smpl_t val) { uint_t j; for (j=0; j< s->length; j++) { s->norm[j] = val; } } -void cvec_zeros_norm(cvec_t *s) { +void cvec_norm_zeros(cvec_t *s) { #if HAVE_MEMCPY_HACKS memset(s->norm, 0, s->length * sizeof(smpl_t)); #else - cvec_set_all_norm(s, 0.); + cvec_norm_set_all (s, 0.); #endif } -void cvec_ones_norm(cvec_t *s) { - cvec_set_all_norm(s, 1.); +void cvec_norm_ones(cvec_t *s) { + cvec_norm_set_all (s, 1.); } -void cvec_set_all_phas(cvec_t *s, smpl_t val) { +void cvec_phas_set_all (cvec_t *s, smpl_t val) { uint_t j; for (j=0; j< s->length; j++) { s->phas[j] = val; } } -void cvec_zeros_phas(cvec_t *s) { +void cvec_phas_zeros(cvec_t *s) { #if HAVE_MEMCPY_HACKS memset(s->phas, 0, s->length * sizeof(smpl_t)); #else - cvec_set_all_phas(s, 0.); + cvec_phas_set_all (s, 0.); #endif } -void cvec_ones_phas(cvec_t *s) { - cvec_set_all_phas(s, 1.); +void cvec_phas_ones(cvec_t *s) { + cvec_phas_set_all (s, 1.); } void cvec_zeros(cvec_t *s) { - cvec_zeros_norm(s); - cvec_zeros_phas(s); + cvec_norm_zeros(s); + cvec_phas_zeros(s); } diff --git a/src/cvec.h b/src/cvec.h index 8cff648d..5db26beb 100644 --- a/src/cvec.h +++ b/src/cvec.h @@ -27,17 +27,17 @@ extern "C" { /** \file - Vector of complex-valued data + Vector of complex-valued data, stored in polar coordinates This file specifies the ::cvec_t buffer type, which is used throughout aubio to store complex data. Complex values are stored in terms of ::cvec_t.phas - and norm, within size/2+1 long vectors of ::smpl_t. + and norm, within 2 vectors of ::smpl_t of size (size/2+1) each. \example test-cvec.c */ -/** Buffer for complex data +/** Vector of real-valued phase and spectrum data \code @@ -78,78 +78,91 @@ typedef struct { */ cvec_t * new_cvec(uint_t length); + /** cvec_t buffer deletion function \param s buffer to delete as returned by new_cvec() */ void del_cvec(cvec_t *s); + /** write norm value in a complex buffer - Note that this function is not used in the aubio library, since the same - result can be obtained by assigning vec->norm[position]. Its purpose - is to access these values from wrappers, as created by swig. + This is equivalent to: + \code + s->norm[position] = val; + \endcode \param s vector to write to - \param data norm value to write in s->norm[position] + \param val norm value to write in s->norm[position] \param position sample position to write to */ -void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position); +void cvec_norm_set_sample (cvec_t *s, smpl_t val, uint_t position); + /** write phase value in a complex buffer - Note that this function is not used in the aubio library, since the same - result can be obtained by assigning vec->phas[position]. Its purpose - is to access these values from wrappers, as created by swig. + This is equivalent to: + \code + s->phas[position] = val; + \endcode \param s vector to write to - \param data phase value to write in s->phas[position] + \param val phase value to write in s->phas[position] \param position sample position to write to */ -void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position); +void cvec_phas_set_sample (cvec_t *s, smpl_t val, uint_t position); + /** read norm value from a complex buffer - Note that this function is not used in the aubio library, since the same - result can be obtained with vec->norm[position]. Its purpose is to - access these values from wrappers, as created by swig. + This is equivalent to: + \code + smpl_t foo = s->norm[position]; + \endcode \param s vector to read from \param position sample position to read from */ -smpl_t cvec_read_norm(cvec_t *s, uint_t position); +smpl_t cvec_norm_get_sample (cvec_t *s, uint_t position); + /** read phase value from a complex buffer - Note that this function is not used in the aubio library, since the same - result can be obtained with vec->phas[position]. Its purpose is to - access these values from wrappers, as created by swig. + This is equivalent to: + \code + smpl_t foo = s->phas[position]; + \endcode \param s vector to read from \param position sample position to read from + \returns the value of the sample at position */ -smpl_t cvec_read_phas(cvec_t *s, uint_t position); +smpl_t cvec_phas_get_sample (cvec_t *s, uint_t position); + /** read norm data from a complex buffer - Note that this function is not used in the aubio library, since the same - result can be obtained with vec->norm. Its purpose is to access these values - from wrappers, as created by swig. + \code + smpl_t *data = s->norm; + \endcode \param s vector to read from */ -smpl_t * cvec_get_norm(cvec_t *s); +smpl_t * cvec_norm_get_data (cvec_t *s); + /** read phase data from a complex buffer - Note that this function is not used in the aubio library, since the same - result can be obtained with vec->phas. Its purpose is to access these values - from wrappers, as created by swig. + This is equivalent to: + \code + smpl_t *data = s->phas; + \endcode \param s vector to read from */ -smpl_t * cvec_get_phas(cvec_t *s); +smpl_t * cvec_phas_get_data (cvec_t *s); /** print out cvec data @@ -172,21 +185,21 @@ void cvec_copy(cvec_t *s, cvec_t *t); \param val value to set elements to */ -void cvec_set_all_norm(cvec_t *s, smpl_t val); +void cvec_norm_set_all (cvec_t *s, smpl_t val); /** set all norm elements to zero \param s vector to modify */ -void cvec_zeros_norm(cvec_t *s); +void cvec_norm_zeros(cvec_t *s); /** set all norm elements to one \param s vector to modify */ -void cvec_ones_norm(cvec_t *s); +void cvec_norm_ones(cvec_t *s); /** set all phase elements to a given value @@ -194,21 +207,21 @@ void cvec_ones_norm(cvec_t *s); \param val value to set elements to */ -void cvec_set_all_phas(cvec_t *s, smpl_t val); +void cvec_phas_set_all (cvec_t *s, smpl_t val); /** set all phase elements to zero \param s vector to modify */ -void cvec_zeros_phas(cvec_t *s); +void cvec_phas_zeros(cvec_t *s); /** set all phase elements to one \param s vector to modify */ -void cvec_ones_phas(cvec_t *s); +void cvec_phas_ones(cvec_t *s); /** set all norm and phas elements to zero diff --git a/tests/src/spectral/test-mfcc.c b/tests/src/spectral/test-mfcc.c index 69829d6e..a2d4d58f 100644 --- a/tests/src/spectral/test-mfcc.c +++ b/tests/src/spectral/test-mfcc.c @@ -12,11 +12,11 @@ int main () // create mfcc object aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coefs, samplerate); - cvec_set_all_norm (in, 1.); + cvec_norm_set_all (in, 1.); aubio_mfcc_do (o, in, out); fvec_print (out); - cvec_set_all_norm (in, .5); + cvec_norm_set_all (in, .5); aubio_mfcc_do (o, in, out); fvec_print (out); diff --git a/tests/src/test-cvec.c b/tests/src/test-cvec.c index 51bbc8a5..9b02d122 100644 --- a/tests/src/test-cvec.c +++ b/tests/src/test-cvec.c @@ -19,7 +19,7 @@ int main () } // set all vector elements to `0` - cvec_zeros_norm(complex_vector); + cvec_norm_zeros(complex_vector); for ( i = 0; i < complex_vector->length; i++ ) { assert( complex_vector->norm[i] == 0. ); // assert( complex_vector->phas[i] == 0 ); @@ -27,7 +27,7 @@ int main () cvec_print(complex_vector); // set all vector elements to `1` - cvec_ones_norm(complex_vector); + cvec_norm_ones(complex_vector); for ( i = 0; i < complex_vector->length; i++ ) { assert( complex_vector->norm[i] == 1. ); // assert( complex_vector->phas[i] == 0 ); @@ -35,10 +35,10 @@ int main () cvec_print(complex_vector); cvec_zeros(complex_vector); - cvec_zeros_phas(complex_vector); - cvec_zeros_norm(complex_vector); - cvec_ones_norm(complex_vector); - cvec_ones_phas(complex_vector); + cvec_phas_zeros(complex_vector); + cvec_norm_zeros(complex_vector); + cvec_norm_ones(complex_vector); + cvec_phas_ones(complex_vector); cvec_copy(complex_vector, complex_vector); // destroy it -- 2.11.0