src/cvec.h: clean up cvec api
authorPaul Brossier <piem@piem.org>
Tue, 17 Dec 2013 16:11:35 +0000 (11:11 -0500)
committerPaul Brossier <piem@piem.org>
Tue, 17 Dec 2013 16:11:35 +0000 (11:11 -0500)
src/cvec.c
src/cvec.h
tests/src/spectral/test-mfcc.c
tests/src/test-cvec.c

index 3439810..1b60ed4 100644 (file)
@@ -38,22 +38,27 @@ void del_cvec(cvec_t *s) {
   AUBIO_FREE(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;
 }
   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;
 }
   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];
 }
   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];
 }
   return s->phas[position];
 }
-smpl_t * cvec_get_norm(cvec_t *s) {
+
+smpl_t * cvec_norm_get_data (cvec_t *s) {
   return s->norm;
 }
   return s->norm;
 }
-smpl_t * cvec_get_phas(cvec_t *s) {
+
+smpl_t * cvec_phas_get_data (cvec_t *s) {
   return s->phas;
 }
 
   return s->phas;
 }
 
@@ -91,45 +96,45 @@ void cvec_copy(cvec_t *s, cvec_t *t) {
 #endif
 }
 
 #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;
   }
 }
 
   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
 #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
 }
 
 #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;
   }
 }
 
   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
 #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
 }
 
 #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) {
 }
 
 void cvec_zeros(cvec_t *s) {
-  cvec_zeros_norm(s);
-  cvec_zeros_phas(s);
+  cvec_norm_zeros(s);
+  cvec_phas_zeros(s);
 }
 }
index 8cff648..5db26be 100644 (file)
@@ -27,17 +27,17 @@ extern "C" {
 
 /** \file
 
 
 /** \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
 
   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
 
 */
 
 
   \example test-cvec.c
 
 */
 
-/** Buffer for complex data
+/** Vector of real-valued phase and spectrum data
 
   \code
 
 
   \code
 
@@ -78,78 +78,91 @@ typedef struct {
 
 */
 cvec_t * new_cvec(uint_t length);
 
 */
 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);
 /** 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
 
 /** 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 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
 
 */
   \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
 
 /** 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 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
 
 */
   \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
 
 /** 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
 
 */
 
   \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
 
 /** 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
 
   \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
 
 /** 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
 
 */
 
   \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
 
 /** 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
 
 */
 
   \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
 
 
 /** print out cvec data
 
@@ -172,21 +185,21 @@ void cvec_copy(cvec_t *s, cvec_t *t);
   \param val value to set elements to
 
 */
   \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
 
 */
 
 /** 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
 
 */
 
 /** 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
 
 
 /** 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
 
 */
   \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
 
 */
 
 /** 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
 
 */
 
 /** 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
 
 
 /** set all norm and phas elements to zero
 
index 69829d6..a2d4d58 100644 (file)
@@ -12,11 +12,11 @@ int main ()
   // create mfcc object
   aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coefs, samplerate);
 
   // 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);
 
   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);
 
   aubio_mfcc_do (o, in, out);
   fvec_print (out);
 
index 51bbc8a..9b02d12 100644 (file)
@@ -19,7 +19,7 @@ int main ()
   }
 
   // set all vector elements to `0`
   }
 
   // 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 );
   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_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 );
   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_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
   cvec_copy(complex_vector, complex_vector);
 
   // destroy it