Changeset 439ba7b for tests


Ignore:
Timestamp:
Apr 1, 2019, 1:30:06 AM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
7a02ce9
Parents:
5f57ea9 (diff), f55630c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feature/pitchshift

Location:
tests/src
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • tests/src/io/base-sink_custom.h

    r5f57ea9 r439ba7b  
    152152  close_temp_sink(sink_path, fd);
    153153
     154  // shouldn't crash on null (bypassed, only check del_aubio_sink)
     155  // del_aubio_sink_custom(NULL);
     156
    154157  return run_on_default_source_and_sink(base_main);
    155158}
  • tests/src/io/base-source_custom.h

    r5f57ea9 r439ba7b  
    9494  if (read != hop_size) return 1;
    9595
     96  // read again in undersized vector
     97  del_fvec(vec);
     98  vec = new_fvec(hop_size - 1);
     99  aubio_source_custom_do(s, vec, &read);
     100  if (read != hop_size - 1) return 1;
     101
     102  // read again in oversized vector
     103  del_fvec(vec);
     104  vec = new_fvec(hop_size + 1);
     105  aubio_source_custom_do(s, vec, &read);
     106  if (read != hop_size) return 1;
     107
    96108  // seek to 0
    97109  if(aubio_source_custom_seek(s, 0)) return 1;
    98110
    99111  // read again as multiple channels
     112  aubio_source_custom_do_multi(s, mat, &read);
     113  if (read != hop_size) return 1;
     114
     115  // read again as multiple channels in an undersized matrix
     116  del_fmat(mat);
     117  mat = new_fmat(channels - 1, hop_size);
     118  aubio_source_custom_do_multi(s, mat, &read);
     119  if (read != hop_size) return 1;
     120
     121  // read again as multiple channels in an undersized matrix
     122  del_fmat(mat);
     123  mat = new_fmat(channels, hop_size - 1);
     124  aubio_source_custom_do_multi(s, mat, &read);
     125  if (read != hop_size - 1) return 1;
     126
     127  // read again as multiple channels in an oversized matrix
     128  del_fmat(mat);
     129  mat = new_fmat(channels + 1, hop_size);
     130  aubio_source_custom_do_multi(s, mat, &read);
     131  if (read != hop_size) return 1;
     132
     133  // read again as multiple channels in an oversized matrix
     134  del_fmat(mat);
     135  mat = new_fmat(channels, hop_size + 1);
    100136  aubio_source_custom_do_multi(s, mat, &read);
    101137  if (read != hop_size) return 1;
     
    106142  aubio_source_custom_close(s);
    107143
     144  // reading after close fails
     145  del_fvec(vec);
     146  vec = new_fvec(hop_size);
     147  aubio_source_custom_do(s, vec, &read);
     148  del_fmat(mat);
     149  mat = new_fmat(channels, hop_size);
     150  aubio_source_custom_do_multi(s, mat, &read);
     151
    108152  del_aubio_source_custom(s);
    109153  del_fmat(mat);
    110154  del_fvec(vec);
     155
     156  // shouldn't crash on null (bypassed, only check del_aubio_source)
     157  // del_aubio_source_custom(NULL);
    111158
    112159  return run_on_default_source(base_main);
  • tests/src/io/test-sink.c

    r5f57ea9 r439ba7b  
    148148  close_temp_sink(sink_path, fd);
    149149
     150  // shouldn't crash on null
     151  del_aubio_sink(NULL);
     152
    150153  return run_on_default_source_and_sink(main);
    151154}
  • tests/src/io/test-source.c

    r5f57ea9 r439ba7b  
    9090  if (read != hop_size) return 1;
    9191
     92  // read again in undersized vector
     93  del_fvec(vec);
     94  vec = new_fvec(hop_size - 1);
     95  aubio_source_do(s, vec, &read);
     96  if (read != hop_size - 1) return 1;
     97
     98  // read again in oversized vector
     99  del_fvec(vec);
     100  vec = new_fvec(hop_size + 1);
     101  aubio_source_do(s, vec, &read);
     102  if (read != hop_size) return 1;
     103
    92104  // seek to 0
    93105  if(aubio_source_seek(s, 0)) return 1;
    94106
    95107  // read again as multiple channels
     108  aubio_source_do_multi(s, mat, &read);
     109  if (read != hop_size) return 1;
     110
     111  // read again as multiple channels in an undersized matrix
     112  del_fmat(mat);
     113  mat = new_fmat(channels - 1, hop_size);
     114  aubio_source_do_multi(s, mat, &read);
     115  if (read != hop_size) return 1;
     116
     117  // read again as multiple channels in an undersized matrix
     118  del_fmat(mat);
     119  mat = new_fmat(channels, hop_size - 1);
     120  aubio_source_do_multi(s, mat, &read);
     121  if (read != hop_size - 1) return 1;
     122
     123  // read again as multiple channels in an oversized matrix
     124  del_fmat(mat);
     125  mat = new_fmat(channels + 1, hop_size);
     126  aubio_source_do_multi(s, mat, &read);
     127  if (read != hop_size) return 1;
     128
     129  // read again as multiple channels in an oversized matrix
     130  del_fmat(mat);
     131  mat = new_fmat(channels, hop_size + 1);
    96132  aubio_source_do_multi(s, mat, &read);
    97133  if (read != hop_size) return 1;
     
    102138  aubio_source_close(s);
    103139
     140  // reading after close fails
     141  del_fvec(vec);
     142  vec = new_fvec(hop_size);
     143  aubio_source_do(s, vec, &read);
     144  del_fmat(mat);
     145  mat = new_fmat(channels, hop_size);
     146  aubio_source_do_multi(s, mat, &read);
     147
    104148  del_aubio_source(s);
    105149  del_fmat(mat);
    106150  del_fvec(vec);
    107151
     152  // shouldn't crash on null
     153  del_aubio_source(NULL);
     154
    108155  return run_on_default_source(main);
    109156}
  • tests/src/spectral/test-mfcc.c

    r5f57ea9 r439ba7b  
    3434  aubio_mfcc_t *mfcc = 0;
    3535
    36   fvec_t *in = new_fvec (win_s); // input buffer
    37   cvec_t *fftgrain = new_cvec (win_s); // input buffer
    38   fvec_t *out = new_fvec (n_coeffs); // output coefficients
     36  fvec_t *in = new_fvec (hop_s);       // phase vocoder input
     37  cvec_t *fftgrain = new_cvec (win_s); // pvoc output / mfcc input
     38  fvec_t *out = new_fvec (n_coeffs);   // mfcc output
    3939
    4040  if (!in || !fftgrain || !out) { err = 1; goto failure; }
  • tests/src/test-cvec.c

    r5f57ea9 r439ba7b  
    44int main (void)
    55{
    6   uint_t i, window_size = 16; // window size
    7   cvec_t * complex_vector = new_cvec (window_size); // input buffer
    8   uint_t rand_times = 4;
     6  uint_t i, window_size = 16;
     7  cvec_t * complex_vector = new_cvec(window_size);
     8  cvec_t * other_cvector = new_cvec(window_size);
    99
    10   utils_init_random();
     10  assert(cvec_norm_get_data(complex_vector) == complex_vector->norm);
     11  assert(cvec_phas_get_data(complex_vector) == complex_vector->phas);
     12  assert(complex_vector->length == window_size / 2 + 1);
    1113
    12   while (rand_times -- ) {
    13     // fill with random phas and norm
    14     for ( i = 0; i < complex_vector->length; i++ ) {
    15       complex_vector->norm[i] = ( 2. / RAND_MAX * random() - 1. );
    16       complex_vector->phas[i] = ( 2. / RAND_MAX * random() - 1. ) * M_PI;
    17     }
    18     // print the vector
    19     cvec_print(complex_vector);
     14  // all elements are initialized to 0
     15  for ( i = 0; i < complex_vector->length; i++ ) {
     16    assert( complex_vector->norm[i] == 0. );
     17    assert( complex_vector->phas[i] == 0. );
    2018  }
    2119
    22   // set all vector elements to `0`
     20  cvec_norm_set_sample(complex_vector, 2., 1);
     21  assert(cvec_norm_get_sample(complex_vector, 1));
     22
     23  cvec_phas_set_sample(complex_vector, 2., 1);
     24  assert(cvec_phas_get_sample(complex_vector, 1));
     25
     26  cvec_print(complex_vector);
     27
     28  // set all norm and phas elements to 0
     29  cvec_zeros(complex_vector);
     30  for ( i = 0; i < complex_vector->length; i++ ) {
     31    assert( complex_vector->norm[i] == 0. );
     32    assert( complex_vector->phas[i] == 0. );
     33  }
     34
     35  // set all norm elements to 1
     36  cvec_norm_ones(complex_vector);
     37  for ( i = 0; i < complex_vector->length; i++ ) {
     38    assert( complex_vector->norm[i] == 1. );
     39  }
     40
     41  // set all norm elements to 0
    2342  cvec_norm_zeros(complex_vector);
    2443  for ( i = 0; i < complex_vector->length; i++ ) {
    2544    assert( complex_vector->norm[i] == 0. );
    26     // assert( complex_vector->phas[i] == 0 );
    2745  }
    28   cvec_print(complex_vector);
    2946
    30   // set all vector elements to `1`
    31   cvec_norm_ones(complex_vector);
     47  // set all phas elements to 1
     48  cvec_phas_ones(complex_vector);
    3249  for ( i = 0; i < complex_vector->length; i++ ) {
    33     assert( complex_vector->norm[i] == 1. );
    34     // assert( complex_vector->phas[i] == 0 );
     50    assert( complex_vector->phas[i] == 1. );
    3551  }
    36   cvec_print(complex_vector);
    3752
    38   cvec_zeros(complex_vector);
     53  // set all phas elements to 0
    3954  cvec_phas_zeros(complex_vector);
    40   cvec_norm_zeros(complex_vector);
    41   cvec_norm_ones(complex_vector);
    42   cvec_phas_ones(complex_vector);
     55  for ( i = 0; i < complex_vector->length; i++ ) {
     56    assert( complex_vector->phas[i] == 0. );
     57  }
     58
     59  cvec_copy(complex_vector, other_cvector);
     60  // copy to self
    4361  cvec_copy(complex_vector, complex_vector);
     62  // copy to a different size fails
     63  del_cvec(other_cvector);
     64  other_cvector = new_cvec(window_size + 2);
     65  cvec_copy(complex_vector, other_cvector);
    4466
    45   // destroy it
    46   del_cvec(complex_vector);
     67  if (complex_vector)
     68    del_cvec(complex_vector);
     69  if (other_cvector)
     70    del_cvec(other_cvector);
     71
     72  // wrong parameters
     73  assert(new_cvec(-1) == NULL);
     74  assert(new_cvec(0) == NULL);
     75
    4776  return 0;
    4877}
  • tests/src/test-fmat.c

    r5f57ea9 r439ba7b  
    55// and j the column.
    66
     7void assert_fmat_all_equal(fmat_t *mat, smpl_t scalar)
     8{
     9  uint_t i, j;
     10  for ( i = 0; i < mat->height; i++ ) {
     11    for ( j = 0; j < mat->length; j++ ) {
     12      assert(mat->data[i][j] == scalar);
     13    }
     14  }
     15}
     16
    717int main (void)
    818{
    9   uint_t height = 3, length = 9, i, j;
     19  uint_t i, j;
     20  uint_t height = 3, length = 9;
     21
    1022  // create fmat_t object
    11   fmat_t * mat = new_fmat (height, length);
    12   for ( i = 0; i < mat->height; i++ ) {
    13     for ( j = 0; j < mat->length; j++ ) {
     23  fmat_t * mat = new_fmat(height, length);
     24  fmat_t * other_mat = new_fmat(height, length);
     25
     26  assert(mat);
     27  assert(other_mat);
     28
     29  assert(mat->length == length);
     30  assert(mat->height == height);
     31
     32  for (i = 0; i < mat->height; i++) {
     33    for (j = 0; j < mat->length; j++) {
    1434      // all elements are already initialized to 0.
    1535      assert(mat->data[i][j] == 0);
    1636      // setting element of row i, column j
    17       mat->data[i][j] = i * 1. + j *.1;
     37      mat->data[i][j] = i * 10. + j;
    1838    }
    1939  }
     40
     41  // print out matrix
     42  fmat_print(mat);
     43
     44  // helpers
     45  fmat_rev(mat);
     46  fmat_print(mat);
     47  for (i = 0; i < mat->height; i++) {
     48    for (j = 0; j < mat->length; j++) {
     49      assert(mat->data[i][j] == i * 10. + mat->length - 1. - j);
     50    }
     51  }
     52
     53  fmat_set_sample(mat, 3, 1, 1);
     54  assert(fmat_get_sample(mat, 1, 1) == 3.);
     55
     56  fmat_ones(mat);
     57  assert_fmat_all_equal(mat, 1.);
     58
     59  fmat_set(other_mat, .5);
     60  assert_fmat_all_equal(other_mat, .5);
     61
     62  fmat_weight(mat, other_mat);
     63  assert_fmat_all_equal(mat, .5);
     64
    2065  fvec_t channel_onstack;
    2166  fvec_t *channel = &channel_onstack;
    2267  fmat_get_channel(mat, 1, channel);
    23   fvec_print (channel);
    24   // print out matrix
    25   fmat_print(mat);
    26   // destroy it
    27   del_fmat(mat);
     68  assert(channel->data == mat->data[1]);
     69
     70  // copy of the same size
     71  fmat_copy(mat, other_mat);
     72  del_fmat(other_mat);
     73
     74  // copy to undersized
     75  other_mat = new_fmat(height - 1, length);
     76  fmat_copy(mat, other_mat);
     77  del_fmat(other_mat);
     78
     79  // copy from undersized
     80  other_mat = new_fmat(height, length + 1);
     81  fmat_copy(mat, other_mat);
     82
     83  // wrong parameters
     84  assert(new_fmat(-1, length) == NULL);
     85  assert(new_fmat(height, -1) == NULL);
     86
     87  // methods for wrappers with opaque structure
     88  assert (fmat_get_channel_data(mat, 0) == mat->data[0]);
     89  assert (fmat_get_data(mat) == mat->data);
     90
     91  if (mat)
     92    del_fmat(mat);
     93  if (other_mat)
     94    del_fmat(other_mat);
    2895  return 0;
    2996}
    30 
  • tests/src/test-fvec.c

    r5f57ea9 r439ba7b  
    22#include "utils_tests.h"
    33
     4void assert_fvec_all_equal(fvec_t *vec, smpl_t scalar)
     5{
     6  uint_t i;
     7  for (i = 0; i < vec->length; i++) {
     8    assert(vec->data[i] == scalar);
     9  }
     10}
     11
    412int main (void)
    513{
    6   uint_t vec_size = 10, i;
    7   fvec_t * vec = new_fvec (vec_size);
     14  uint_t length = 10;
     15  uint_t i;
     16
     17  fvec_t * vec = new_fvec (length);
     18  fvec_t * other_vec = new_fvec (length);
     19
     20  assert (vec);
     21  assert (other_vec);
    822
    923  // vec->length matches requested size
    10   assert(vec->length == vec_size);
     24  assert(vec->length == length);
    1125
    1226  // all elements are initialized to `0.`
     
    1529  }
    1630
     31  // all elements can be set to `1.`
     32  fvec_ones(vec);
     33  assert_fvec_all_equal(vec, 1.);
     34
    1735  // all elements can be set to `0.`
    1836  fvec_zeros(vec);
    19   for ( i = 0; i < vec->length; i++ ) {
    20     assert(vec->data[i] == 0.);
    21   }
    22   fvec_print(vec);
    23 
    24   // all elements can be set to `1.`
    25   fvec_ones(vec);
    26   for ( i = 0; i < vec->length; i++ ) {
    27     assert(vec->data[i] == 1.);
    28   }
    29   fvec_print(vec);
     37  assert_fvec_all_equal(vec, 0.);
    3038
    3139  // each element can be accessed directly
     
    3644  fvec_print(vec);
    3745
     46  fvec_set_sample(vec, 3, 2);
     47  assert(fvec_get_sample(vec, 2) == 3);
     48
     49  assert(fvec_get_data(vec) == vec->data);
     50
     51  // wrong parameters
     52  assert(new_fvec(-1) == NULL);
     53
     54  // copy to an identical size works
     55  fvec_copy(vec, other_vec);
     56  del_fvec(other_vec);
     57
     58  // copy to a different size fail
     59  other_vec = new_fvec(length + 1);
     60  fvec_copy(vec, other_vec);
     61  del_fvec(other_vec);
     62
     63  // copy to a different size fail
     64  other_vec = new_fvec(length - 1);
     65  fvec_copy(vec, other_vec);
     66
    3867  // now destroys the vector
    39   del_fvec(vec);
    40 
     68  if (vec)
     69    del_fvec(vec);
     70  if (other_vec)
     71    del_fvec(other_vec);
    4172  return 0;
    4273}
    43 
  • tests/src/test-lvec.c

    r5f57ea9 r439ba7b  
    22#include "utils_tests.h"
    33
     4void assert_lvec_all_equal(lvec_t *vec, lsmp_t scalar)
     5{
     6  uint_t i;
     7  for (i = 0; i < vec->length; i++) {
     8    assert(vec->data[i] == scalar);
     9  }
     10}
     11
    412int main (void)
    513{
    6   uint_t win_s = 32; // window size
    7   lvec_t * sp = new_lvec (win_s); // input buffer
    8   lvec_set_sample (sp, 2./3., 0);
    9   PRINT_MSG(AUBIO_LSMP_FMT "\n", lvec_get_sample (sp, 0));
    10   lvec_print (sp);
    11   lvec_ones (sp);
    12   lvec_print (sp);
    13   lvec_set_all (sp, 3./5.);
    14   lvec_print (sp);
    15   del_lvec(sp);
     14  uint_t length = 32; // window size
     15
     16  lvec_t * vec = new_lvec (length); // input buffer
     17
     18  assert(vec);
     19
     20  assert(vec->length == length);
     21
     22  lvec_set_sample (vec, 3., 0);
     23  assert(lvec_get_sample(vec, 0) == 3.);
     24
     25  assert(lvec_get_data(vec) == vec->data);
     26
     27  lvec_print (vec);
     28  // note AUBIO_LSMP_FMT can be used to print lsmp_t
     29  PRINT_MSG(AUBIO_LSMP_FMT "\n", lvec_get_sample (vec, 0));
     30
     31  lvec_set_all (vec, 2.);
     32  assert_lvec_all_equal(vec, 2.);
     33
     34  lvec_ones (vec);
     35  assert_lvec_all_equal(vec, 1.);
     36
     37  lvec_zeros (vec);
     38  assert_lvec_all_equal(vec, 0.);
     39
     40  del_lvec(vec);
     41
     42  // wrong parameters
     43  assert(new_lvec(0) == NULL);
     44  assert(new_lvec(-1) == NULL);
     45
    1646  return 0;
    1747}
    18 
  • tests/src/test-mathutils-window.c

    r5f57ea9 r439ba7b  
    88  uint_t lengths[4] = { 8, 10, 15, 16 };
    99  char *method = "default";
    10   char *window_types[10] = { "default",
    11     "rectangle", "hamming", "hanning", "hanningz",
     10  char *window_types[11] = { "default",
     11    "ones", "rectangle", "hamming", "hanning", "hanningz",
    1212    "blackman", "blackman_harris", "gaussian", "welch", "parzen"};
    1313
     
    2727    }
    2828  }
     29
     30  assert (new_aubio_window("parzen", -1) == NULL);
     31  assert (new_aubio_window(NULL, length) == NULL);
     32  assert (new_aubio_window("\0", length) == NULL);
    2933  return 0;
    3034}
Note: See TracChangeset for help on using the changeset viewer.