Changeset 39a7b26


Ignore:
Timestamp:
Nov 26, 2013, 8:09:06 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
88fee8f
Parents:
923a7a8
Message:

src/cvec.h: improve cvec_t api

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/cvec.c

    r923a7a8 r39a7b26  
    7171}
    7272
    73 void cvec_set(cvec_t *s, smpl_t val) {
     73void cvec_copy(cvec_t *s, cvec_t *t) {
     74  if (s->length != t->length) {
     75    AUBIO_ERR("trying to copy %d elements to %d elements \n",
     76        s->length, t->length);
     77    return;
     78  }
     79#if HAVE_MEMCPY_HACKS
     80  memcpy(t->norm, s->norm, t->length * sizeof(smpl_t));
     81  memcpy(t->phas, s->phas, t->length * sizeof(smpl_t));
     82#else
     83  uint_t j;
     84  for (j=0; j< t->length; j++) {
     85    t->norm[j] = s->norm[j];
     86    t->phas[j] = s->phas[j];
     87  }
     88#endif
     89}
     90
     91void cvec_set_all_norm(cvec_t *s, smpl_t val) {
    7492  uint_t j;
    7593  for (j=0; j< s->length; j++) {
     
    7896}
    7997
    80 void cvec_zeros(cvec_t *s) {
    81   cvec_set(s, 0.);
     98void cvec_zeros_norm(cvec_t *s) {
     99#if HAVE_MEMCPY_HACKS
     100  memset(s->norm, 0, s->length * sizeof(smpl_t));
     101#else
     102  cvec_set_all_norm(s, 0.);
     103#endif
    82104}
    83105
    84 void cvec_ones(cvec_t *s) {
    85   cvec_set(s, 1.);
     106void cvec_ones_norm(cvec_t *s) {
     107  cvec_set_all_norm(s, 1.);
    86108}
    87109
     110void cvec_set_all_phas(cvec_t *s, smpl_t val) {
     111  uint_t j;
     112  for (j=0; j< s->length; j++) {
     113    s->phas[j] = val;
     114  }
     115}
     116
     117void cvec_zeros_phas(cvec_t *s) {
     118#if HAVE_MEMCPY_HACKS
     119  memset(s->phas, 0, s->length * sizeof(smpl_t));
     120#else
     121  cvec_set_all_phas(s, 0.);
     122#endif
     123}
     124
     125void cvec_ones_phas(cvec_t *s) {
     126  cvec_set_all_phas(s, 1.);
     127}
     128
     129void cvec_zeros(cvec_t *s) {
     130  cvec_zeros_norm(s);
     131  cvec_zeros_phas(s);
     132}
  • src/cvec.h

    r923a7a8 r39a7b26  
    159159void cvec_print(cvec_t *s);
    160160
    161 /** set all elements to a given value
     161/** make a copy of a vector
     162
     163  \param s source vector
     164  \param t vector to copy to
     165
     166*/
     167void cvec_copy(cvec_t *s, cvec_t *t);
     168
     169/** set all norm elements to a given value
    162170
    163171  \param s vector to modify
     
    165173
    166174*/
    167 void cvec_set(cvec_t *s, smpl_t val);
    168 
    169 /** set all elements to zero
     175void cvec_set_all_norm(cvec_t *s, smpl_t val);
     176
     177/** set all norm elements to zero
     178
     179  \param s vector to modify
     180
     181*/
     182void cvec_zeros_norm(cvec_t *s);
     183
     184/** set all norm elements to one
     185
     186  \param s vector to modify
     187
     188*/
     189void cvec_ones_norm(cvec_t *s);
     190
     191/** set all phase elements to a given value
     192
     193  \param s vector to modify
     194  \param val value to set elements to
     195
     196*/
     197void cvec_set_all_phas(cvec_t *s, smpl_t val);
     198
     199/** set all phase elements to zero
     200
     201  \param s vector to modify
     202
     203*/
     204void cvec_zeros_phas(cvec_t *s);
     205
     206/** set all phase elements to one
     207
     208  \param s vector to modify
     209
     210*/
     211void cvec_ones_phas(cvec_t *s);
     212
     213/** set all norm and phas elements to zero
    170214
    171215  \param s vector to modify
     
    173217*/
    174218void cvec_zeros(cvec_t *s);
    175 
    176 /** set all elements to ones
    177 
    178   \param s vector to modify
    179 
    180 */
    181 void cvec_ones(cvec_t *s);
    182219
    183220#ifdef __cplusplus
  • tests/src/spectral/test-mfcc.c

    r923a7a8 r39a7b26  
    1313  aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coefs, samplerate);
    1414
    15   cvec_set (in, 1.);
     15  cvec_set_all_norm (in, 1.);
    1616  aubio_mfcc_do (o, in, out);
    1717  fvec_print (out);
    1818
    19   cvec_set (in, .5);
     19  cvec_set_all_norm (in, .5);
    2020  aubio_mfcc_do (o, in, out);
    2121  fvec_print (out);
  • tests/src/test-cvec.c

    r923a7a8 r39a7b26  
    2020
    2121  // set all vector elements to `0`
    22   cvec_zeros(complex_vector);
     22  cvec_zeros_norm(complex_vector);
    2323  for ( i = 0; i < complex_vector->length; i++ ) {
    2424    assert( complex_vector->norm[i] == 0. );
     
    2828
    2929  // set all vector elements to `1`
    30   cvec_ones(complex_vector);
     30  cvec_ones_norm(complex_vector);
    3131  for ( i = 0; i < complex_vector->length; i++ ) {
    3232    assert( complex_vector->norm[i] == 1. );
     
    3434  }
    3535  cvec_print(complex_vector);
     36
     37  cvec_zeros(complex_vector);
     38  cvec_zeros_phas(complex_vector);
     39  cvec_zeros_norm(complex_vector);
     40  cvec_ones_norm(complex_vector);
     41  cvec_ones_phas(complex_vector);
     42  cvec_copy(complex_vector, complex_vector);
     43
    3644  // destroy it
    3745  del_cvec(complex_vector);
Note: See TracChangeset for help on using the changeset viewer.