Changeset c71aa44 for tests/src


Ignore:
Timestamp:
Mar 3, 2013, 5:47:05 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:
248da64
Parents:
e230bb4
Message:

tests/src/pitch/: improve examples

Location:
tests/src/pitch
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • tests/src/pitch/test-pitch.c

    re230bb4 rc71aa44  
    11#include <aubio.h>
    22
    3 int
    4 main ()
     3int main ()
    54{
    6   /* allocate some memory */
    7   uint_t win_s = 1024;          /* window size */
    8   uint_t hop_s = win_s / 4;     /* hop size */
    9   uint_t samplerate = 44100;    /* samplerate */
    10   fvec_t *in = new_fvec (hop_s);      /* input buffer */
    11   fvec_t *out = new_fvec (1); /* input buffer */
    12   aubio_pitch_t *o =
    13       new_aubio_pitch ("default", win_s, hop_s, samplerate);
    14   uint_t i = 0;
     5  // 1. allocate some memory
     6  uint_t n = 0; // frame counter
     7  uint_t win_s = 1024; // window size
     8  uint_t hop_s = win_s / 4; // hop size
     9  uint_t samplerate = 44100; // samplerate
     10  // create some vectors
     11  fvec_t *input = new_fvec (hop_s); // input buffer
     12  fvec_t *out = new_fvec (1); // output candidates
     13  // create pitch object
     14  aubio_pitch_t *o = new_aubio_pitch ("default", win_s, hop_s, samplerate);
    1515
    16   while (i < 100) {
    17     aubio_pitch_do (o, in, out);
    18     i++;
     16  // 2. do something with it
     17  while (n < 100) {
     18    // get `hop_s` new samples into `input`
     19    // ...
     20    // exectute pitch
     21    aubio_pitch_do (o, input, out);
     22    // do something with output candidates
     23    // ...
     24    n++;
    1925  };
    2026
     27  // 3. clean up memory
    2128  del_aubio_pitch (o);
    2229  del_fvec (out);
    23   del_fvec (in);
     30  del_fvec (input);
    2431  aubio_cleanup ();
    2532
  • tests/src/pitch/test-pitchfcomb.c

    re230bb4 rc71aa44  
    11#define AUBIO_UNSTABLE 1
     2
     3// this file uses the unstable aubio api, please use aubio_pitch instead
     4// see src/pitch/pitch.h and tests/src/pitch/test-pitch.c
    25
    36#include <aubio.h>
    47
    5 int main(){
    6         /* allocate some memory */
    7         uint_t win_s      = 1024;                       /* window size */
    8         uint_t hop_s      = win_s/4;                    /* hop size */
    9         fvec_t * in       = new_fvec (hop_s); /* input buffer */
    10         fvec_t * out      = new_fvec (1);
    11         aubio_pitchfcomb_t * o  = new_aubio_pitchfcomb (
    12           win_s, hop_s);
    13         uint_t i = 0;
     8int main ()
     9{
     10  uint_t i = 0;
     11  uint_t win_s = 1024; // window size
     12  uint_t hop_s = win_s/4; // hop size
     13  // create some vectors
     14  fvec_t * in = new_fvec (hop_s); // input buffer
     15  fvec_t * out = new_fvec (1); // output candidates
     16  // create pitch object
     17  aubio_pitchfcomb_t * o  = new_aubio_pitchfcomb ( win_s, hop_s);
    1418
    15         while (i < 2) {
    16           aubio_pitchfcomb_do (o,in, out);
    17           i++;
    18         };
     19  while (i < 10) {
     20    aubio_pitchfcomb_do (o,in, out);
     21    i++;
     22  };
    1923
    20         del_aubio_pitchfcomb(o);
    21         del_fvec(out);
    22         del_fvec(in);
    23         aubio_cleanup();
    24 
    25         return 0;
     24  del_aubio_pitchfcomb(o);
     25  del_fvec(out);
     26  del_fvec(in);
     27  aubio_cleanup();
     28  return 0;
    2629}
  • tests/src/pitch/test-pitchmcomb.c

    re230bb4 rc71aa44  
    11#define AUBIO_UNSTABLE 1
     2
     3// this file uses the unstable aubio api, please use aubio_pitch instead
     4// see src/pitch/pitch.h and tests/src/pitch/test-pitch.c
    25
    36#include <aubio.h>
    47
    5 int main(){
    6         /* allocate some memory */
    7         uint_t win_s      = 1024;                       /* window size */
    8         uint_t hop_s      = win_s/4;                    /* hop size */
    9         cvec_t * in       = new_cvec (win_s); /* input buffer */
    10         fvec_t * out      = new_fvec (1); /* input buffer */
     8int main ()
     9{
     10  uint_t n = 10; // compute n times
     11  uint_t win_s = 1024; // window size
     12  uint_t hop_s = win_s/4; // hop size
     13  // create some vectors
     14  cvec_t * in_cvec = new_cvec (win_s); // input fftgrain
     15  fvec_t * out_cands = new_fvec (1); // pitch candidate
     16  // create pitch object
     17  aubio_pitchmcomb_t * mcomb = new_aubio_pitchmcomb(win_s, hop_s);
    1118
    12         aubio_pitchmcomb_t * o  = new_aubio_pitchmcomb(win_s, hop_s);
    13         uint_t i = 0;
     19  while ( n-- ) {
     20    aubio_pitchmcomb_do (mcomb, in_cvec, out_cands);
     21    // fvec_print(out_cands);
     22  };
    1423
    15         while (i < 1000) {
    16           aubio_pitchmcomb_do (o,in, out);
    17           i++;
    18         };
     24  // clean up before exiting
     25  del_aubio_pitchmcomb(mcomb);
     26  del_cvec(in_cvec);
     27  del_fvec(out_cands);
    1928
    20         del_aubio_pitchmcomb(o);
    21         del_cvec(in);
    22         del_fvec(out);
    23         aubio_cleanup();
     29  aubio_cleanup();
    2430
    25         return 0;
     31  return 0;
    2632}
  • tests/src/pitch/test-pitchschmitt.c

    re230bb4 rc71aa44  
    11#define AUBIO_UNSTABLE 1
     2
     3// this file uses the unstable aubio api, please use aubio_pitch instead
     4// see src/pitch/pitch.h and tests/src/pitch/test-pitch.c
    25
    36#include <aubio.h>
    47
    5 int main(){
    6         /* allocate some memory */
    7         uint_t win_s      = 1024;                       /* window size */
    8         fvec_t * in       = new_fvec (win_s); /* input buffer */
    9         fvec_t * out = new_fvec (1); /* input buffer */
    10         aubio_pitchschmitt_t * o  = new_aubio_pitchschmitt(win_s);
    11         uint_t i = 0;
     8int main ()
     9{
     10  uint_t n = 10; // compute n times
     11  uint_t win_s = 1024; // window size
     12  // create some vectors
     13  fvec_t * in = new_fvec (win_s); // input buffer
     14  fvec_t * out = new_fvec (1); // input buffer
     15  // create pitch object
     16  aubio_pitchschmitt_t * o = new_aubio_pitchschmitt(win_s);
    1217
    13         while (i < 1000) {
    14           aubio_pitchschmitt_do (o,in, out);
    15           i++;
    16         };
     18  while ( n-- ) {
     19    aubio_pitchschmitt_do (o,in, out);
     20  };
    1721
    18         del_aubio_pitchschmitt(o);
    19         del_fvec(in);
    20         del_fvec(out);
    21         aubio_cleanup();
     22  del_aubio_pitchschmitt(o);
     23  del_fvec(in);
     24  del_fvec(out);
     25  aubio_cleanup();
    2226
    23         return 0;
     27  return 0;
    2428}
    2529
  • tests/src/pitch/test-pitchyin.c

    re230bb4 rc71aa44  
    11#define AUBIO_UNSTABLE 1
     2
     3// this file uses the unstable aubio api, please use aubio_pitch instead
     4// see src/pitch/pitch.h and tests/src/pitch/test-pitch.c
    25
    36#include <aubio.h>
    47
    5 int main(){
    6         /* allocate some memory */
    7         uint_t win_s      = 1024;                       /* window size */
    8         fvec_t * in       = new_fvec (win_s); /* input buffer */
    9         fvec_t * out      = new_fvec (win_s/2); /* input buffer */
    10         aubio_pitchyin_t *p = new_aubio_pitchyin (win_s);
    11         uint_t i = 0;
     8int main ()
     9{
     10  uint_t n = 10; // compute n times
     11  uint_t win_s = 1024; // window size
     12  // create some vectors
     13  fvec_t * input_signal = new_fvec (win_s); // input signal
     14  fvec_t * output_cands = new_fvec (1); // output candidates
     15  // create pitch object
     16  aubio_pitchyin_t *p = new_aubio_pitchyin (win_s);
    1217
    13         while (i < 10) {
    14           aubio_pitchyin_do (p, in,out);
    15           i++;
    16         };
     18  while ( n-- ) {
     19    aubio_pitchyin_do (p, input_signal, output_cands);
     20  };
    1721
    18         del_fvec(in);
    19         del_fvec(out);
    20         del_aubio_pitchyin(p);
    21         aubio_cleanup();
     22  fvec_print(output_cands);
    2223
    23         return 0;
     24  del_fvec(input_signal);
     25  del_fvec(output_cands);
     26  del_aubio_pitchyin(p);
     27  aubio_cleanup();
     28
     29  return 0;
    2430}
  • tests/src/pitch/test-pitchyinfft.c

    re230bb4 rc71aa44  
    11#define AUBIO_UNSTABLE 1
     2
     3// this file uses the unstable aubio api, please use aubio_pitch instead
     4// see src/pitch/pitch.h and tests/src/pitch/test-pitch.c
    25
    36#include <aubio.h>
    47
    5 int main(){
    6         /* allocate some memory */
    7         uint_t win_s      = 1024;                       /* window size */
    8         fvec_t * in       = new_fvec (win_s); /* input buffer */
    9         fvec_t * out      = new_fvec (1); /* output pitch periods */
    10         aubio_pitchyinfft_t * o  = new_aubio_pitchyinfft(win_s);
    11         aubio_pitchyinfft_set_tolerance (o, 0.2);
    12         uint_t i = 0;
     8int main ()
     9{
     10  uint_t n = 10; // compute n times
     11  uint_t win_s = 1024; // window size
     12  // create some vectors
     13  fvec_t * in = new_fvec (win_s); // input buffer
     14  fvec_t * out = new_fvec (1); // output candidates
     15  // create pitch object
     16  aubio_pitchyinfft_t *p  = new_aubio_pitchyinfft(win_s);
     17  aubio_pitchyinfft_set_tolerance (p, 0.2);
    1318
    14         while (i < 10) {
    15           aubio_pitchyinfft_do (o,in,out);
    16           i++;
    17         };
     19  while ( n-- ) {
     20    aubio_pitchyinfft_do (p, in,out);
     21  };
    1822
    19         del_aubio_pitchyinfft(o);
    20         del_fvec(in);
    21         del_fvec(out);
    22         aubio_cleanup();
     23  fvec_print(out);
    2324
    24         return 0;
     25  del_fvec(in);
     26  del_fvec(out);
     27  del_aubio_pitchyinfft(p);
     28  aubio_cleanup();
     29
     30  return 0;
    2531}
    26 
Note: See TracChangeset for help on using the changeset viewer.