Changeset 4621cd6


Ignore:
Timestamp:
Dec 4, 2009, 1:46:40 AM (15 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:
aea235c
Parents:
c17a0ee
Message:

examples: switch to mono

Location:
examples
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • examples/aubiomfcc.c

    rc17a0ee r4621cd6  
    3333
    3434static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    35   unsigned int i;       /*channels*/
    3635  unsigned int j;       /*frames*/
    3736 
    3837  for (j=0;j<(unsigned)nframes;j++) {
    3938    if(usejack) {
    40       for (i=0;i<channels;i++) {
    41         /* write input to datanew */
    42         fvec_write_sample(ibuf, input[i][j], i, pos);
    43         /* put synthnew in output */
    44         output[i][j] = fvec_read_sample(obuf, i, pos);
    45       }
     39      /* write input to datanew */
     40      fvec_write_sample(ibuf, input[0][j], pos);
     41      /* put synthnew in output */
     42      output[0][j] = fvec_read_sample(obuf, pos);
    4643    }
    4744    /*time for fft*/
     
    5047     
    5148      //compute mag spectrum
    52       aubio_pvoc_do (pv,ibuf, fftgrain);
     49      aubio_pvoc_do (pv, ibuf, fftgrain);
    5350     
    5451      //compute mfccs
     
    7269        outmsg("%f\t",frames*overlap_size/(float)samplerate);
    7370        for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) {
    74             outmsg("%f ", fvec_read_sample (mfcc_out, 0, coef_cnt) );
     71            outmsg("%f ", fvec_read_sample (mfcc_out, coef_cnt) );
    7572        }
    7673        outmsg("\n");
     
    8683
    8784  /* phase vocoder */
    88   pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
     85  pv = new_aubio_pvoc (buffer_size, overlap_size);
    8986
    90   fftgrain = new_cvec (buffer_size, channels);
     87  fftgrain = new_cvec (buffer_size);
    9188
    9289  //populating the filter
    9390  mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
    9491 
    95   mfcc_out = new_fvec(n_coefs,channels);
     92  mfcc_out = new_fvec(n_coefs);
    9693 
    9794  //process
  • examples/aubionotes.c

    rc17a0ee r4621cd6  
    1919*/
    2020
    21 #define AUBIO_UNSTABLE 1 // for fvec_median_channel
     21#define AUBIO_UNSTABLE 1 // for fvec_median
    2222
    2323#include "utils.h"
     
    5050
    5151static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    52   unsigned int i;       /*channels*/
    5352  unsigned int j;       /*frames*/
    5453  for (j=0;j<(unsigned)nframes;j++) {
    5554    if(usejack) {
    56       for (i=0;i<channels;i++) {
    57         /* write input to datanew */
    58         fvec_write_sample(ibuf, input[i][j], i, pos);
    59         /* put synthnew in output */
    60         output[i][j] = fvec_read_sample(obuf, i, pos);
    61       }
     55      /* write input to datanew */
     56      fvec_write_sample(ibuf, input[0][j], pos);
     57      /* put synthnew in output */
     58      output[0][j] = fvec_read_sample(obuf, pos);
    6259    }
    6360    /*time for fft*/
     
    6764     
    6865      aubio_pitch_do (pitchdet, ibuf, pitch_obuf);
    69       pitch = fvec_read_sample(pitch_obuf, 0, 0);
     66      pitch = fvec_read_sample(pitch_obuf, 0);
    7067      if(median){
    7168              note_append(note_buffer, pitch);
     
    7471      /* curlevel is negatif or 1 if silence */
    7572      curlevel = aubio_level_detection(ibuf, silence);
    76       if (fvec_read_sample(onset, 0, 0)) {
     73      if (fvec_read_sample(onset, 0)) {
    7774              /* test for silence */
    7875              if (curlevel == 1.) {
     
    9289
    9390                      for (pos = 0; pos < overlap_size; pos++){
    94                               obuf->data[0][pos] = woodblock->data[0][pos];
     91                              obuf->data[pos] = woodblock->data[pos];
    9592                      }
    9693              }
     
    112109              } // if median
    113110        for (pos = 0; pos < overlap_size; pos++)
    114           obuf->data[0][pos] = 0.;
     111          obuf->data[pos] = 0.;
    115112      }
    116113      /* end of block loop */
     
    131128  uint_t i = 0;
    132129  for (i = 0; i < note_buffer->length - 1; i++) {
    133     note_buffer->data[0][i] = note_buffer->data[0][i + 1];
     130    note_buffer->data[i] = note_buffer->data[i + 1];
    134131  }
    135   note_buffer->data[0][note_buffer->length - 1] = curnote;
     132  note_buffer->data[note_buffer->length - 1] = curnote;
    136133  return;
    137134}
     
    142139  uint_t i;
    143140  for (i = 0; i < note_buffer->length; i++) {
    144     note_buffer2->data[0][i] = note_buffer->data[0][i];
     141    note_buffer2->data[i] = note_buffer->data[i];
    145142  }
    146   return fvec_median_channel (note_buffer2, 0);
     143  return fvec_median (note_buffer2);
    147144}
    148145
     
    150147  examples_common_init(argc,argv);
    151148
    152   o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
    153           samplerate);
     149  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate);
    154150  if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
    155   onset = new_fvec (1, channels);
     151  onset = new_fvec (1);
    156152
    157153  pitchdet = new_aubio_pitch (pitch_mode, buffer_size * 4,
    158           overlap_size, channels, samplerate);
     154          overlap_size, samplerate);
    159155  aubio_pitch_set_tolerance (pitchdet, 0.7);
    160   pitch_obuf = new_fvec (1, channels);
     156  pitch_obuf = new_fvec (1);
    161157  if (median) {
    162       note_buffer = new_fvec (median, 1);
    163       note_buffer2 = new_fvec (median, 1);
     158      note_buffer = new_fvec (median);
     159      note_buffer2 = new_fvec (median);
    164160  }
    165161
  • examples/aubioonset.c

    rc17a0ee r4621cd6  
    3131  for (j=0;j<(unsigned)nframes;j++) {
    3232    if(usejack) {
    33       for (i=0;i<channels;i++) {
    34         /* write input to datanew */
    35         fvec_write_sample(ibuf, input[i][j], i, pos);
    36         /* put synthnew in output */
    37         output[i][j] = fvec_read_sample(obuf, i, pos);
    38       }
     33      /* write input to datanew */
     34      fvec_write_sample(ibuf, input[0][j], pos);
     35      /* put synthnew in output */
     36      output[0][j] = fvec_read_sample(obuf, pos);
    3937    }
    4038    /*time for fft*/
    41     if (pos == overlap_size-1) {         
     39    if (pos == overlap_size-1) {
    4240      /* block loop */
    4341      aubio_onset_do (o, ibuf, onset);
    44       if (fvec_read_sample(onset, 0, 0)) {
     42      if ( fvec_read_sample(onset, 0) ) {
    4543        fvec_copy (woodblock, obuf);
    4644      } else {
     
    5553}
    5654
    57 static void process_print (void) {
    58       /* output times in seconds, taking back some
    59        * delay to ensure the label is _before_ the
    60        * actual onset */
    61       if (!verbose && usejack) return;
    62       smpl_t onset_found = fvec_read_sample(onset, 0, 0);
    63       if (onset_found) {
    64         if(frames >= 4) {
    65           outmsg("%f\n",(frames - frames_delay + onset_found)
    66                   *overlap_size/(float)samplerate);
    67         } else if (frames < frames_delay) {
    68           outmsg("%f\n",0.);
    69         }
    70       }
     55static void
     56process_print (void)
     57{
     58  /* output times in seconds, taking back some delay to ensure the label is
     59   * _before_ the actual onset */
     60  if (!verbose && usejack)
     61    return;
     62  smpl_t onset_found = fvec_read_sample (onset, 0);
     63  if (onset_found) {
     64    if (frames >= 4) {
     65      outmsg ("%f\n", (frames - frames_delay + onset_found)
     66          * overlap_size / (float) samplerate);
     67    } else if (frames < frames_delay) {
     68      outmsg ("%f\n", 0.);
     69    }
     70  }
    7171}
    7272
     
    7575  examples_common_init(argc,argv);
    7676
    77   o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
    78           samplerate);
     77  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate);
    7978  if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
    80   onset = new_fvec (1, channels);
     79  onset = new_fvec (1);
    8180
    8281  examples_common_process(aubio_process,process_print);
  • examples/aubiopitch.c

    rc17a0ee r4621cd6  
    2727
    2828static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    29   unsigned int i;       /*channels*/
    3029  unsigned int j;       /*frames*/
    3130  for (j=0;j<(unsigned)nframes;j++) {
    3231    if(usejack) {
    33       for (i=0;i<channels;i++) {
    34         /* write input to datanew */
    35         fvec_write_sample(ibuf, input[i][j], i, pos);
    36         /* put synthnew in output */
    37         output[i][j] = fvec_read_sample(obuf, i, pos);
    38       }
     32      /* write input to datanew */
     33      fvec_write_sample(ibuf, input[0][j], pos);
     34      /* put synthnew in output */
     35      output[0][j] = fvec_read_sample(obuf, pos);
    3936    }
    4037    /*time for fft*/
     
    4239      /* block loop */
    4340      aubio_pitch_do (o, ibuf, pitch);
    44       if (fvec_read_sample(pitch, 0, 0)) {
     41      if (fvec_read_sample(pitch, 0)) {
    4542        for (pos = 0; pos < overlap_size; pos++){
    4643          // TODO, play sine at this freq
     
    5956static void process_print (void) {
    6057      if (!verbose && usejack) return;
    61       smpl_t pitch_found = fvec_read_sample(pitch, 0, 0);
     58      smpl_t pitch_found = fvec_read_sample(pitch, 0);
    6259      outmsg("%f %f\n",(frames)
    6360              *overlap_size/(float)samplerate, pitch_found);
     
    6764  examples_common_init(argc,argv);
    6865
    69   o = new_aubio_pitch (onset_mode, buffer_size, overlap_size, channels,
    70           samplerate);
    71   pitch = new_fvec (1, channels);
     66  o = new_aubio_pitch (onset_mode, buffer_size, overlap_size, samplerate);
     67  pitch = new_fvec (1);
    7268
    7369  examples_common_process(aubio_process,process_print);
  • examples/aubioquiet.c

    rc17a0ee r4621cd6  
    2626int aubio_process(smpl_t **input, smpl_t **output, int nframes);
    2727int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    28   unsigned int i;       /*channels*/
    2928  unsigned int j;       /*frames*/
    3029  for (j=0;j<(unsigned)nframes;j++) {
    3130    if(usejack) {
    32       for (i=0;i<channels;i++) {
    33         /* write input to datanew */
    34         fvec_write_sample(ibuf, input[i][j], i, pos);
    35         /* put synthnew in output */
    36         output[i][j] = fvec_read_sample(obuf, i, pos);
    37       }
     31      /* write input to datanew */
     32      fvec_write_sample(ibuf, input[0][j], pos);
     33      /* put synthnew in output */
     34      output[0][j] = fvec_read_sample(obuf, pos);
    3835    }
    3936    /*time for fft*/
     
    4138      /* test for silence */
    4239      if (aubio_silence_detection(ibuf, silence)==1) {
    43         if (wassilence==1) issilence = 1;
    44         else issilence = 2;
     40        if (wassilence==1) issilence = 1;
     41        else issilence = 2;
    4542        wassilence=1;
    4643      } else {
    47         if (wassilence<=0) issilence = 0;
    48         else issilence = -1;
     44        if (wassilence<=0) issilence = 0;
     45        else issilence = -1;
    4946        wassilence=0;
    5047      }
  • examples/aubiotrack.c

    rc17a0ee r4621cd6  
    2929
    3030static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
    31   unsigned int i;       /*channels*/
    3231  unsigned int j;       /*frames*/
    3332  for (j=0;j<(unsigned)nframes;j++) {
    3433    if(usejack) {
    35       for (i=0;i<channels;i++) {
    36         /* write input to datanew */
    37         fvec_write_sample(ibuf, input[i][j], i, pos);
    38         /* put synthnew in output */
    39         output[i][j] = fvec_read_sample(obuf, i, pos);
    40       }
     34      /* write input to datanew */
     35      fvec_write_sample(ibuf, input[0][j], pos);
     36      /* put synthnew in output */
     37      output[0][j] = fvec_read_sample(obuf, pos);
    4138    }
    4239    /*time for fft*/
     
    4441      /* block loop */
    4542      aubio_tempo_do (bt,ibuf,tempo_out);
    46       istactus = fvec_read_sample (tempo_out, 0, 0);
    47       isonset = fvec_read_sample (tempo_out, 0, 1);
     43      istactus = fvec_read_sample (tempo_out, 0);
     44      isonset = fvec_read_sample (tempo_out, 1);
    4845      if (istactus > 0.) {
    4946        fvec_copy (woodblock, obuf);
     
    7673  examples_common_init(argc,argv);
    7774
    78   tempo_out = new_fvec(2,channels);
    79   bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels, samplerate);
     75  tempo_out = new_fvec(2);
     76  bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, samplerate);
    8077  if (threshold != 0.) aubio_tempo_set_threshold (bt, threshold);
    8178
  • examples/sndfileio.c

    rc17a0ee r4621cd6  
    9696        aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t);
    9797        f->samplerate    = fmodel->samplerate;
    98         f->channels      = fmodel->channels;
     98        f->channels      = 1; //fmodel->channels;
    9999        f->format        = fmodel->format;
    100100        aubio_sndfile_open_wo(f, outputname);
     
    125125/* read frames from file in data
    126126 *  return the number of frames actually read */
    127 int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t * read) {
     127int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t ** read) {
    128128        sf_count_t read_frames;
    129129        int i,j, channels = f->channels;
     
    150150        /* de-interleaving data  */
    151151        for (i=0; i<channels; i++) {
    152                 pread = (smpl_t *)fvec_get_channel(read,i);
     152                pread = (smpl_t *)fvec_get_data(read[i]);
    153153                for (j=0; j<aread; j++) {
    154154                        pread[j] = (smpl_t)f->tmpdata[channels*j+i];
     
    158158}
    159159
     160int
     161aubio_sndfile_read_mono (aubio_sndfile_t * f, int frames, fvec_t * read)
     162{
     163  sf_count_t read_frames;
     164  int i, j, channels = f->channels;
     165  int nsamples = frames * channels;
     166  int aread;
     167  smpl_t *pread;
     168
     169  /* allocate data for de/interleaving reallocated when needed. */
     170  if (nsamples >= f->size) {
     171    AUBIO_ERR ("Maximum aubio_sndfile_read buffer size exceeded.");
     172    return -1;
     173    /*
     174    AUBIO_FREE(f->tmpdata);
     175    f->tmpdata = AUBIO_ARRAY(float,nsamples);
     176    */
     177  }
     178  //f->size = nsamples;
     179
     180  /* do actual reading */
     181  read_frames = sf_read_float (f->handle, f->tmpdata, nsamples);
     182
     183  aread = (int) FLOOR (read_frames / (float) channels);
     184
     185  /* de-interleaving data  */
     186  pread = (smpl_t *) fvec_get_data (read);
     187  for (i = 0; i < channels; i++) {
     188    for (j = 0; j < aread; j++) {
     189      pread[j] += (smpl_t) f->tmpdata[channels * j + i];
     190    }
     191  }
     192  for (j = 0; j < aread; j++) {
     193    pread[j] /= (smpl_t)channels;
     194  }
     195
     196  return aread;
     197}
     198
    160199/* write 'frames' samples to file from data
    161200 *   return the number of frames actually written
    162201 */
    163 int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t * write) {
     202int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t ** write) {
    164203        sf_count_t written_frames = 0;
    165204        int i, j,       channels = f->channels;
     
    180219        /* interleaving data  */
    181220        for (i=0; i<channels; i++) {
    182                 pwrite = (smpl_t *)fvec_get_channel(write,i);
     221                pwrite = (smpl_t *)fvec_get_data(write[i]);
    183222                for (j=0; j<frames; j++) {
    184223                        f->tmpdata[channels*j+i] = (float)pwrite[j];
  • examples/sndfileio.h

    rc17a0ee r4621cd6  
    4949 * Read frames data from file
    5050 */
    51 int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t * read);
     51int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t ** read);
    5252/**
    5353 * Write data of length frames to file
    5454 */
    55 int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t * write);
     55int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t ** write);
    5656/**
    5757 * Close file and delete file object
  • examples/utils.c

    rc17a0ee r4621cd6  
    6161uint_t buffer_size = 512;       //1024;
    6262uint_t overlap_size = 256;      //512;
    63 uint_t channels = 1;
    6463uint_t samplerate = 44100;
    6564
     
    208207  parse_args (argc, argv);
    209208
    210   woodblock = new_fvec (buffer_size, 1);
     209  woodblock = new_fvec (overlap_size);
    211210  if (output_filename || usejack) {
    212211    /* dummy assignement to keep egcs happy */
     
    221220  if (onsetfile) {
    222221    /* read the output sound once */
    223     aubio_sndfile_read (onsetfile, overlap_size, woodblock);
     222    aubio_sndfile_read_mono (onsetfile, overlap_size, woodblock);
    224223  }
    225224
     
    233232    if (verbose)
    234233      aubio_sndfile_info (file);
    235     channels = aubio_sndfile_channels (file);
    236234    samplerate = aubio_sndfile_samplerate (file);
    237235    if (output_filename != NULL)
     
    256254#endif /* HAVE_LASH */
    257255
    258   ibuf = new_fvec (overlap_size, channels);
    259   obuf = new_fvec (overlap_size, channels);
     256  uint_t i;
     257  ibuf = new_fvec (overlap_size);
     258  obuf = new_fvec (overlap_size);
    260259
    261260}
     
    265264examples_common_del (void)
    266265{
     266  uint_t i;
    267267  del_fvec (ibuf);
    268268  del_fvec (obuf);
     
    283283#if HAVE_JACK
    284284    debug ("Jack init ...\n");
    285     jack_setup = new_aubio_jack (channels, channels,
     285    jack_setup = new_aubio_jack (1, 1,
    286286        0, 1, (aubio_process_func_t) process_func);
    287287    debug ("Jack activation ...\n");
     
    301301    frames = 0;
    302302
    303     while ((signed) overlap_size == aubio_sndfile_read (file, overlap_size,
    304             ibuf)) {
    305       process_func (ibuf->data, obuf->data, overlap_size);
     303    while ((signed) overlap_size ==
     304        aubio_sndfile_read_mono (file, overlap_size, ibuf)) {
     305      process_func (&ibuf->data, &obuf->data, overlap_size);
    306306      print ();
    307307      if (output_filename != NULL) {
    308         aubio_sndfile_write (fileout, overlap_size, obuf);
     308        aubio_sndfile_write (fileout, overlap_size, &obuf);
    309309      }
    310310      frames++;
     
    328328  fvec_zeros(obuf);
    329329  for (i = 0; (signed) i < frames_delay; i++) {
    330     process_func (ibuf->data, obuf->data, overlap_size);
     330    process_func (&ibuf->data, &obuf->data, overlap_size);
    331331    print ();
    332332  }
  • examples/utils.h

    rc17a0ee r4621cd6  
    7474extern uint_t buffer_size;
    7575extern uint_t overlap_size;
    76 extern uint_t channels;
    7776extern uint_t samplerate;
    7877
Note: See TracChangeset for help on using the changeset viewer.