Changeset dc467b5d for tests/src


Ignore:
Timestamp:
Oct 27, 2013, 12:44:29 PM (11 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
8247249
Parents:
dd15573 (diff), 7fc5ba2 (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 'develop' of aubio.org:/git/aubio/aubio into wavetable

Location:
tests/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • tests/src/io/test-source_multi.c

    rdd15573 rdc467b5d  
    1717    PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
    1818    PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
     19    PRINT_MSG(" - read file.wav at original samplerate with 256 frames blocks, mono\n");
     20    PRINT_MSG("       %s file.wav 0 4096 1\n", argv[0]);
    1921    return err;
    2022  }
     
    2325  uint_t hop_size = 256;
    2426  uint_t n_frames = 0, read = 0;
    25   if ( argc == 3 ) samplerate = atoi(argv[2]);
    26   if ( argc == 4 ) hop_size = atoi(argv[3]);
     27  uint_t n_channels = 0;
     28  if ( argc >= 3 ) samplerate = atoi(argv[2]);
     29  if ( argc >= 4 ) hop_size   = atoi(argv[3]);
     30  if ( argc >= 5 ) n_channels = atoi(argv[4]);
    2731
    2832  char_t *source_path = argv[1];
     
    3135  if (!s) { err = -1; goto beach; }
    3236
    33   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(s);
     37  if ( samplerate == 0 ) samplerate = aubio_source_get_samplerate(s);
    3438
    35   fmat_t *mat = new_fmat(hop_size, aubio_source_get_channels(s) );
     39  if ( n_channels == 0 ) n_channels = aubio_source_get_channels(s);
     40
     41  fmat_t *mat = new_fmat(hop_size, n_channels);
    3642
    3743  do {
     
    4147  } while ( read == hop_size );
    4248
    43   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n", n_frames, samplerate,
    44     n_frames / hop_size, source_path);
     49  PRINT_MSG("read %d frames in %d channels at %dHz (%d blocks) from %s\n",
     50      n_frames, n_channels, samplerate, n_frames / hop_size, source_path);
    4551
    4652  del_fmat (mat);
  • tests/src/io/test-source_seek.c

    rdd15573 rdc467b5d  
    2323  uint_t hop_size = 256;
    2424  uint_t n_frames = 0, read = 0;
    25   uint_t old_n_frames;
     25  uint_t old_n_frames_1, old_n_frames_2, old_n_frames_3;
    2626  if ( argc == 3 ) samplerate = atoi(argv[2]);
    2727  if ( argc == 4 ) hop_size = atoi(argv[3]);
     
    4242  } while ( read == hop_size );
    4343
    44   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n", n_frames, samplerate,
    45     n_frames / hop_size, source_path);
     44  PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
     45      n_frames * 1. / samplerate,
     46      n_frames, samplerate,
     47      n_frames / hop_size, source_path);
     48
     49  old_n_frames_1 = n_frames;
    4650
    4751  aubio_source_seek (s, 0);
    48 
    49   old_n_frames = n_frames;
    5052
    5153  n_frames = 0;
     
    5658  } while ( read == hop_size );
    5759
    58   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n", n_frames, samplerate,
    59     n_frames / hop_size, source_path);
     60  PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
     61      n_frames * 1. / samplerate,
     62      n_frames, samplerate,
     63      n_frames / hop_size, source_path);
     64
     65  old_n_frames_2 = n_frames;
     66
     67  aubio_source_seek (s, n_frames / 2);
     68
     69  n_frames = 0;
     70  do {
     71    aubio_source_do(s, vec, &read);
     72    //fvec_print (vec);
     73    n_frames += read;
     74  } while ( read == hop_size );
     75
     76  PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
     77      n_frames * 1. / samplerate,
     78      n_frames, samplerate,
     79      n_frames / hop_size, source_path);
     80
     81  old_n_frames_3 = n_frames;
    6082
    6183  del_aubio_source (s);
     
    6385  del_fvec (vec);
    6486
    65   assert ( n_frames == old_n_frames );
     87  assert ( old_n_frames_2 == old_n_frames_1 );
     88  assert ( old_n_frames_3 == (uint_t)floor(old_n_frames_1 / 2. + .5) );
    6689  return err;
    6790}
  • tests/src/onset/test-onset.c

    rdd15573 rdc467b5d  
    11#include <aubio.h>
     2#include "utils_tests.h"
    23
    3 int main ()
     4int main (int argc, char **argv)
    45{
    5   // 1. allocate some memory
    6   uint_t n = 0; // frame counter
     6  uint_t err = 0;
     7  if (argc < 2) {
     8    err = 2;
     9    PRINT_ERR("not enough arguments\n");
     10    PRINT_MSG("read a wave file as a mono vector\n");
     11    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     12    return err;
     13  }
     14  uint_t samplerate = 0;
    715  uint_t win_s = 1024; // window size
    8   uint_t hop_s = win_s / 4; // hop size
    9   uint_t samplerate = 44100; // samplerate
     16  uint_t hop_size = win_s / 4;
     17  uint_t n_frames = 0, read = 0;
     18  if ( argc == 3 ) samplerate = atoi(argv[2]);
     19  if ( argc == 4 ) hop_size = atoi(argv[3]);
     20
     21  char_t *source_path = argv[1];
     22  aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size);
     23  if (!source) { err = 1; goto beach; }
     24
     25  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
     26
    1027  // create some vectors
    11   fvec_t * input = new_fvec (win_s/4); // input buffer
    12   fvec_t * out = new_fvec (2); // input buffer
     28  fvec_t * in = new_fvec (hop_size); // input audio buffer
     29  fvec_t * out = new_fvec (2); // output position
     30
    1331  // create onset object
    14   aubio_onset_t * onset = new_aubio_onset("complex", win_s, hop_s, samplerate);
     32  aubio_onset_t * o = new_aubio_onset("default", win_s, hop_size, samplerate);
    1533
    16   // 2. do something with it
    17   while (n < 10) {
    18     // get `hop_s` new samples into `input`
    19     // ...
    20     // exectute onset detection
    21     aubio_onset_do (onset, input, out);
    22     // do something with output candidates
    23     // ...
    24     n++;
    25   };
     34  do {
     35    // put some fresh data in input vector
     36    aubio_source_do(source, in, &read);
     37    // execute onset
     38    aubio_onset_do(o,in,out);
     39    // do something with the onsets
     40    if (out->data[0] != 0) {
     41      PRINT_MSG("onset at %.3fms, %.3fs, frame %d\n",
     42          aubio_onset_get_last_ms(o), aubio_onset_get_last_s(o),
     43          aubio_onset_get_last(o));
     44    }
     45    n_frames += read;
     46  } while ( read == hop_size );
    2647
    27   // 3. clean up memory
    28   del_aubio_onset(onset);
    29   del_fvec(input);
     48  PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
     49      n_frames * 1. / samplerate,
     50      n_frames, samplerate,
     51      n_frames / hop_size, source_path);
     52
     53  // clean up memory
     54  del_aubio_onset(o);
     55  del_fvec(in);
    3056  del_fvec(out);
     57beach:
    3158  aubio_cleanup();
    3259
    33   return 0;
     60  return err;
    3461}
  • tests/src/spectral/test-filterbank.c

    rdd15573 rdc467b5d  
    88  cvec_t *in_spec = new_cvec (win_s); // input vector of samples
    99  fvec_t *out_filters = new_fvec (n_filters); // per-band outputs
    10   fmat_t *coeffs; // pointer to the coefficients
    1110
    1211  // create filterbank object
    1312  aubio_filterbank_t *o = new_aubio_filterbank (n_filters, win_s);
    1413
     14  // apply filterbank ten times
     15  uint_t n = 10;
     16  while (n) {
     17    aubio_filterbank_do (o, in_spec, out_filters);
     18    n--;
     19  }
     20
     21  // print out filterbank coeffs
     22  fmat_t *coeffs; // pointer to the coefficients
    1523  coeffs = aubio_filterbank_get_coeffs (o);
     24  fmat_print (coeffs);
    1625
    17   aubio_filterbank_do (o, in_spec, out_filters);
     26  //fvec_print (out_filters);
    1827
    19   // fmat_print (coeffs);
    20   // cvec_print(in_spec);
    21   // fvec_print(out_filters);
    22 
     28  // clean up
    2329  del_aubio_filterbank (o);
    2430  del_cvec (in_spec);
  • tests/src/spectral/test-filterbank_mel.c

    rdd15573 rdc467b5d  
    99  cvec_t *in_spec = new_cvec (win_s); // input vector of samples
    1010  fvec_t *out_filters = new_fvec (n_filters); // per-band outputs
    11   fmat_t *coeffs; // pointer to the coefficients
    1211
    1312  // create filterbank object
     
    1716  aubio_filterbank_set_mel_coeffs_slaney (o, samplerate);
    1817
     18  // apply filterbank ten times
     19  uint_t n = 10;
     20  while (n) {
     21    aubio_filterbank_do (o, in_spec, out_filters);
     22    n--;
     23  }
     24
     25  // print out filter coefficients
     26  fmat_t *coeffs; // pointer to the coefficients
    1927  coeffs = aubio_filterbank_get_coeffs (o);
     28  fmat_print (coeffs);
    2029
    21   aubio_filterbank_do (o, in_spec, out_filters);
    22 
    23   // fmat_print (coeffs);
    24   // cvec_print(in_spec);
    25   // fvec_print(out_filters);
     30  //fvec_print (out_filters);
    2631
    2732  del_aubio_filterbank (o);
  • tests/src/tempo/test-tempo.c

    rdd15573 rdc467b5d  
    11#include <aubio.h>
     2#include "utils_tests.h"
    23
    3 int main ()
     4int main (int argc, char **argv)
    45{
    5   uint_t i = 0;
     6  uint_t err = 0;
     7  if (argc < 2) {
     8    err = 2;
     9    PRINT_ERR("not enough arguments\n");
     10    PRINT_MSG("read a wave file as a mono vector\n");
     11    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     12    return err;
     13  }
     14  uint_t samplerate = 0;
    615  uint_t win_s = 1024; // window size
    7   fvec_t * in = new_fvec (win_s); // input vector
    8   fvec_t * out = new_fvec (2); // output beat position
     16  uint_t hop_size = win_s / 4;
     17  uint_t n_frames = 0, read = 0;
     18  if ( argc == 3 ) samplerate = atoi(argv[2]);
     19  if ( argc == 4 ) hop_size = atoi(argv[3]);
     20
     21  char_t *source_path = argv[1];
     22  aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size);
     23  if (!source) { err = 1; goto beach; }
     24
     25  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
     26
     27  // create some vectors
     28  fvec_t * in = new_fvec (hop_size); // input audio buffer
     29  fvec_t * out = new_fvec (2); // output position
    930
    1031  // create tempo object
    11   aubio_tempo_t * o = new_aubio_tempo("complex", win_s, win_s/4, 44100.);
     32  aubio_tempo_t * o = new_aubio_tempo("default", win_s, hop_size, samplerate);
    1233
    13   smpl_t bpm, confidence;
    14 
    15   while (i < 1000) {
     34  do {
    1635    // put some fresh data in input vector
    17     // ...
    18 
     36    aubio_source_do(source, in, &read);
    1937    // execute tempo
    2038    aubio_tempo_do(o,in,out);
    2139    // do something with the beats
    22     // ...
     40    if (out->data[0] != 0) {
     41      PRINT_MSG("beat at %.3fms, %.3fs, frame %d, %.2fbpm with confidence %.2f\n",
     42          aubio_tempo_get_last_ms(o), aubio_tempo_get_last_s(o),
     43          aubio_tempo_get_last(o), aubio_tempo_get_bpm(o), aubio_tempo_get_confidence(o));
     44    }
     45    n_frames += read;
     46  } while ( read == hop_size );
    2347
    24     // get bpm and confidence
    25     bpm = aubio_tempo_get_bpm(o);
    26     confidence = aubio_tempo_get_confidence(o);
     48  PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
     49      n_frames * 1. / samplerate,
     50      n_frames, samplerate,
     51      n_frames / hop_size, source_path);
    2752
    28     i++;
    29   };
    30 
     53  // clean up memory
    3154  del_aubio_tempo(o);
    3255  del_fvec(in);
    3356  del_fvec(out);
     57  del_aubio_source(source);
     58beach:
    3459  aubio_cleanup();
    3560
    36   return 0;
     61  return err;
    3762}
  • tests/src/temporal/test-filter.c

    rdd15573 rdc467b5d  
    33int main ()
    44{
    5   uint_t win_s = 32; // window size
     5  uint_t win_s = 16; // window size
     6  uint_t impulse_at = win_s / 2;
    67  fvec_t *in = new_fvec (win_s); // input buffer
    78  fvec_t *out = new_fvec (win_s); // input buffer
    89
    910  aubio_filter_t *o = new_aubio_filter_c_weighting (44100);
    10   in->data[12] = 0.5;
     11  in->data[impulse_at] = 0.5;
    1112  fvec_print (in);
    1213  aubio_filter_do (o, in);
     
    1516
    1617  o = new_aubio_filter_a_weighting (32000);
    17   in->data[12] = 0.5;
     18  in->data[impulse_at] = 0.5;
    1819  fvec_print (in);
    1920  aubio_filter_do_outplace (o, in, out);
     
    2122
    2223  aubio_filter_set_a_weighting (o, 32000);
    23   in->data[12] = 0.5;
     24  in->data[impulse_at] = 0.5;
    2425  fvec_print (in);
    2526  aubio_filter_do_filtfilt (o, in, out);
  • tests/src/test-delnull.c

    rdd15573 rdc467b5d  
    11#include <stdlib.h>
    22#include <aubio.h>
     3
     4// Because aubio does not check for double free, this program will crash.
     5// Programs that call these functions should check for null pointers.
    36
    47int main ()
  • tests/src/test-fmat.c

    rdd15573 rdc467b5d  
    1818    }
    1919  }
     20  fvec_t channel_onstack;
     21  fvec_t *channel = &channel_onstack;
     22  fmat_get_channel(mat, 1, channel);
     23  fvec_print (channel);
    2024  // print out matrix
    2125  fmat_print(mat);
Note: See TracChangeset for help on using the changeset viewer.