ref: 39a7b26d00a5898b87643043304c634b66d1e7ad
parent: 923a7a8011ed28c4759b62e70598d3de91f5eeec
author: Paul Brossier <[email protected]>
date: Tue Nov 26 15:09:06 EST 2013
src/cvec.h: improve cvec_t api
--- a/src/cvec.c
+++ b/src/cvec.c
@@ -70,18 +70,63 @@
AUBIO_MSG("\n");
}
-void cvec_set(cvec_t *s, smpl_t val) {
+void cvec_copy(cvec_t *s, cvec_t *t) {
+ if (s->length != t->length) {
+ AUBIO_ERR("trying to copy %d elements to %d elements \n",
+ s->length, t->length);
+ return;
+ }
+#if HAVE_MEMCPY_HACKS
+ memcpy(t->norm, s->norm, t->length * sizeof(smpl_t));
+ memcpy(t->phas, s->phas, t->length * sizeof(smpl_t));
+#else
uint_t j;
+ for (j=0; j< t->length; j++) {
+ t->norm[j] = s->norm[j];
+ t->phas[j] = s->phas[j];
+ }
+#endif
+}
+
+void cvec_set_all_norm(cvec_t *s, smpl_t val) {
+ uint_t j;
for (j=0; j< s->length; j++) {
s->norm[j] = val;
}
}
-void cvec_zeros(cvec_t *s) {
- cvec_set(s, 0.);
+void cvec_zeros_norm(cvec_t *s) {
+#if HAVE_MEMCPY_HACKS
+ memset(s->norm, 0, s->length * sizeof(smpl_t));
+#else
+ cvec_set_all_norm(s, 0.);
+#endif
}
-void cvec_ones(cvec_t *s) {
- cvec_set(s, 1.);
+void cvec_ones_norm(cvec_t *s) {
+ cvec_set_all_norm(s, 1.);
}
+void cvec_set_all_phas(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) {
+#if HAVE_MEMCPY_HACKS
+ memset(s->phas, 0, s->length * sizeof(smpl_t));
+#else
+ cvec_set_all_phas(s, 0.);
+#endif
+}
+
+void cvec_ones_phas(cvec_t *s) {
+ cvec_set_all_phas(s, 1.);
+}
+
+void cvec_zeros(cvec_t *s) {
+ cvec_zeros_norm(s);
+ cvec_zeros_phas(s);
+}
--- a/src/cvec.h
+++ b/src/cvec.h
@@ -158,27 +158,64 @@
*/
void cvec_print(cvec_t *s);
-/** set all elements to a given value
+/** make a copy of a vector
+ \param s source vector
+ \param t vector to copy to
+
+*/
+void cvec_copy(cvec_t *s, cvec_t *t);
+
+/** set all norm elements to a given value
+
\param s vector to modify
\param val value to set elements to
*/
-void cvec_set(cvec_t *s, smpl_t val);
+void cvec_set_all_norm(cvec_t *s, smpl_t val);
-/** set all elements to zero
+/** set all norm elements to zero
\param s vector to modify
*/
-void cvec_zeros(cvec_t *s);
+void cvec_zeros_norm(cvec_t *s);
-/** set all elements to ones
+/** set all norm elements to one
\param s vector to modify
*/
-void cvec_ones(cvec_t *s);
+void cvec_ones_norm(cvec_t *s);
+
+/** set all phase elements to a given value
+
+ \param s vector to modify
+ \param val value to set elements to
+
+*/
+void cvec_set_all_phas(cvec_t *s, smpl_t val);
+
+/** set all phase elements to zero
+
+ \param s vector to modify
+
+*/
+void cvec_zeros_phas(cvec_t *s);
+
+/** set all phase elements to one
+
+ \param s vector to modify
+
+*/
+void cvec_ones_phas(cvec_t *s);
+
+/** set all norm and phas elements to zero
+
+ \param s vector to modify
+
+*/
+void cvec_zeros(cvec_t *s);
#ifdef __cplusplus
}
--- a/tests/src/spectral/test-mfcc.c
+++ b/tests/src/spectral/test-mfcc.c
@@ -12,11 +12,11 @@
// create mfcc object
aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coefs, samplerate);
- cvec_set (in, 1.);
+ cvec_set_all_norm (in, 1.);
aubio_mfcc_do (o, in, out);
fvec_print (out);
- cvec_set (in, .5);
+ cvec_set_all_norm (in, .5);
aubio_mfcc_do (o, in, out);
fvec_print (out);
--- a/tests/src/test-cvec.c
+++ b/tests/src/test-cvec.c
@@ -19,7 +19,7 @@
}
// set all vector elements to `0`
- cvec_zeros(complex_vector);
+ cvec_zeros_norm(complex_vector);
for ( i = 0; i < complex_vector->length; i++ ) {
assert( complex_vector->norm[i] == 0. );
// assert( complex_vector->phas[i] == 0 );
@@ -27,12 +27,20 @@
cvec_print(complex_vector);
// set all vector elements to `1`
- cvec_ones(complex_vector);
+ cvec_ones_norm(complex_vector);
for ( i = 0; i < complex_vector->length; i++ ) {
assert( complex_vector->norm[i] == 1. );
// assert( complex_vector->phas[i] == 0 );
}
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_copy(complex_vector, complex_vector);
+
// destroy it
del_cvec(complex_vector);
return 0;