Changeset 9547247 for tests


Ignore:
Timestamp:
Mar 3, 2013, 7:38:32 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:
3684ab4
Parents:
6938a20
Message:

tests/src/tempo/: improve examples

Location:
tests/src/tempo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/src/tempo/test-beattracking.c

    r6938a20 r9547247  
    11#define AUBIO_UNSTABLE 1
    22
    3 #include <stdio.h>
    43#include <aubio.h>
    54
    6 int main(){
    7         /* allocate some memory */
    8         uint_t win_s      = 1024;                       /* window size */
    9         fvec_t * in       = new_fvec (win_s); /* input buffer */
    10         fvec_t * out      = new_fvec (win_s/4);     /* input buffer */
    11  
    12         /* allocate fft and other memory space */
    13         aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s);
     5int main ()
     6{
     7  uint_t i = 0;
     8  uint_t win_s = 1024; // window size
     9  fvec_t * in = new_fvec (win_s); // input buffer
     10  fvec_t * out = new_fvec (2); // output beat position
    1411
    15         uint_t i = 0;
     12  // create beattracking object
     13  aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s);
    1614
    17         smpl_t curtempo, curtempoconf;
     15  smpl_t bpm, confidence;
    1816
    19         while (i < 10) {
    20           aubio_beattracking_do(tempo,in,out);
    21           curtempo = aubio_beattracking_get_bpm(tempo);
    22           if (curtempo != 0.) {
    23             fprintf(stdout,"%f\n",curtempo);
    24             return 1;
    25           }
    26           curtempoconf = aubio_beattracking_get_confidence(tempo);
    27           if (curtempoconf != 0.) {
    28             fprintf(stdout,"%f\n",curtempo);
    29             return 1;
    30           }
    31           i++;
    32         };
     17  while (i < 10) {
     18    // put some fresh data in feature vector
     19    // ...
    3320
    34         del_aubio_beattracking(tempo);
    35         del_fvec(in);
    36         del_fvec(out);
    37         aubio_cleanup();
     21    aubio_beattracking_do(tempo,in,out);
     22    // do something  with the beats
     23    // ...
    3824
    39         return 0;
     25    // get bpm and confidence
     26    bpm = aubio_beattracking_get_bpm(tempo);
     27    confidence = aubio_beattracking_get_confidence(tempo);
     28    i++;
     29  };
     30
     31  del_aubio_beattracking(tempo);
     32  del_fvec(in);
     33  del_fvec(out);
     34  aubio_cleanup();
     35
     36  return 0;
    4037}
    4138
  • tests/src/tempo/test-tempo.c

    r6938a20 r9547247  
    1 #include <stdio.h>
    21#include <aubio.h>
    32
    4 int main(){
    5         /* allocate some memory */
    6         uint_t win_s      = 1024;                       /* window size */
    7         fvec_t * in       = new_fvec (win_s); /* input buffer */
    8         fvec_t * out      = new_fvec (2);     /* input buffer */
    9         aubio_tempo_t * o  = new_aubio_tempo("complex", win_s, win_s/4, 44100.);
    10         uint_t i = 0;
     3int main ()
     4{
     5  uint_t i = 0;
     6  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
    119
    12         smpl_t curtempo, curtempoconf;
     10  // create tempo object
     11  aubio_tempo_t * o = new_aubio_tempo("complex", win_s, win_s/4, 44100.);
    1312
    14         while (i < 1000) {
    15           aubio_tempo_do(o,in,out);
    16           curtempo = aubio_tempo_get_bpm(o);
    17           if (curtempo != 0.) {
    18             fprintf(stdout,"%f\n",curtempo);
    19             return 1;
    20           }
    21           curtempoconf = aubio_tempo_get_confidence(o);
    22           if (curtempoconf != 0.) {
    23             fprintf(stdout,"%f\n",curtempo);
    24             return 1;
    25           }
    26           i++;
    27         };
     13  smpl_t bpm, confidence;
    2814
    29         del_aubio_tempo(o);
    30         del_fvec(in);
    31         del_fvec(out);
    32         aubio_cleanup();
     15  while (i < 1000) {
     16    // put some fresh data in input vector
     17    // ...
    3318
    34         return 0;
     19    // execute tempo
     20    aubio_tempo_do(o,in,out);
     21    // do something with the beats
     22    // ...
     23
     24    // get bpm and confidence
     25    bpm = aubio_tempo_get_bpm(o);
     26    confidence = aubio_tempo_get_confidence(o);
     27
     28    i++;
     29  };
     30
     31  del_aubio_tempo(o);
     32  del_fvec(in);
     33  del_fvec(out);
     34  aubio_cleanup();
     35
     36  return 0;
    3537}
Note: See TracChangeset for help on using the changeset viewer.