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

tests/src/tempo/: improve examples

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.