Changes in / [8212692:f650860]


Ignore:
Files:
1 added
6 deleted
106 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified examples/aubiomfcc.c

    r8212692 rf650860  
    3333
    3434static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     35  unsigned int i;       /*channels*/
    3536  unsigned int j;       /*frames*/
    3637 
    3738  for (j=0;j<(unsigned)nframes;j++) {
    3839    if(usejack) {
    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);
     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      }
    4346    }
    4447    /*time for fft*/
     
    4750     
    4851      //compute mag spectrum
    49       aubio_pvoc_do (pv, ibuf, fftgrain);
     52      aubio_pvoc_do (pv,ibuf, fftgrain);
    5053     
    5154      //compute mfccs
     
    6972        outmsg("%f\t",frames*overlap_size/(float)samplerate);
    7073        for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) {
    71             outmsg("%f ", fvec_read_sample (mfcc_out, coef_cnt) );
     74            outmsg("%f ", fvec_read_sample (mfcc_out, 0, coef_cnt) );
    7275        }
    7376        outmsg("\n");
     
    8386
    8487  /* phase vocoder */
    85   pv = new_aubio_pvoc (buffer_size, overlap_size);
     88  pv = new_aubio_pvoc (buffer_size, overlap_size, channels);
    8689
    87   fftgrain = new_cvec (buffer_size);
     90  fftgrain = new_cvec (buffer_size, channels);
    8891
    8992  //populating the filter
    9093  mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
    9194 
    92   mfcc_out = new_fvec(n_coefs);
     95  mfcc_out = new_fvec(n_coefs,channels);
    9396 
    9497  //process
  • TabularUnified examples/aubionotes.c

    r8212692 rf650860  
    1919*/
    2020
    21 #define AUBIO_UNSTABLE 1 // for fvec_median
     21#define AUBIO_UNSTABLE 1 // for fvec_median_channel
    2222
    2323#include "utils.h"
     
    5050
    5151static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     52  unsigned int i;       /*channels*/
    5253  unsigned int j;       /*frames*/
    5354  for (j=0;j<(unsigned)nframes;j++) {
    5455    if(usejack) {
    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);
     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      }
    5962    }
    6063    /*time for fft*/
     
    6467     
    6568      aubio_pitch_do (pitchdet, ibuf, pitch_obuf);
    66       pitch = fvec_read_sample(pitch_obuf, 0);
     69      pitch = fvec_read_sample(pitch_obuf, 0, 0);
    6770      if(median){
    6871              note_append(note_buffer, pitch);
     
    7174      /* curlevel is negatif or 1 if silence */
    7275      curlevel = aubio_level_detection(ibuf, silence);
    73       if (fvec_read_sample(onset, 0)) {
     76      if (fvec_read_sample(onset, 0, 0)) {
    7477              /* test for silence */
    7578              if (curlevel == 1.) {
     
    8992
    9093                      for (pos = 0; pos < overlap_size; pos++){
    91                               obuf->data[pos] = woodblock->data[pos];
     94                              obuf->data[0][pos] = woodblock->data[0][pos];
    9295                      }
    9396              }
     
    109112              } // if median
    110113        for (pos = 0; pos < overlap_size; pos++)
    111           obuf->data[pos] = 0.;
     114          obuf->data[0][pos] = 0.;
    112115      }
    113116      /* end of block loop */
     
    128131  uint_t i = 0;
    129132  for (i = 0; i < note_buffer->length - 1; i++) {
    130     note_buffer->data[i] = note_buffer->data[i + 1];
     133    note_buffer->data[0][i] = note_buffer->data[0][i + 1];
    131134  }
    132   note_buffer->data[note_buffer->length - 1] = curnote;
     135  note_buffer->data[0][note_buffer->length - 1] = curnote;
    133136  return;
    134137}
     
    139142  uint_t i;
    140143  for (i = 0; i < note_buffer->length; i++) {
    141     note_buffer2->data[i] = note_buffer->data[i];
     144    note_buffer2->data[0][i] = note_buffer->data[0][i];
    142145  }
    143   return fvec_median (note_buffer2);
     146  return fvec_median_channel (note_buffer2, 0);
    144147}
    145148
     
    147150  examples_common_init(argc,argv);
    148151
    149   o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate);
     152  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
     153          samplerate);
    150154  if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
    151   onset = new_fvec (1);
     155  onset = new_fvec (1, channels);
    152156
    153157  pitchdet = new_aubio_pitch (pitch_mode, buffer_size * 4,
    154           overlap_size, samplerate);
     158          overlap_size, channels, samplerate);
    155159  aubio_pitch_set_tolerance (pitchdet, 0.7);
    156   pitch_obuf = new_fvec (1);
     160  pitch_obuf = new_fvec (1, channels);
    157161  if (median) {
    158       note_buffer = new_fvec (median);
    159       note_buffer2 = new_fvec (median);
     162      note_buffer = new_fvec (median, 1);
     163      note_buffer2 = new_fvec (median, 1);
    160164  }
    161165
  • TabularUnified examples/aubioonset.c

    r8212692 rf650860  
    3131  for (j=0;j<(unsigned)nframes;j++) {
    3232    if(usejack) {
    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);
     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      }
    3739    }
    3840    /*time for fft*/
    39     if (pos == overlap_size-1) {
     41    if (pos == overlap_size-1) {         
    4042      /* block loop */
    4143      aubio_onset_do (o, ibuf, onset);
    42       if ( fvec_read_sample(onset, 0) ) {
     44      if (fvec_read_sample(onset, 0, 0)) {
    4345        fvec_copy (woodblock, obuf);
    4446      } else {
     
    5355}
    5456
    55 static void
    56 process_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   }
     57static 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      }
    7171}
    7272
     
    7575  examples_common_init(argc,argv);
    7676
    77   o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate);
     77  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
     78          samplerate);
    7879  if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
    79   onset = new_fvec (1);
     80  onset = new_fvec (1, channels);
    8081
    8182  examples_common_process(aubio_process,process_print);
  • TabularUnified examples/aubiopitch.c

    r8212692 rf650860  
    2727
    2828static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     29  unsigned int i;       /*channels*/
    2930  unsigned int j;       /*frames*/
    3031  for (j=0;j<(unsigned)nframes;j++) {
    3132    if(usejack) {
    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);
     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      }
    3639    }
    3740    /*time for fft*/
     
    3942      /* block loop */
    4043      aubio_pitch_do (o, ibuf, pitch);
    41       if (fvec_read_sample(pitch, 0)) {
     44      if (fvec_read_sample(pitch, 0, 0)) {
    4245        for (pos = 0; pos < overlap_size; pos++){
    4346          // TODO, play sine at this freq
     
    5659static void process_print (void) {
    5760      if (!verbose && usejack) return;
    58       smpl_t pitch_found = fvec_read_sample(pitch, 0);
     61      smpl_t pitch_found = fvec_read_sample(pitch, 0, 0);
    5962      outmsg("%f %f\n",(frames)
    6063              *overlap_size/(float)samplerate, pitch_found);
     
    6467  examples_common_init(argc,argv);
    6568
    66   o = new_aubio_pitch (onset_mode, buffer_size, overlap_size, samplerate);
    67   pitch = new_fvec (1);
     69  o = new_aubio_pitch (onset_mode, buffer_size, overlap_size, channels,
     70          samplerate);
     71  pitch = new_fvec (1, channels);
    6872
    6973  examples_common_process(aubio_process,process_print);
  • TabularUnified examples/aubioquiet.c

    r8212692 rf650860  
    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*/
    2829  unsigned int j;       /*frames*/
    2930  for (j=0;j<(unsigned)nframes;j++) {
    3031    if(usejack) {
    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);
     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      }
    3538    }
    3639    /*time for fft*/
     
    3841      /* test for silence */
    3942      if (aubio_silence_detection(ibuf, silence)==1) {
    40         if (wassilence==1) issilence = 1;
    41         else issilence = 2;
     43        if (wassilence==1) issilence = 1;
     44        else issilence = 2;
    4245        wassilence=1;
    4346      } else {
    44         if (wassilence<=0) issilence = 0;
    45         else issilence = -1;
     47        if (wassilence<=0) issilence = 0;
     48        else issilence = -1;
    4649        wassilence=0;
    4750      }
  • TabularUnified examples/aubiotrack.c

    r8212692 rf650860  
    2929
    3030static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
     31  unsigned int i;       /*channels*/
    3132  unsigned int j;       /*frames*/
    3233  for (j=0;j<(unsigned)nframes;j++) {
    3334    if(usejack) {
    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);
     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      }
    3841    }
    3942    /*time for fft*/
     
    4144      /* block loop */
    4245      aubio_tempo_do (bt,ibuf,tempo_out);
    43       istactus = fvec_read_sample (tempo_out, 0);
    44       isonset = fvec_read_sample (tempo_out, 1);
     46      istactus = fvec_read_sample (tempo_out, 0, 0);
     47      isonset = fvec_read_sample (tempo_out, 0, 1);
    4548      if (istactus > 0.) {
    4649        fvec_copy (woodblock, obuf);
     
    7376  examples_common_init(argc,argv);
    7477
    75   tempo_out = new_fvec(2);
    76   bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, samplerate);
     78  tempo_out = new_fvec(2,channels);
     79  bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels, samplerate);
    7780  if (threshold != 0.) aubio_tempo_set_threshold (bt, threshold);
    7881
  • TabularUnified examples/sndfileio.c

    r8212692 rf650860  
    9696        aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t);
    9797        f->samplerate    = fmodel->samplerate;
    98         f->channels      = 1; //fmodel->channels;
     98        f->channels      = 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_data(read[i]);
     152                pread = (smpl_t *)fvec_get_channel(read,i);
    153153                for (j=0; j<aread; j++) {
    154154                        pread[j] = (smpl_t)f->tmpdata[channels*j+i];
     
    158158}
    159159
    160 int
    161 aubio_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 
    199160/* write 'frames' samples to file from data
    200161 *   return the number of frames actually written
    201162 */
    202 int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t ** write) {
     163int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t * write) {
    203164        sf_count_t written_frames = 0;
    204165        int i, j,       channels = f->channels;
     
    219180        /* interleaving data  */
    220181        for (i=0; i<channels; i++) {
    221                 pwrite = (smpl_t *)fvec_get_data(write[i]);
     182                pwrite = (smpl_t *)fvec_get_channel(write,i);
    222183                for (j=0; j<frames; j++) {
    223184                        f->tmpdata[channels*j+i] = (float)pwrite[j];
  • TabularUnified examples/sndfileio.h

    r8212692 rf650860  
    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
  • TabularUnified examples/utils.c

    r8212692 rf650860  
    6161uint_t buffer_size = 512;       //1024;
    6262uint_t overlap_size = 256;      //512;
     63uint_t channels = 1;
    6364uint_t samplerate = 44100;
    6465
     
    216217    if (verbose)
    217218      aubio_sndfile_info (file);
     219    channels = aubio_sndfile_channels (file);
    218220    samplerate = aubio_sndfile_samplerate (file);
    219221    if (output_filename != NULL)
     
    263265examples_common_del (void)
    264266{
    265   uint_t i;
    266267  del_fvec (ibuf);
    267268  del_fvec (obuf);
     
    282283#if HAVE_JACK
    283284    debug ("Jack init ...\n");
    284     jack_setup = new_aubio_jack (1, 1,
     285    jack_setup = new_aubio_jack (channels, channels,
    285286        0, 1, (aubio_process_func_t) process_func);
    286287    debug ("Jack activation ...\n");
     
    300301    frames = 0;
    301302
    302     while ((signed) overlap_size ==
    303         aubio_sndfile_read_mono (file, overlap_size, ibuf)) {
    304       process_func (&ibuf->data, &obuf->data, overlap_size);
     303    while ((signed) overlap_size == aubio_sndfile_read (file, overlap_size,
     304            ibuf)) {
     305      process_func (ibuf->data, obuf->data, overlap_size);
    305306      print ();
    306307      if (output_filename != NULL) {
    307         aubio_sndfile_write (fileout, overlap_size, &obuf);
     308        aubio_sndfile_write (fileout, overlap_size, obuf);
    308309      }
    309310      frames++;
     
    327328  fvec_zeros(obuf);
    328329  for (i = 0; (signed) i < frames_delay; i++) {
    329     process_func (&ibuf->data, &obuf->data, overlap_size);
     330    process_func (ibuf->data, obuf->data, overlap_size);
    330331    print ();
    331332  }
  • TabularUnified examples/utils.h

    r8212692 rf650860  
    7474extern uint_t buffer_size;
    7575extern uint_t overlap_size;
     76extern uint_t channels;
    7677extern uint_t samplerate;
    7778
  • TabularUnified interfaces/python/aubio-types.h

    r8212692 rf650860  
    66#include <aubio.h>
    77
    8 #define Py_default_vector_length 1024
    9 #define Py_default_vector_height 1
     8#define Py_default_vector_length   1024
     9#define Py_default_vector_channels 1
    1010
    1111#define Py_aubio_default_samplerate 44100
     
    1818#endif
    1919
    20 // special python type for cvec
     20/**
     21
     22Defining this constant to 1 will allow PyAubio_CastToFvec to convert from data
     23types different than NPY_FLOAT to and fvec, and therefore creating a copy of
     24it.
     25
     26*/
     27#define AUBIO_DO_CASTING 0
     28
     29typedef struct
     30{
     31  PyObject_HEAD
     32  fvec_t * o;
     33  uint_t length;
     34  uint_t channels;
     35} Py_fvec;
     36extern PyTypeObject Py_fvecType;
     37extern PyObject *PyAubio_FvecToArray (Py_fvec * self);
     38extern PyObject *PyAubio_CFvecToArray (fvec_t * self);
     39extern Py_fvec *PyAubio_ArrayToFvec (PyObject * self);
     40
    2141typedef struct
    2242{
     
    2747} Py_cvec;
    2848extern PyTypeObject Py_cvecType;
     49extern PyObject *PyAubio_CvecToArray (Py_cvec * self);
     50extern Py_cvec *PyAubio_ArrayToCvec (PyObject * self);
    2951
    30 // defined in aubio-proxy.c
    31 extern PyObject *PyAubio_CFvecToArray (fvec_t * self);
    32 extern fvec_t *PyAubio_ArrayToCFvec (PyObject * self);
    33 
    34 extern Py_cvec *PyAubio_CCvecToPyCvec (cvec_t * self);
    35 extern cvec_t *PyAubio_ArrayToCCvec (PyObject *input);
    36 
    37 extern PyObject *PyAubio_CFmatToArray (fmat_t * self);
    38 extern fmat_t *PyAubio_ArrayToCFmat (PyObject *input);
    39 
    40 // hand written wrappers
    4152extern PyTypeObject Py_filterType;
    4253
     
    4657
    4758extern PyTypeObject Py_pvocType;
    48 
  • TabularUnified interfaces/python/aubiomodule.c

    r8212692 rf650860  
    1212{
    1313  PyObject *input;
    14   fvec_t *vec;
     14  Py_fvec *vec;
    1515  smpl_t alpha;
    1616  PyObject *result;
     
    2424  }
    2525
    26   vec = PyAubio_ArrayToCFvec (input);
     26  vec = PyAubio_ArrayToFvec (input);
    2727
    2828  if (vec == NULL) {
     
    3131
    3232  // compute the function
    33   result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha));
     33  result = Py_BuildValue ("f", fvec_alpha_norm (vec->o, alpha));
    3434  if (result == NULL) {
    3535    return NULL;
     
    4545{
    4646  PyObject *input;
    47   fvec_t *vec;
     47  Py_fvec *vec;
    4848  PyObject *result;
    4949
     
    5656  }
    5757
    58   vec = PyAubio_ArrayToCFvec (input);
     58  vec = PyAubio_ArrayToFvec (input);
    5959
    6060  if (vec == NULL) {
     
    6363
    6464  // compute the function
    65   result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec));
     65  result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec->o));
    6666  if (result == NULL) {
    6767    return NULL;
     
    7373static char Py_min_removal_doc[] = "compute zero crossing rate";
    7474
    75 static PyObject *
     75static PyObject * 
    7676Py_min_removal(PyObject * self, PyObject * args)
    7777{
    7878  PyObject *input;
    79   fvec_t *vec;
     79  Py_fvec *vec;
    8080
    8181  if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
     
    8787  }
    8888
    89   vec = PyAubio_ArrayToCFvec (input);
     89  vec = PyAubio_ArrayToFvec (input);
    9090
    9191  if (vec == NULL) {
     
    9494
    9595  // compute the function
    96   fvec_min_removal (vec);
     96  fvec_min_removal (vec->o);
    9797
    9898  // since this function does not return, we could return None
    9999  //return Py_None;
    100   // however it is convenient to return the modified vector
    101   return (PyObject *) PyAubio_CFvecToArray(vec);
     100  // however it is convenient to return the modified vector 
     101  return (PyObject *) PyAubio_FvecToArray(vec);
    102102  // or even without converting it back to an array
    103103  //Py_INCREF(vec);
     
    107107static PyMethodDef aubio_methods[] = {
    108108  {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc},
    109   {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS,
     109  {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS, 
    110110    Py_zero_crossing_rate_doc},
    111111  {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc},
     
    121121  int err;
    122122
    123   if (   (PyType_Ready (&Py_cvecType) < 0)
    124       || (PyType_Ready (&Py_filterType) < 0)
    125       || (PyType_Ready (&Py_filterbankType) < 0)
    126       || (PyType_Ready (&Py_fftType) < 0)
    127       || (PyType_Ready (&Py_pvocType) < 0)
     123  if ((PyType_Ready (&Py_fvecType) < 0)
     124      || (PyType_Ready (&Py_cvecType) < 0)
     125      || (PyType_Ready (&Py_filterType) < 0)
     126      || (PyType_Ready (&Py_filterbankType) < 0)
     127      || (PyType_Ready (&Py_fftType) < 0)
     128      || (PyType_Ready (&Py_pvocType) < 0)
    128129      // generated objects
    129130      || (generated_types_ready() < 0 )
     
    145146  }
    146147
     148  Py_INCREF (&Py_fvecType);
     149  PyModule_AddObject (m, "fvec", (PyObject *) & Py_fvecType);
    147150  Py_INCREF (&Py_cvecType);
    148151  PyModule_AddObject (m, "cvec", (PyObject *) & Py_cvecType);
  • TabularUnified interfaces/python/aubiowraphell.h

    r8212692 rf650860  
    9494
    9595// some more helpers
    96 #define AUBIO_NEW_VEC(name, type, lengthval) \
     96#define AUBIO_NEW_VEC(name, type, lengthval, channelsval) \
    9797  name = (type *) PyObject_New (type, & type ## Type); \
     98  name->channels = channelsval; \
    9899  name->length = lengthval;
  • TabularUnified interfaces/python/gen_pyobject.py

    r8212692 rf650860  
    6969# move into the C library at some point.
    7070defaultsizes = {
    71     'resampler':    'input->length * self->ratio',
    72     'specdesc':     '1',
    73     'onset':        '1',
    74     'pitchyin':     '1',
    75     'pitchyinfft':  '1',
    76     'pitchschmitt': '1',
    77     'pitchmcomb':   '1',
    78     'pitchfcomb':   '1',
    79     'pitch':        '1',
    80     'tss':          'self->hop_size',
    81     'mfcc':         'self->n_coeffs',
    82     'beattracking': 'self->hop_size',
    83     'tempo':        '1',
    84     'peakpicker':   '1',
     71    'resampler':    ('input->length * self->ratio', 'input->channels'),
     72    'specdesc':     ('1', 'fftgrain->channels'),
     73    'onset':        ('1', 'self->channels'),
     74    'pitchyin':     ('1', 'in->channels'),
     75    'pitchyinfft':  ('1', 'in->channels'),
     76    'pitchschmitt': ('1', 'in->channels'),
     77    'pitchmcomb':   ('1', 'self->channels'),
     78    'pitchfcomb':   ('1', 'self->channels'),
     79    'pitch':        ('1', 'self->channels'),
     80    'tss':          ('self->hop_size', 'self->channels'),
     81    'mfcc':         ('self->n_coeffs', 'in->channels'),
     82    'beattracking': ('self->hop_size', 'self->channels'),
     83    'tempo':        ('1', 'self->channels'),
     84    'peakpicker':   ('1', 'self->channels'),
    8585}
    8686
     
    9999    'hop_size': 'Py_default_vector_length / 2',
    100100    # these should be alright
     101    'channels': 'Py_default_vector_channels',
    101102    'samplerate': 'Py_aubio_default_samplerate',
    102103    # now for the non obvious ones
     
    123124}
    124125
    125 # python to aubio
     126# aubio to pyaubio
     127aubio2pyaubio = {
     128    'fvec_t*': 'Py_fvec',
     129    'cvec_t*': 'Py_cvec',
     130}
     131
     132# array to aubio
    126133aubiovecfrompyobj = {
    127     'fvec_t*': 'PyAubio_ArrayToCFvec',
    128     'cvec_t*': 'PyAubio_ArrayToCCvec',
    129 }
    130 
    131 # aubio to python
     134    'fvec_t*': 'PyAubio_ArrayToFvec',
     135    'cvec_t*': 'PyAubio_ArrayToCvec',
     136}
     137
     138# aubio to array
    132139aubiovectopyobj = {
     140    'fvec_t*': 'PyAubio_FvecToArray',
     141    'cvec_t*': 'PyAubio_CvecToArray',
     142}
     143
     144aubiovectopyobj_new = {
    133145    'fvec_t*': 'PyAubio_CFvecToArray',
    134     'cvec_t*': 'PyAubio_CCvecToPyCvec',
     146    'cvec_t*': 'PyAubio_CCvecToArray',
    135147    'smpl_t': 'PyFloat_FromDouble',
    136148}
     
    139151    newparams = get_params_types_names(newfunc)
    140152    # self->param1, self->param2, self->param3
    141     if len(newparams):
    142         selfparams = ', self->'+', self->'.join([p[1] for p in newparams])
    143     else:
    144         selfparams = ''
     153    selfparams = ', self->'.join([p[1] for p in newparams])
    145154    # "param1", "param2", "param3"
    146155    paramnames = ", ".join(["\""+p[1]+"\"" for p in newparams])
     
    170179Py_%(name)s_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds)
    171180{
    172   Py_%(name)s *self;
    173181""" % locals()
    174182    for ptype, pname in newparams:
     
    178186""" % locals()
    179187    # now the actual PyArg_Parse
    180     if len(paramnames):
    181         s += """\
     188    s += """\
     189  Py_%(name)s *self;
    182190  static char *kwlist[] = { %(paramnames)s, NULL };
    183191
     
    186194    return NULL;
    187195  }
    188 """ % locals()
    189     s += """\
    190196
    191197  self = (Py_%(name)s *) pytype->tp_alloc (pytype, 0);
     
    232238}
    233239
    234 AUBIO_INIT(%(name)s %(selfparams)s)
     240AUBIO_INIT(%(name)s, self->%(selfparams)s)
    235241
    236242AUBIO_DEL(%(name)s)
     
    259265    inputdefs = "\n  ".join(["PyObject * " + p[-1] + "_obj;" for p in inputparams])
    260266    inputvecs = "\n  ".join(map(lambda p: \
    261                 p[0] + p[-1] + ";", inputparams))
     267                aubio2pyaubio[p[0]]+" * " + p[-1] + ";", inputparams))
    262268    parseinput = ""
    263269    for p in inputparams:
     
    279285        #assert len(outputparams) == 1, \
    280286        #    "too many output parameters"
    281         outputvecs = "\n  ".join([p[0] + p[-1] + ";" for p in outputparams])
     287        outputvecs = "\n  ".join([aubio2pyaubio[p[0]]+" * " + p[-1] + ";" for p in outputparams])
    282288        outputcreate = "\n  ".join(["""\
    283   %(name)s = new_%(autype)s (%(length)s);""" % \
    284     {'name': p[-1], 'pytype': p[0], 'autype': p[0][:-3],
    285         'length': defaultsizes[name]} \
     289AUBIO_NEW_VEC(%(name)s, %(pytype)s, %(length)s, %(channels)s)
     290  %(name)s->o = new_%(autype)s (%(length)s, %(channels)s);""" % \
     291    {'name': p[-1], 'pytype': aubio2pyaubio[p[0]], 'autype': p[0][:-3],
     292        'length': defaultsizes[name][0], 'channels': defaultsizes[name][1]} \
    286293        for p in outputparams])
    287294        if len(outputparams) > 1:
     
    301308
    302309    # build the parameters for the  _do() call
    303     doparams_string = "self->o, " + ", ".join([p[-1] for p in doparams])
     310    doparams_string = "self->o, " + ", ".join([p[-1]+"->o" for p in doparams])
    304311
    305312    # put it all together
     
    409416            "get method has more than one parameter %s" % params
    410417        getter_args = "self->o"
    411         returnval = "(PyObject *)" + aubiovectopyobj[out_type] + " (tmp)"
     418        returnval = "(PyObject *)" + aubiovectopyobj_new[out_type] + " (tmp)"
    412419        shortname = method_name.split(name+'_')[-1]
    413420        method_defs += """\
  • TabularUnified interfaces/python/py-cvec.c

    r8212692 rf650860  
    44
    55class cvec():
    6     def __init__(self, length = 1024):
     6    def __init__(self, length = 1024, channels = 1):
    77        self.length = length
    8         self.norm = array(length)
    9         self.phas = array(length)
    10 
     8        self.channels = channels
     9        self.norm = array(length, channels)
     10        self.phas = array(length, channels)
    1111*/
     12
    1213
    1314static char Py_cvec_doc[] = "cvec object";
     
    1617Py_cvec_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
    1718{
    18   int length= 0;
     19  int length= 0, channels = 0;
    1920  Py_cvec *self;
    20   static char *kwlist[] = { "length", NULL };
    21 
    22   if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist,
    23           &length)) {
     21  static char *kwlist[] = { "length", "channels", NULL };
     22
     23  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
     24          &length, &channels)) {
    2425    return NULL;
    2526  }
     
    2930
    3031  self->length = Py_default_vector_length / 2 + 1;
     32  self->channels = Py_default_vector_channels;
    3133
    3234  if (self == NULL) {
     
    4244  }
    4345
     46  if (channels > 0) {
     47    self->channels = channels;
     48  } else if (channels < 0) {
     49    PyErr_SetString (PyExc_ValueError,
     50        "can not use negative number of channels");
     51    return NULL;
     52  }
     53
    4454  return (PyObject *) self;
    4555}
     
    4858Py_cvec_init (Py_cvec * self, PyObject * args, PyObject * kwds)
    4959{
    50   self->o = new_cvec ((self->length - 1) * 2);
     60  self->o = new_cvec ((self->length - 1) * 2, self->channels);
    5161  if (self->o == NULL) {
    5262    return -1;
     
    7080  PyObject *result = NULL;
    7181
    72   format = PyString_FromString ("aubio cvec of %d elements");
     82  format = PyString_FromString ("aubio cvec of %d elements with %d channels");
    7383  if (format == NULL) {
    7484    goto fail;
    7585  }
    7686
    77   args = Py_BuildValue ("I", self->length);
     87  args = Py_BuildValue ("II", self->length, self->channels);
    7888  if (args == NULL) {
    7989    goto fail;
    8090  }
    81   cvec_print ( self->o );
     91  //cvec_print ( self->o );
    8292
    8393  result = PyString_Format (format, args);
     
    90100}
    91101
     102Py_cvec *
     103PyAubio_ArrayToCvec (PyObject *input) {
     104  PyObject *array;
     105  Py_cvec *vec;
     106  uint_t i;
     107  // parsing input object into a Py_cvec
     108  if (PyObject_TypeCheck (input, &Py_cvecType)) {
     109    // input is an cvec, nothing else to do
     110    vec = (Py_cvec *) input;
     111  } else if (PyArray_Check(input)) {
     112
     113    // we got an array, convert it to an cvec
     114    if (PyArray_NDIM (input) == 0) {
     115      PyErr_SetString (PyExc_ValueError, "input array is a scalar");
     116      goto fail;
     117    } else if (PyArray_NDIM (input) > 2) {
     118      PyErr_SetString (PyExc_ValueError,
     119          "input array has more than two dimensions");
     120      goto fail;
     121    }
     122
     123    if (!PyArray_ISFLOAT (input)) {
     124      PyErr_SetString (PyExc_ValueError, "input array should be float");
     125      goto fail;
     126#if AUBIO_DO_CASTING
     127    } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) {
     128      // input data type is not float32, casting
     129      array = PyArray_Cast ( (PyArrayObject*) input, AUBIO_NPY_SMPL);
     130      if (array == NULL) {
     131        PyErr_SetString (PyExc_IndexError, "failed converting to NPY_FLOAT");
     132        goto fail;
     133      }
     134#else
     135    } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) {
     136      PyErr_SetString (PyExc_ValueError, "input array should be float32");
     137      goto fail;
     138#endif
     139    } else {
     140      // input data type is float32, nothing else to do
     141      array = input;
     142    }
     143
     144    // create a new cvec object
     145    vec = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
     146    if (PyArray_NDIM (array) == 1) {
     147      PyErr_SetString (PyExc_ValueError,
     148          "input array should be have at least two rows for norm and phas");
     149      goto fail;
     150    } else if (PyArray_NDIM (array) == 2) {
     151      vec->channels = 1;
     152      vec->length = PyArray_SIZE (array);
     153    } else {
     154      vec->channels = PyArray_DIM (array, 0) / 2;
     155      vec->length = PyArray_DIM (array, 1);
     156    }
     157
     158    // no need to really allocate cvec, just its struct member
     159    // vec->o = new_cvec (vec->length, vec->channels);
     160    vec->o = (cvec_t *)malloc(sizeof(cvec_t));
     161    vec->o->length = vec->length; vec->o->channels = vec->channels;
     162    vec->o->norm = (smpl_t**)malloc(vec->o->channels * sizeof(smpl_t*));
     163    vec->o->phas = (smpl_t**)malloc(vec->o->channels * sizeof(smpl_t*));
     164    // hat data[i] point to array line
     165    for (i = 0; i < vec->channels; i+=2) {
     166      vec->o->norm[i] = (smpl_t *) PyArray_GETPTR1 (array, i);
     167      vec->o->phas[i] = (smpl_t *) PyArray_GETPTR1 (array, i+1);
     168    }
     169
     170  } else {
     171    PyErr_SetString (PyExc_ValueError, "can only accept array or cvec as input");
     172    return NULL;
     173  }
     174
     175  return vec;
     176
     177fail:
     178  return NULL;
     179}
     180
     181PyObject *
     182PyAubio_CvecToArray (Py_cvec * self)
     183{
     184  PyObject *array = NULL;
     185  uint_t i;
     186  npy_intp dims[] = { self->o->length, 1 };
     187  PyObject *concat = PyList_New (0), *tmp = NULL;
     188  for (i = 0; i < self->channels; i++) {
     189    tmp = PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->norm[i]);
     190    PyList_Append (concat, tmp);
     191    Py_DECREF (tmp);
     192    tmp = PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->phas[i]);
     193    PyList_Append (concat, tmp);
     194    Py_DECREF (tmp);
     195  }
     196  array = PyArray_FromObject (concat, NPY_FLOAT, 2, 2);
     197  Py_DECREF (concat);
     198  return array;
     199}
     200
    92201PyObject *
    93202PyAubio_CvecNormToArray (Py_cvec * self)
    94203{
     204  PyObject *array = NULL;
     205  uint_t i;
    95206  npy_intp dims[] = { self->o->length, 1 };
    96   return PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->norm);
     207  PyObject *concat = PyList_New (0), *tmp = NULL;
     208  for (i = 0; i < self->channels; i++) {
     209    tmp = PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->norm[i]);
     210    PyList_Append (concat, tmp);
     211    Py_DECREF (tmp);
     212  }
     213  array = PyArray_FromObject (concat, NPY_FLOAT, 2, 2);
     214  Py_DECREF (concat);
     215  return array;
    97216}
    98217
     
    101220PyAubio_CvecPhasToArray (Py_cvec * self)
    102221{
     222  PyObject *array = NULL;
     223  uint_t i;
    103224  npy_intp dims[] = { self->o->length, 1 };
    104   return PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->phas);
     225  PyObject *concat = PyList_New (0), *tmp = NULL;
     226  for (i = 0; i < self->channels; i++) {
     227    tmp = PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->phas[i]);
     228    PyList_Append (concat, tmp);
     229    Py_DECREF (tmp);
     230  }
     231  array = PyArray_FromObject (concat, NPY_FLOAT, 2, 2);
     232  Py_DECREF (concat);
     233  return array;
    105234}
    106235
     
    126255Py_cvec_set_norm (Py_cvec * vec, PyObject *input, void * closure)
    127256{
     257  uint_t i;
    128258  PyObject * array;
    129259  if (input == NULL) {
     
    153283
    154284    // check input array dimensions
    155     if (PyArray_NDIM (array) != 1) {
    156       PyErr_Format (PyExc_ValueError,
    157           "input array has %d dimensions, not 1",
    158           PyArray_NDIM (array));
    159       goto fail;
    160     } else {
     285    if (PyArray_NDIM (array) == 1) {
     286      if (vec->channels != 1) {
     287          PyErr_SetString (PyExc_ValueError,
     288                  "input array should have more than one channel");
     289          goto fail;
     290      }
    161291      if (vec->o->length != PyArray_SIZE (array)) {
    162292          PyErr_Format (PyExc_ValueError,
     
    165295          goto fail;
    166296      }
    167     }
    168 
    169     vec->o->norm = (smpl_t *) PyArray_GETPTR1 (array, 0);
     297    } else {
     298      if (vec->channels != PyArray_DIM (array, 0)) {
     299          PyErr_Format (PyExc_ValueError,
     300                  "input array has %d channels, but vector has %d channels",
     301                  PyArray_DIM (array, 0), vec->channels);
     302          goto fail;
     303      }
     304      if (vec->o->length != PyArray_DIM (array, 1)) {
     305          PyErr_Format (PyExc_ValueError,
     306                  "input array has length %d, but vector has length %d",
     307                  PyArray_DIM (array, 1), vec->o->length);
     308          goto fail;
     309      }
     310    }
     311
     312    for (i = 0; i < vec->channels; i++) {
     313      vec->o->norm[i] = (smpl_t *) PyArray_GETPTR1 (array, i);
     314    }
    170315
    171316  } else {
     
    184329Py_cvec_set_phas (Py_cvec * vec, PyObject *input, void * closure)
    185330{
     331  uint_t i;
    186332  PyObject * array;
    187333  if (input == NULL) {
     
    211357
    212358    // check input array dimensions
    213     if (PyArray_NDIM (array) != 1) {
    214       PyErr_Format (PyExc_ValueError,
    215           "input array has %d dimensions, not 1",
    216           PyArray_NDIM (array));
    217       goto fail;
    218     } else {
     359    if (PyArray_NDIM (array) == 1) {
     360      if (vec->channels != 1) {
     361          PyErr_SetString (PyExc_ValueError,
     362                  "input array should have more than one channel");
     363          goto fail;
     364      }
    219365      if (vec->o->length != PyArray_SIZE (array)) {
    220366          PyErr_Format (PyExc_ValueError,
     
    223369          goto fail;
    224370      }
    225     }
    226 
    227     vec->o->phas = (smpl_t *) PyArray_GETPTR1 (array, 0);
     371    } else {
     372      if (vec->channels != PyArray_DIM (array, 0)) {
     373          PyErr_Format (PyExc_ValueError,
     374                  "input array has %d channels, but vector has %d channels",
     375                  PyArray_DIM (array, 0), vec->channels);
     376          goto fail;
     377      }
     378      if (vec->o->length != PyArray_DIM (array, 1)) {
     379          PyErr_Format (PyExc_ValueError,
     380                  "input array has length %d, but vector has length %d",
     381                  PyArray_DIM (array, 1), vec->o->length);
     382          goto fail;
     383      }
     384    }
     385
     386    for (i = 0; i < vec->channels; i++) {
     387      vec->o->phas[i] = (smpl_t *) PyArray_GETPTR1 (array, i);
     388    }
    228389
    229390  } else {
     
    237398fail:
    238399  return 1;
     400}
     401
     402static Py_ssize_t
     403Py_cvec_getchannels (Py_cvec * self)
     404{
     405  return self->channels;
     406}
     407
     408static PyObject *
     409Py_cvec_getitem (Py_cvec * self, Py_ssize_t index)
     410{
     411  PyObject *array;
     412
     413  if (index < 0 || index >= self->channels) {
     414    PyErr_SetString (PyExc_IndexError, "no such channel");
     415    return NULL;
     416  }
     417
     418  npy_intp dims[] = { self->length, 1 };
     419  array = PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->norm[index]);
     420  return array;
     421}
     422
     423static int
     424Py_cvec_setitem (Py_cvec * self, Py_ssize_t index, PyObject * o)
     425{
     426  PyObject *array;
     427
     428  if (index < 0 || index >= self->channels) {
     429    PyErr_SetString (PyExc_IndexError, "no such channel");
     430    return -1;
     431  }
     432
     433  array = PyArray_FROM_OT (o, NPY_FLOAT);
     434  if (array == NULL) {
     435    PyErr_SetString (PyExc_ValueError, "should be an array of float");
     436    goto fail;
     437  }
     438
     439  if (PyArray_NDIM (array) != 1) {
     440    PyErr_SetString (PyExc_ValueError, "should be a one-dimensional array");
     441    goto fail;
     442  }
     443
     444  if (PyArray_SIZE (array) != self->length) {
     445    PyErr_SetString (PyExc_ValueError,
     446        "should be an array of same length as target cvec");
     447    goto fail;
     448  }
     449
     450  self->o->norm[index] = (smpl_t *) PyArray_GETPTR1 (array, 0);
     451
     452  return 0;
     453
     454fail:
     455  return -1;
    239456}
    240457
     
    243460  {"length", T_INT, offsetof (Py_cvec, length), READONLY,
    244461      "length attribute"},
     462  {"channels", T_INT, offsetof (Py_cvec, channels), READONLY,
     463      "channels attribute"},
    245464  {NULL}                        /* Sentinel */
    246465};
    247466
    248467static PyMethodDef Py_cvec_methods[] = {
     468  {"__array__", (PyCFunction) PyAubio_CvecToArray, METH_NOARGS,
     469      "Returns the content of this cvec as a numpy array"},
    249470  {NULL}
    250471};
     
    252473static PyGetSetDef Py_cvec_getseters[] = {
    253474  {"norm", (getter)Py_cvec_get_norm, (setter)Py_cvec_set_norm,
    254       "Numpy vector of shape (length,) containing the magnitude",
     475      "Content of the magnitude of this cvec",
    255476      NULL},
    256477  {"phas", (getter)Py_cvec_get_phas, (setter)Py_cvec_set_phas,
    257       "Numpy vector of shape (length,) containing the phase",
     478      "Content of the magnitude of this cvec",
    258479      NULL},
    259480  {NULL} /* sentinel */
    260481};
     482
     483static PySequenceMethods Py_cvec_tp_as_sequence = {
     484  (lenfunc) Py_cvec_getchannels,        /* sq_length         */
     485  0,                                    /* sq_concat         */
     486  0,                                    /* sq_repeat         */
     487  (ssizeargfunc) Py_cvec_getitem,       /* sq_item           */
     488  0,                                    /* sq_slice          */
     489  (ssizeobjargproc) Py_cvec_setitem,    /* sq_ass_item       */
     490  0,                                    /* sq_ass_slice      */
     491  0,                                    /* sq_contains       */
     492  0,                                    /* sq_inplace_concat */
     493  0,                                    /* sq_inplace_repeat */
     494};
     495
    261496
    262497PyTypeObject Py_cvecType = {
     
    273508  (reprfunc) Py_cvec_repr,      /* tp_repr           */
    274509  0,                            /* tp_as_number      */
    275   0, //&Py_cvec_tp_as_sequence,      /* tp_as_sequence    */
     510  &Py_cvec_tp_as_sequence,      /* tp_as_sequence    */
    276511  0,                            /* tp_as_mapping     */
    277512  0,                            /* tp_hash           */
  • TabularUnified interfaces/python/py-fft.c

    r8212692 rf650860  
    33static char Py_fft_doc[] = "fft object";
    44
    5 AUBIO_DECLARE(fft, uint_t win_s)
     5AUBIO_DECLARE(fft, uint_t win_s; uint_t channels)
    66
    77//AUBIO_NEW(fft)
     
    99Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
    1010{
    11   int win_s = 0;
     11  int win_s = 0, channels = 0;
    1212  Py_fft *self;
    13   static char *kwlist[] = { "win_s", NULL };
     13  static char *kwlist[] = { "win_s", "channels", NULL };
    1414
    15   if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist,
    16           &win_s)) {
     15  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
     16          &win_s, &channels)) {
    1717    return NULL;
    1818  }
     
    2525
    2626  self->win_s = Py_default_vector_length;
     27  self->channels = Py_default_vector_channels;
    2728
    2829  if (self == NULL) {
     
    3839  }
    3940
     41  if (channels > 0) {
     42    self->channels = channels;
     43  } else if (channels < 0) {
     44    PyErr_SetString (PyExc_ValueError,
     45        "can not use negative number of filters");
     46    return NULL;
     47  }
     48
    4049  return (PyObject *) self;
    4150}
    4251
    4352
    44 AUBIO_INIT(fft, self->win_s)
     53AUBIO_INIT(fft, self->win_s, self->channels)
    4554
    4655AUBIO_DEL(fft)
     
    5059{
    5160  PyObject *input;
    52   fvec_t *vec;
    53   cvec_t *output;
     61  Py_fvec *vec;
     62  Py_cvec *output;
    5463
    5564  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    5766  }
    5867
    59   vec = PyAubio_ArrayToCFvec (input);
     68  vec = PyAubio_ArrayToFvec (input);
    6069
    6170  if (vec == NULL) {
     
    6372  }
    6473
    65   output = new_cvec(((Py_fft *) self)->win_s);
     74  output = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
     75  output->channels = vec->channels;
     76  output->length = ((Py_fft *) self)->win_s;
     77  output->o = new_cvec(((Py_fft *) self)->win_s, vec->channels);
    6678
    6779  // compute the function
    68   aubio_fft_do (((Py_fft *)self)->o, vec, output);
    69   return (PyObject *)PyAubio_CCvecToPyCvec(output);
     80  aubio_fft_do (((Py_fft *)self)->o, vec->o, output->o);
     81  Py_INCREF(output);
     82  return (PyObject *)output;
     83  //return (PyObject *)PyAubio_CvecToArray(output);
    7084}
    7185
     
    7387  {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
    7488    "size of the window"},
     89  {"channels", T_INT, offsetof (Py_fft, channels), READONLY,
     90    "number of channels"},
    7591AUBIO_MEMBERS_STOP(fft)
    7692
    7793static PyObject *
    78 Py_fft_rdo(Py_fft * self, PyObject * args)
     94Py_fft_rdo(PyObject * self, PyObject * args)
    7995{
    8096  PyObject *input;
    81   cvec_t *vec;
    82   fvec_t *output;
     97  Py_cvec *vec;
     98  Py_fvec *output;
    8399
    84100  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    86102  }
    87103
    88   vec = PyAubio_ArrayToCCvec (input);
     104  vec = PyAubio_ArrayToCvec (input);
    89105
    90106  if (vec == NULL) {
     
    92108  }
    93109
    94   output = new_fvec(self->win_s);
     110  output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType);
     111  output->channels = vec->channels;
     112  output->length = ((Py_fft *) self)->win_s;
     113  output->o = new_fvec(output->length, output->channels);
    95114
    96115  // compute the function
    97   aubio_fft_rdo (((Py_fft *)self)->o, vec, output);
    98   return (PyObject *)PyAubio_CFvecToArray(output);
     116  aubio_fft_rdo (((Py_fft *)self)->o, vec->o, output->o);
     117  return (PyObject *)PyAubio_FvecToArray(output);
    99118}
    100119
  • TabularUnified interfaces/python/py-filter.c

    r8212692 rf650860  
    66  aubio_filter_t * o;
    77  uint_t order;
     8  uint_t channels;
    89} Py_filter;
    910
     
    1314Py_filter_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
    1415{
    15   int order= 0;
     16  int order= 0, channels = 0;
    1617  Py_filter *self;
    17   static char *kwlist[] = { "order", NULL };
     18  static char *kwlist[] = { "order", "channels", NULL };
    1819
    19   if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist,
    20           &order)) {
     20  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
     21          &order, &channels)) {
    2122    return NULL;
    2223  }
     
    2930
    3031  self->order = 7;
     32  self->channels = Py_default_vector_channels;
    3133
    3234  if (order > 0) {
     
    3840  }
    3941
     42  if (channels > 0) {
     43    self->channels = channels;
     44  } else if (channels < 0) {
     45    PyErr_SetString (PyExc_ValueError,
     46        "can not use negative number of channels");
     47    return NULL;
     48  }
     49
    4050  return (PyObject *) self;
    4151}
     
    4454Py_filter_init (Py_filter * self, PyObject * args, PyObject * kwds)
    4555{
    46   self->o = new_aubio_filter (self->order);
     56  self->o = new_aubio_filter (self->order, self->channels);
    4757  if (self->o == NULL) {
    4858    return -1;
     
    6070
    6171static PyObject *
    62 Py_filter_do(Py_filter * self, PyObject * args)
     72Py_filter_do(PyObject * self, PyObject * args)
    6373{
    6474  PyObject *input;
    65   fvec_t *vec;
     75  Py_fvec *vec;
    6676
    6777  if (!PyArg_ParseTuple (args, "O:digital_filter.do", &input)) {
     
    7383  }
    7484
    75   vec = PyAubio_ArrayToCFvec (input);
     85  vec = PyAubio_ArrayToFvec (input);
    7686
    7787  if (vec == NULL) {
     
    8090
    8191  // compute the function
    82   fvec_t * out = new_fvec(vec->length);
    83   aubio_filter_do_outplace (self->o, vec, out);
    84   return PyAubio_CFvecToArray(out);
     92#if 1
     93  aubio_filter_do (((Py_filter *)self)->o, vec->o);
     94  Py_INCREF(vec);
     95  return (PyObject *)vec;
     96#else
     97  Py_fvec *copy = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType);
     98  copy->o = new_fvec(vec->o->length, vec->o->channels);
     99  aubio_filter_do_outplace (((Py_filter *)self)->o, vec->o, copy->o);
     100  return (PyObject *)copy;
     101#endif
    85102}
    86103
     
    125142  {"order", T_INT, offsetof (Py_filter, order), READONLY,
    126143      "order of the filter"},
     144  {"channels", T_INT, offsetof (Py_filter, channels), READONLY,
     145      "number of channels"},
    127146  {NULL}                        /* Sentinel */
    128147};
  • TabularUnified interfaces/python/py-filterbank.c

    r8212692 rf650860  
    5454{
    5555  PyObject *input;
    56   cvec_t *vec;
    57   fvec_t *out;
     56  Py_cvec *vec;
     57  Py_fvec *output;
    5858
    5959  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    6161  }
    6262
    63   vec = PyAubio_ArrayToCCvec (input);
     63  vec = PyAubio_ArrayToCvec (input);
    6464
    6565  if (vec == NULL) {
     
    6767  }
    6868
    69   out = new_fvec (self->n_filters);
     69  output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType);
     70  output->channels = vec->channels;
     71  output->length = self->n_filters;
     72  output->o = new_fvec(self->n_filters, vec->channels);
    7073
    7174  // compute the function
    72   aubio_filterbank_do (self->o, vec, out);
    73   return (PyObject *)PyAubio_CFvecToArray(out);
     75  aubio_filterbank_do (self->o, vec->o, output->o);
     76  return (PyObject *)PyAubio_FvecToArray(output);
    7477}
    7578
     
    8891  PyObject *input;
    8992  uint_t samplerate;
    90   fvec_t *freqs;
     93  Py_fvec *freqs;
    9194  if (!PyArg_ParseTuple (args, "OI", &input, &samplerate)) {
    9295    return NULL;
     
    97100  }
    98101
    99   freqs = PyAubio_ArrayToCFvec (input);
     102  freqs = PyAubio_ArrayToFvec (input);
    100103
    101104  if (freqs == NULL) {
     
    104107
    105108  err = aubio_filterbank_set_triangle_bands (self->o,
    106       freqs, samplerate);
     109      freqs->o, samplerate);
    107110  if (err > 0) {
    108111    PyErr_SetString (PyExc_ValueError,
     
    135138Py_filterbank_get_coeffs (Py_filterbank * self, PyObject *unused)
    136139{
    137   return (PyObject *)PyAubio_CFmatToArray(
    138       aubio_filterbank_get_coeffs (self->o) );
     140  Py_fvec *output = (Py_fvec *) PyObject_New (Py_fvec, &Py_fvecType);
     141  output->channels = self->n_filters;
     142  output->length = self->win_s / 2 + 1;
     143  output->o = aubio_filterbank_get_coeffs (self->o);
     144  return (PyObject *)PyAubio_FvecToArray(output);
    139145}
    140146
  • TabularUnified interfaces/python/py-phasevoc.c

    r8212692 rf650860  
    33static char Py_pvoc_doc[] = "pvoc object";
    44
    5 AUBIO_DECLARE(pvoc, uint_t win_s; uint_t hop_s)
     5AUBIO_DECLARE(pvoc, uint_t win_s; uint_t hop_s; uint_t channels)
    66
    77//AUBIO_NEW(pvoc)
     
    99Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
    1010{
    11   int win_s = 0, hop_s = 0;
     11  int win_s = 0, hop_s = 0, channels = 0;
    1212  Py_pvoc *self;
    13   static char *kwlist[] = { "win_s", "hop_s", NULL };
     13  static char *kwlist[] = { "win_s", "hop_s", "channels", NULL };
    1414
    15   if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
    16           &win_s, &hop_s)) {
     15  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|III", kwlist,
     16          &win_s, &hop_s, &channels)) {
    1717    return NULL;
    1818  }
     
    2626  self->win_s = Py_default_vector_length;
    2727  self->hop_s = Py_default_vector_length/2;
     28  self->channels = Py_default_vector_channels;
    2829
    2930  if (self == NULL) {
     
    4748  }
    4849
     50  if (channels > 0) {
     51    self->channels = channels;
     52  } else if (channels < 0) {
     53    PyErr_SetString (PyExc_ValueError,
     54        "can not use negative number of filters");
     55    return NULL;
     56  }
     57
    4958  return (PyObject *) self;
    5059}
    5160
    5261
    53 AUBIO_INIT(pvoc, self->win_s, self->hop_s)
     62AUBIO_INIT(pvoc, self->win_s, self->hop_s, self->channels)
    5463
    5564AUBIO_DEL(pvoc)
    5665
    5766static PyObject *
    58 Py_pvoc_do(Py_pvoc * self, PyObject * args)
     67Py_pvoc_do(PyObject * self, PyObject * args)
    5968{
    6069  PyObject *input;
    61   fvec_t *vec;
    62   cvec_t *output;
     70  Py_fvec *vec;
     71  Py_cvec *output;
    6372
    6473  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    6675  }
    6776
    68   vec = PyAubio_ArrayToCFvec (input);
     77  vec = PyAubio_ArrayToFvec (input);
    6978
    7079  if (vec == NULL) {
     
    7281  }
    7382
    74   output = new_cvec(self->win_s);
     83  output = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
     84  output->channels = vec->channels;
     85  output->length = ((Py_pvoc *) self)->win_s;
     86  output->o = new_cvec(((Py_pvoc *) self)->win_s, vec->channels);
    7587
    7688  // compute the function
    77   aubio_pvoc_do (self->o, vec, output);
    78   return (PyObject *)PyAubio_CCvecToPyCvec(output);
     89  aubio_pvoc_do (((Py_pvoc *)self)->o, vec->o, output->o);
     90  Py_INCREF(output);
     91  return (PyObject *)output;
     92  //return (PyObject *)PyAubio_CvecToArray(output);
    7993}
    8094
     
    8498  {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
    8599    "size of the hop"},
     100  {"channels", T_INT, offsetof (Py_pvoc, channels), READONLY,
     101    "number of channels"},
    86102AUBIO_MEMBERS_STOP(pvoc)
    87103
    88104static PyObject *
    89 Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
     105Py_pvoc_rdo(PyObject * self, PyObject * args)
    90106{
    91107  PyObject *input;
    92   cvec_t *vec;
    93   fvec_t *output;
     108  Py_cvec *vec;
     109  Py_fvec *output;
    94110
    95111  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    97113  }
    98114
    99   vec = PyAubio_ArrayToCCvec (input);
     115  vec = PyAubio_ArrayToCvec (input);
    100116
    101117  if (vec == NULL) {
     
    103119  }
    104120
    105   output = new_fvec(self->hop_s);
     121  output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType);
     122  output->channels = vec->channels;
     123  output->length = ((Py_pvoc *) self)->hop_s;
     124  output->o = new_fvec(output->length, output->channels);
    106125
    107126  // compute the function
    108   aubio_pvoc_rdo (self->o, vec, output);
    109   return (PyObject *)PyAubio_CFvecToArray(output);
     127  aubio_pvoc_rdo (((Py_pvoc *)self)->o, vec->o, output->o);
     128  return (PyObject *)PyAubio_FvecToArray(output);
    110129}
    111130
  • TabularUnified interfaces/python/setup.py

    r8212692 rf650860  
    1010        Extension("_aubio",
    1111            ["aubiomodule.c",
    12             "aubioproxy.c",
     12            "py-fvec.c",
    1313            "py-cvec.c",
    14             # example without macro
    1514            "py-filter.c",
    16             # macroised
     15            # macroised 
    1716            "py-filterbank.c",
    1817            "py-fft.c",
  • TabularUnified interfaces/python/test_aubio.py

    r8212692 rf650860  
    11from numpy.testing import TestCase, run_module_suite
     2from numpy.testing import assert_equal
     3from _aubio import *
     4from numpy import array
     5
     6AUBIO_DO_CASTING = 0
    27
    38class aubiomodule_test_case(TestCase):
    49
    5   def test_import(self):
     10  def setUp(self):
    611    """ try importing aubio """
    7     import aubio
     12
     13  def test_vector(self):
     14    a = fvec()
     15    a.length, a.channels
     16    a[0]
     17    array(a)
     18    a = fvec(10)
     19    a = fvec(1, 2)
     20    array(a).T
     21    a[0] = range(a.length)
     22    a[1][0] = 2
     23
     24  def test_wrong_values(self):
     25    self.assertRaises (ValueError, fvec, -10)
     26    self.assertRaises (ValueError, fvec, 1, -1)
     27 
     28    a = fvec(2, 3)
     29    self.assertRaises (IndexError, a.__getitem__, 3)
     30    self.assertRaises (IndexError, a[0].__getitem__, 2)
     31
     32  def test_alpha_norm_of_fvec(self):
     33    a = fvec(2, 2)
     34    self.assertEquals (alpha_norm(a, 1), 0)
     35    a[0] = [1, 2]
     36    self.assertEquals (alpha_norm(a, 1), 1.5)
     37    a[1] = [1, 2]
     38    self.assertEquals (alpha_norm(a, 1), 3)
     39    a[0] = [0, 1]; a[1] = [1, 0]
     40    self.assertEquals (alpha_norm(a, 2), 1)
     41
     42  def test_alpha_norm_of_array_of_float32(self):
     43    # check scalar fails
     44    a = array(1, dtype = 'float32')
     45    self.assertRaises (ValueError, alpha_norm, a, 1)
     46    # check 3d array fails
     47    a = array([[[1,2],[3,4]]], dtype = 'float32')
     48    self.assertRaises (ValueError, alpha_norm, a, 1)
     49    # check 1d array
     50    a = array(range(10), dtype = 'float32')
     51    self.assertEquals (alpha_norm(a, 1), 4.5)
     52    # check 2d array
     53    a = array([range(10), range(10)], dtype = 'float32')
     54    self.assertEquals (alpha_norm(a, 1), 9)
     55
     56  def test_alpha_norm_of_array_of_int(self):
     57    a = array(1, dtype = 'int')
     58    self.assertRaises (ValueError, alpha_norm, a, 1)
     59    a = array([[[1,2],[3,4]]], dtype = 'int')
     60    self.assertRaises (ValueError, alpha_norm, a, 1)
     61    a = array(range(10), dtype = 'int')
     62    self.assertRaises (ValueError, alpha_norm, a, 1)
     63
     64  def test_alpha_norm_of_array_of_string (self):
     65    a = "hello"
     66    self.assertRaises (ValueError, alpha_norm, a, 1)
     67
     68  def test_zero_crossing_rate(self):
     69    a = array([0,1,-1], dtype='float32')
     70    self.assertEquals (zero_crossing_rate(a), 1./3 )
     71    a = array([0.]*100, dtype='float32')
     72    self.assertEquals (zero_crossing_rate(a), 0 )
     73    a = array([-1.]*100, dtype='float32')
     74    self.assertEquals (zero_crossing_rate(a), 0 )
     75    a = array([1.]*100, dtype='float32')
     76    self.assertEquals (zero_crossing_rate(a), 0 )
     77
     78  def test_alpha_norm_of_array_of_float64(self):
     79    # check scalar fail
     80    a = array(1, dtype = 'float64')
     81    self.assertRaises (ValueError, alpha_norm, a, 1)
     82    # check 3d array fail
     83    a = array([[[1,2],[3,4]]], dtype = 'float64')
     84    self.assertRaises (ValueError, alpha_norm, a, 1)
     85    if AUBIO_DO_CASTING:
     86      # check float64 1d array fail
     87      a = array(range(10), dtype = 'float64')
     88      self.assertEquals (alpha_norm(a, 1), 4.5)
     89      # check float64 2d array fail
     90      a = array([range(10), range(10)], dtype = 'float64')
     91      self.assertEquals (alpha_norm(a, 1), 9)
     92    else:
     93      # check float64 1d array fail
     94      a = array(range(10), dtype = 'float64')
     95      self.assertRaises (ValueError, alpha_norm, a, 1)
     96      # check float64 2d array fail
     97      a = array([range(10), range(10)], dtype = 'float64')
     98      self.assertRaises (ValueError, alpha_norm, a, 1)
     99
     100  def test_fvec_min_removal_of_array(self):
     101    a = array([20,1,19], dtype='float32')
     102    b = min_removal(a)
     103    assert_equal (array(b), [19, 0, 18])
     104    assert_equal (b, [19, 0, 18])
     105    assert_equal (a, b)
     106    a[0] = 0
     107    assert_equal (a, b)
     108
     109  def test_fvec_min_removal_of_array_float64(self):
     110    a = array([20,1,19], dtype='float64')
     111    if AUBIO_DO_CASTING:
     112      b = min_removal(a)
     113      assert_equal (array(b), [19, 0, 18])
     114      assert_equal (b, [19, 0, 18])
     115      #assert_equal (a, b)
     116    else:
     117      self.assertRaises (ValueError, min_removal, a)
     118     
     119  def test_fvec_min_removal_of_fvec(self):
     120    a = fvec(3, 1)
     121    a[0] = [20, 1, 19]
     122    b = min_removal(a)
     123    assert_equal (array(b), [19, 0, 18])
     124    assert_equal (b, [19, 0, 18])
     125    assert_equal (a, b)
    8126
    9127if __name__ == '__main__':
  • TabularUnified interfaces/python/test_fft.py

    r8212692 rf650860  
    22from numpy.testing import assert_equal, assert_almost_equal
    33# WARNING: numpy also has an fft object
    4 from aubio import fvec, fft, cvec
     4from _aubio import fft, fvec, cvec
    55from numpy import array, shape
    66from math import pi
     
    1010  def test_members(self):
    1111    f = fft()
    12     assert_equal (f.win_s, 1024)
     12    assert_equal ([f.win_s, f.channels], [1024, 1])
     13    f = fft(2048, 4)
     14    assert_equal ([f.win_s, f.channels], [2048, 4])
    1315
    1416  def test_output_dimensions(self):
    1517    """ check the dimensions of output """
    16     win_s = 1024
    17     timegrain = fvec(win_s)
    18     f = fft(win_s)
     18    win_s, chan = 1024, 3
     19    timegrain = fvec(win_s, chan)
     20    f = fft(win_s, chan)
    1921    fftgrain = f (timegrain)
     22    assert_equal (array(fftgrain), 0)
     23    assert_equal (shape(fftgrain), (chan * 2, win_s/2+1))
    2024    assert_equal (fftgrain.norm, 0)
    21     assert_equal (shape(fftgrain.norm), (win_s/2+1,))
     25    assert_equal (shape(fftgrain.norm), (chan, win_s/2+1))
    2226    assert_equal (fftgrain.phas, 0)
    23     assert_equal (shape(fftgrain.phas), (win_s/2+1,))
     27    assert_equal (shape(fftgrain.phas), (chan, win_s/2+1))
    2428
    2529  def test_zeros(self):
    2630    """ check the transform of zeros """
    27     win_s = 512
    28     timegrain = fvec(win_s)
    29     f = fft(win_s)
     31    win_s, chan = 512, 3
     32    timegrain = fvec(win_s, chan)
     33    f = fft(win_s, chan)
    3034    fftgrain = f(timegrain)
    3135    assert_equal ( fftgrain.norm == 0, True )
     
    3640    from random import random
    3741    from math import floor
    38     win_s = 256
     42    win_s, chan = 256, 1
    3943    i = floor(random()*win_s)
    4044    impulse = pi * random()
    41     f = fft(win_s)
    42     timegrain = fvec(win_s)
    43     timegrain[i] = impulse
     45    f = fft(win_s, chan)
     46    timegrain = fvec(win_s, chan)
     47    timegrain[0][i] = impulse
    4448    fftgrain = f ( timegrain )
    45     #self.plot_this ( fftgrain.phas )
     49    #self.plot_this ( fftgrain.phas[0] )
    4650    assert_almost_equal ( fftgrain.norm, impulse, decimal = 6 )
    4751    assert_equal ( fftgrain.phas <= pi, True)
     
    5256    from random import random
    5357    from math import floor
    54     win_s = 256
     58    win_s, chan = 256, 1
    5559    i = 0
    5660    impulse = -10.
    57     f = fft(win_s)
    58     timegrain = fvec(win_s)
    59     timegrain[i] = impulse
     61    f = fft(win_s, chan)
     62    timegrain = fvec(win_s, chan)
     63    timegrain[0][i] = impulse
    6064    fftgrain = f ( timegrain )
    61     #self.plot_this ( fftgrain.phas )
     65    #self.plot_this ( fftgrain.phas[0] )
    6266    assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 6 )
    6367    if impulse < 0:
    6468      # phase can be pi or -pi, as it is not unwrapped
    65       assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )
    66       assert_almost_equal ( fftgrain.phas[0], pi, decimal = 6)
    67       assert_almost_equal ( fftgrain.phas[-1], pi, decimal = 6)
     69      assert_almost_equal ( abs(fftgrain.phas[0][1:-1]) , pi, decimal = 6 )
     70      assert_almost_equal ( fftgrain.phas[0][0], pi, decimal = 6)
     71      assert_almost_equal ( fftgrain.phas[0][-1], pi, decimal = 6)
    6872    else:
    69       assert_equal ( fftgrain.phas[1:-1] == 0, True)
    70       assert_equal ( fftgrain.phas[0] == 0, True)
    71       assert_equal ( fftgrain.phas[-1] == 0, True)
     73      assert_equal ( fftgrain.phas[0][1:-1] == 0, True)
     74      assert_equal ( fftgrain.phas[0][0] == 0, True)
     75      assert_equal ( fftgrain.phas[0][-1] == 0, True)
    7276    # now check the resynthesis
    7377    synthgrain = f.rdo ( fftgrain )
     
    7983
    8084  def test_impulse_at_zero(self):
    81     """ check the transform of one impulse at a index 0 """
    82     win_s = 1024
     85    """ check the transform of one impulse at a index 0 in one channel """
     86    win_s, chan = 1024, 2
    8387    impulse = pi
    84     f = fft(win_s)
    85     timegrain = fvec(win_s)
    86     timegrain[0] = impulse
     88    f = fft(win_s, chan)
     89    timegrain = fvec(win_s, chan)
     90    timegrain[0][0] = impulse
    8791    fftgrain = f ( timegrain )
    8892    #self.plot_this ( fftgrain.phas )
    8993    assert_equal ( fftgrain.phas[0], 0)
    9094    assert_equal ( fftgrain.phas[1], 0)
    91     assert_almost_equal (fftgrain.norm[0], impulse, decimal = 6 )
     95    assert_almost_equal ( fftgrain.norm[0], impulse, decimal = 6 )
     96    assert_equal ( fftgrain.norm[0], impulse)
    9297
    9398  def test_rdo_before_do(self):
    9499    """ check running fft.rdo before fft.do works """
    95     win_s = 1024
     100    win_s, chan = 1024, 2
    96101    impulse = pi
    97     f = fft(win_s)
    98     fftgrain = cvec(win_s)
     102    f = fft(win_s, chan)
     103    fftgrain = cvec(win_s, chan)
    99104    t = f.rdo( fftgrain )
    100105    assert_equal ( t, 0 )
  • TabularUnified interfaces/python/test_filter.py

    r8212692 rf650860  
    11from numpy.testing import TestCase, run_module_suite
    22from numpy.testing import assert_equal, assert_almost_equal
    3 from aubio import fvec, digital_filter
     3from _aubio import *
    44from numpy import array
    55
     
    1212  def test_members(self):
    1313    f = digital_filter()
    14     assert_equal (f.order, 7)
    15     f = digital_filter(5)
    16     assert_equal (f.order, 5)
     14    assert_equal ([f.channels, f.order], [1, 7])
     15    f = digital_filter(5, 2)
     16    assert_equal ([f.channels, f.order], [2, 5])
    1717    f(fvec())
    1818 
    1919  def test_cweighting_error(self):
    20     f = digital_filter (2)
     20    f = digital_filter (2, 1)
    2121    self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
    22     f = digital_filter (8)
     22    f = digital_filter (8, 1)
    2323    self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
    24     f = digital_filter (5)
     24    f = digital_filter (5, 1)
    2525    self.assertRaises ( ValueError, f.set_c_weighting, 4000 )
    26     f = digital_filter (5)
     26    f = digital_filter (5, 1)
    2727    self.assertRaises ( ValueError, f.set_c_weighting, 193000 )
    28     f = digital_filter (7)
     28    f = digital_filter (7, 1)
    2929    self.assertRaises ( ValueError, f.set_a_weighting, 193000 )
    30     f = digital_filter (5)
     30    f = digital_filter (5, 1)
    3131    self.assertRaises ( ValueError, f.set_a_weighting, 192000 )
    3232
    3333  def test_c_weighting(self):
    3434    expected = array_from_text_file('c_weighting_test_simple.expected')
    35     f = digital_filter(5)
     35    f = digital_filter(5, 1)
    3636    f.set_c_weighting(44100)
    3737    v = fvec(32)
    38     v[12] = .5
     38    v[0][12] = .5
    3939    u = f(v)
    4040    assert_almost_equal (expected[1], u)
     
    4242  def test_a_weighting(self):
    4343    expected = array_from_text_file('a_weighting_test_simple.expected')
    44     f = digital_filter(7)
     44    f = digital_filter(7, 1)
    4545    f.set_a_weighting(44100)
    4646    v = fvec(32)
    47     v[12] = .5
     47    v[0][12] = .5
    4848    u = f(v)
    4949    assert_almost_equal (expected[1], u)
     
    5151  def test_a_weighting_parted(self):
    5252    expected = array_from_text_file('a_weighting_test_simple.expected')
    53     f = digital_filter(7)
     53    f = digital_filter(7, 1)
    5454    f.set_a_weighting(44100)
    5555    v = fvec(16)
    56     v[12] = .5
     56    v[0][12] = .5
    5757    u = f(v)
    5858    assert_almost_equal (expected[1][:16], u)
  • TabularUnified interfaces/python/test_filterbank.py

    r8212692 rf650860  
    22from numpy.testing import assert_equal, assert_almost_equal
    33from numpy import array, shape
    4 from aubio import cvec, filterbank
     4from _aubio import *
    55
    66class aubio_filter_test_case(TestCase):
     
    1111    a = f.get_coeffs()
    1212    a.T
    13     assert_equal(shape (a), (40, 512/2 + 1) )
    1413
    1514  def test_other_slaney(self):
     
    2423      #print "sum is", sum(sum(a))
    2524
    26   def test_triangle_freqs_zeros(self):
     25  def test_triangle_freqs(self):
    2726    f = filterbank(9, 1024)
    2827    freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
     
    3029    f.set_triangle_bands(freqs, 48000)
    3130    f.get_coeffs().T
    32     assert_equal ( f(cvec(1024)), 0)
    33 
    34   def test_triangle_freqs_ones(self):
    35     f = filterbank(9, 1024)
    36     freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
    37     freqs = array(freq_list, dtype = 'float32')
    38     f.set_triangle_bands(freqs, 48000)
    39     f.get_coeffs().T
     31    assert_equal ( f(cvec(1024)), [0] * 9)
    4032    spec = cvec(1024)
    41     spec.norm[:] = 1
    42     assert_almost_equal ( f(spec),
    43             [ 0.02070313,  0.02138672,  0.02127604,  0.02135417,
    44         0.02133301, 0.02133301,  0.02133311,  0.02133334,  0.02133345])
     33    spec[0][40:100] = 100
     34    #print f(spec)
    4535
    4636if __name__ == '__main__':
  • TabularUnified interfaces/python/test_onsetdetection.py

    r8212692 rf650860  
    22from numpy.testing import assert_equal, assert_almost_equal
    33# WARNING: numpy also has an fft object
    4 from aubio import specdesc, cvec
     4from _aubio import cvec, specdesc
    55from numpy import array, shape, arange, zeros, log
    66from math import pi
     
    1010    def test_members(self):
    1111        o = specdesc()
    12         assert_equal ([o.buf_size, o.method],
    13             [1024, "default"])
     12        assert_equal ([o.buf_size, o.channels, o.method],
     13            [1024, 1, "default"])
     14        o = specdesc("complex", 512, 2)
     15        assert_equal ([o.buf_size, o.channels, o.method],
     16            [512, 2, "complex"])
    1417
    1518    def test_hfc(self):
     
    1922        a = arange(c.length, dtype='float32')
    2023        c.norm = a
    21         assert_equal (a, c.norm)
     24        assert_equal (a, c.norm[0])
    2225        assert_equal ( sum(a*(a+1)), o(c))
    2326
     
    2831        a = arange(c.length, dtype='float32')
    2932        c.norm = a
    30         assert_equal (a, c.norm)
     33        assert_equal (a, c.norm[0])
    3134        # the previous run was on zeros, so previous frames are still 0
    3235        # so we have sqrt ( abs ( r2 ^ 2) ) == r2
  • TabularUnified interfaces/python/test_phasevoc.py

    r8212692 rf650860  
    11from numpy.testing import TestCase, run_module_suite
    22from numpy.testing import assert_equal, assert_almost_equal
    3 from aubio import fvec, cvec, pvoc
     3from _aubio import *
    44from numpy import array, shape
    55
     
    2626  def test_steps_two_channels(self):
    2727    """ check the resynthesis of steps is correct """
    28     f = pvoc(1024, 512)
    29     t1 = fvec(512)
    30     t2 = fvec(512)
     28    f = pvoc(1024, 512, 2)
     29    t1 = fvec(512, 2)
     30    t2 = fvec(512, 2)
    3131    # positive step in first channel
    32     t1[100:200] = .1
     32    t1[0][100:200] = .1
    3333    # positive step in second channel
    34     t1[20:50] = -.1
     34    t1[1][20:50] = -.1
    3535    s1 = f(t1)
    3636    r1 = f.rdo(s1)
     
    4242  def test_steps_three_random_channels(self):
    4343    from random import random
    44     f = pvoc(64, 16)
    45     t0 = fvec(16)
    46     t1 = fvec(16)
    47     for i in xrange(16):
    48         t1[i] = random() * 2. - 1.
     44    f = pvoc(64, 16, 3)
     45    t0 = fvec(16, 3)
     46    t1 = fvec(16, 3)
     47    for i in xrange(3):
     48      for j in xrange(16):
     49        t1[i][j] = random() * 2. - 1.
    4950    t2 = f.rdo(f(t1))
    5051    t2 = f.rdo(f(t0))
  • TabularUnified src/aubio.h

    r8212692 rf650860  
    4949
    5050  Two basic structures are being used in aubio: ::fvec_t and ::cvec_t. The
    51   ::fvec_t structures are used to store vectors of floating pointer number.
    52   ::cvec_t are used to store complex number, as two vectors of norm and phase
    53   elements.
    54 
     51  ::fvec_t structures are used to store vectors of floating pointer number,
     52  optionally on several channels. ::cvec_t are used to store complex number,
     53  as two vectors of norm and phase elements, also on several channels.
     54 
    5555  Additionally, the ::lvec_t structure can be used to store floating point
    5656  numbers in double precision. They are mostly used to store filter
    5757  coefficients, to avoid instability.
    58 
     58 
    5959  \subsection objects Available objects
    6060
     
    6464
    6565  // fast Fourier transform (FFT)
    66   aubio_fft_t *fft = new_aubio_fft (winsize);
     66  aubio_fft_t *fft = new_aubio_fft (winsize, channels);
    6767  // phase vocoder
    68   aubio_pvoc_t *pv = new_aubio_pvoc (winsize, stepsize);
    69   // onset detection
    70   aubio_onset_t *onset = new_aubio_onset (method, winsize, stepsize, samplerate);
    71   // pitch detection
    72   aubio_pitch_t *pitch = new_aubio_pitch (method, winsize, stepsize, samplerate);
     68  aubio_pvoc_t *pv = new_aubio_pvoc (winsize, stepsize, channels);
     69  // onset detection 
     70  aubio_onset_t *onset = new_aubio_onset (method, winsize, stepsize, channels, samplerate);
     71  // pitch detection 
     72  aubio_pitch_t *pitch = new_aubio_pitch (method, winsize, stepsize, channels, samplerate);
    7373  // beat tracking
    74   aubio_tempo_t *tempo = new_aubio_tempo (method, winsize, stepsize, samplerate);
     74  aubio_tempo_t *tempo = new_aubio_tempo (method, winsize, stepsize, channels, samplerate);
    7575
    7676  \endcode
     
    8282  Here is a simple example that creates an A-Weighting filter and applies it to a
    8383  vector.
    84 
     84 
    8585  \code
    8686
    87   // set window size, and sampling rate
    88   uint_t winsize = 1024, sr = 44100;
     87  // set channels, window size, and sampling rate
     88  uint_t channels = 2, winsize = 1024, sr = 44100;
    8989  // create a vector
    90   fvec_t *this_buffer = new_fvec (winsize);
     90  fvec_t *this_buffer = new_fvec (winsize, channels);
    9191  // create the a-weighting filter
    92   aubio_filter_t *this_filter = new_aubio_filter_a_weighting (sr);
    93 
     92  aubio_filter_t *this_filter = new_aubio_filter_a_weighting (channels, sr);
     93 
    9494  while (running) {
    9595    // here some code to put some data in this_buffer
     
    9999    aubio_filter_do (this_filter, this_buffer);
    100100
    101     // here some code to get some data from this_buffer
     101    // here some code to get some data from this_buffer 
    102102    // ...
    103103  }
    104 
     104 
    105105  // and free the structures
    106106  del_aubio_filter (this_filter);
     
    129129
    130130  \section download Download
    131 
     131 
    132132  Latest versions, further documentation, examples, wiki, and mailing lists can
    133133  be found at http://aubio.org .
    134 
     134 
    135135 */
    136136
     
    141141
    142142  Programmers just need to include this file as:
    143 
     143 
    144144  @code
    145145    #include <aubio/aubio.h>
    146146  @endcode
    147 
     147 
    148148 */
    149149
     
    158158#include "cvec.h"
    159159#include "lvec.h"
    160 #include "fmat.h"
    161160#include "musicutils.h"
    162161#include "temporal/resampler.h"
  • TabularUnified src/cvec.c

    r8212692 rf650860  
    2222#include "cvec.h"
    2323
    24 cvec_t * new_cvec( uint_t length) {
     24cvec_t * new_cvec( uint_t length, uint_t channels) {
    2525  cvec_t * s = AUBIO_NEW(cvec_t);
    26   uint_t j;
     26  uint_t i,j;
     27  s->channels = channels;
    2728  s->length = length/2 + 1;
    28   s->norm = AUBIO_ARRAY(smpl_t,s->length);
    29   s->phas = AUBIO_ARRAY(smpl_t,s->length);
    30   for (j=0; j< s->length; j++) {
    31     s->norm[j]=0.;
    32     s->phas[j]=0.;
     29  s->norm = AUBIO_ARRAY(smpl_t*,s->channels);
     30  s->phas = AUBIO_ARRAY(smpl_t*,s->channels);
     31  for (i=0; i< s->channels; i++) {
     32    s->norm[i] = AUBIO_ARRAY(smpl_t,s->length);
     33    s->phas[i] = AUBIO_ARRAY(smpl_t,s->length);
     34    for (j=0; j< s->length; j++) {
     35      s->norm[i][j]=0.;
     36      s->phas[i][j]=0.;
     37    }
    3338  }
    3439  return s;
     
    3641
    3742void del_cvec(cvec_t *s) {
     43  uint_t i;
     44  for (i=0; i<s->channels; i++) {
     45    AUBIO_FREE(s->norm[i]);
     46    AUBIO_FREE(s->phas[i]);
     47  }
    3848  AUBIO_FREE(s->norm);
    3949  AUBIO_FREE(s->phas);
     
    4151}
    4252
    43 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position) {
    44   s->norm[position] = data;
     53void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position) {
     54  s->norm[channel][position] = data;
    4555}
    46 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position) {
    47   s->phas[position] = data;
     56void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position) {
     57  s->phas[channel][position] = data;
    4858}
    49 smpl_t cvec_read_norm(cvec_t *s, uint_t position) {
    50   return s->norm[position];
     59smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position) {
     60  return s->norm[channel][position];
    5161}
    52 smpl_t cvec_read_phas(cvec_t *s, uint_t position) {
    53   return s->phas[position];
     62smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position) {
     63  return s->phas[channel][position];
    5464}
    55 smpl_t * cvec_get_norm(cvec_t *s) {
     65void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel) {
     66  s->norm[channel] = data;
     67}
     68void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel) {
     69  s->phas[channel] = data;
     70}
     71smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel) {
     72  return s->norm[channel];
     73}
     74smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel) {
     75  return s->phas[channel];
     76}
     77smpl_t ** cvec_get_norm(cvec_t *s) {
    5678  return s->norm;
    5779}
    58 smpl_t * cvec_get_phas(cvec_t *s) {
     80smpl_t ** cvec_get_phas(cvec_t *s) {
    5981  return s->phas;
    6082}
     
    6385
    6486void cvec_print(cvec_t *s) {
    65   uint_t j;
    66   AUBIO_MSG("norm: ");
    67   for (j=0; j< s->length; j++) {
    68     AUBIO_MSG(AUBIO_SMPL_FMT " ", s->norm[j]);
     87  uint_t i,j;
     88  for (i=0; i< s->channels; i++) {
     89    AUBIO_MSG("norm: ");
     90    for (j=0; j< s->length; j++) {
     91      AUBIO_MSG(AUBIO_SMPL_FMT " ", s->norm[i][j]);
     92    }
     93    AUBIO_MSG("\n");
     94    AUBIO_MSG("phas: ");
     95    for (j=0; j< s->length; j++) {
     96      AUBIO_MSG(AUBIO_SMPL_FMT " ", s->phas[i][j]);
     97    }
     98    AUBIO_MSG("\n");
    6999  }
    70   AUBIO_MSG("\n");
    71   AUBIO_MSG("phas: ");
    72   for (j=0; j< s->length; j++) {
    73     AUBIO_MSG(AUBIO_SMPL_FMT " ", s->phas[j]);
    74   }
    75   AUBIO_MSG("\n");
    76100}
    77101
    78102void cvec_set(cvec_t *s, smpl_t val) {
    79   uint_t j;
    80   for (j=0; j< s->length; j++) {
    81     s->norm[j] = val;
     103  uint_t i,j;
     104  for (i=0; i< s->channels; i++) {
     105    for (j=0; j< s->length; j++) {
     106      s->norm[i][j] = val;
     107    }
    82108  }
    83109}
  • TabularUnified src/cvec.h

    r8212692 rf650860  
    3939typedef struct {
    4040  uint_t length;   /**< length of buffer = (requested length)/2 + 1 */
    41   smpl_t *norm;   /**< norm array of size [length] */
    42   smpl_t *phas;   /**< phase array of size [length] */
     41  uint_t channels; /**< number of channels */
     42  smpl_t **norm;   /**< norm array of size [length] * [channels] */
     43  smpl_t **phas;   /**< phase array of size [length] * [channels] */
    4344} cvec_t;
    4445
     
    4647
    4748  This function creates a cvec_t structure holding two arrays of size
    48   [length/2+1], corresponding to the norm and phase values of the
     49  [length/2+1] * channels, corresponding to the norm and phase values of the
    4950  spectral frame. The length stored in the structure is the actual size of both
    5051  arrays, not the length of the complex and symetrical vector, specified as
     
    5253
    5354  \param length the length of the buffer to create
    54 
    55 */
    56 cvec_t * new_cvec(uint_t length);
     55  \param channels the number of channels in the buffer
     56
     57*/
     58cvec_t * new_cvec(uint_t length, uint_t channels);
    5759/** cvec_t buffer deletion function
    5860
     
    6466
    6567  Note that this function is not used in the aubio library, since the same
    66   result can be obtained by assigning vec->norm[position]. Its purpose
     68  result can be obtained by assigning vec->norm[channel][position]. Its purpose
    6769  is to access these values from wrappers, as created by swig.
    6870
    6971  \param s vector to write to
    70   \param data norm value to write in s->norm[position]
     72  \param data norm value to write in s->norm[channel][position]
     73  \param channel channel to write to
    7174  \param position sample position to write to
    7275
    7376*/
    74 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position);
     77void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
    7578/** write phase value in a complex buffer
    7679
    7780  Note that this function is not used in the aubio library, since the same
    78   result can be obtained by assigning vec->phas[position]. Its purpose
     81  result can be obtained by assigning vec->phas[channel][position]. Its purpose
    7982  is to access these values from wrappers, as created by swig.
    8083
    8184  \param s vector to write to
    82   \param data phase value to write in s->phas[position]
     85  \param data phase value to write in s->phas[channel][position]
     86  \param channel channel to write to
    8387  \param position sample position to write to
    8488
    8589*/
    86 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position);
     90void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
    8791/** read norm value from a complex buffer
    8892
    8993  Note that this function is not used in the aubio library, since the same
    90   result can be obtained with vec->norm[position]. Its purpose is to
    91   access these values from wrappers, as created by swig.
    92 
    93   \param s vector to read from
     94  result can be obtained with vec->norm[channel][position]. Its purpose is to
     95  access these values from wrappers, as created by swig.
     96
     97  \param s vector to read from
     98  \param channel channel to read from
    9499  \param position sample position to read from
    95100
    96101*/
    97 smpl_t cvec_read_norm(cvec_t *s, uint_t position);
     102smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position);
    98103/** read phase value from a complex buffer
    99104
    100105  Note that this function is not used in the aubio library, since the same
    101   result can be obtained with vec->phas[position]. Its purpose is to
    102   access these values from wrappers, as created by swig.
    103 
    104   \param s vector to read from
     106  result can be obtained with vec->phas[channel][position]. Its purpose is to
     107  access these values from wrappers, as created by swig.
     108
     109  \param s vector to read from
     110  \param channel channel to read from
    105111  \param position sample position to read from
    106112
    107113*/
    108 smpl_t cvec_read_phas(cvec_t *s, uint_t position);
     114smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position);
     115/** write norm channel in a complex buffer
     116
     117  Note that this function is not used in the aubio library, since the same
     118  result can be obtained by assigning vec->norm[channel]. Its purpose is to
     119  access these values from wrappers, as created by swig.
     120
     121  \param s vector to write to
     122  \param data norm vector of [length] samples to write in s->norm[channel]
     123  \param channel channel to write to
     124
     125*/
     126void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel);
     127/** write phase channel in a complex buffer
     128
     129  Note that this function is not used in the aubio library, since the same
     130  result can be obtained by assigning vec->phas[channel]. Its purpose is to
     131  access these values from wrappers, as created by swig.
     132
     133  \param s vector to write to
     134  \param data phase vector of [length] samples to write in s->phas[channel]
     135  \param channel channel to write to
     136
     137*/
     138void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel);
     139/** read norm channel from a complex buffer
     140
     141  Note that this function is not used in the aubio library, since the same
     142  result can be obtained with vec->norm[channel]. Its purpose is to access
     143  these values from wrappers, as created by swig.
     144
     145  \param s vector to read from
     146  \param channel channel to read from
     147
     148*/
     149smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel);
     150/** write phase channel in a complex buffer
     151
     152  Note that this function is not used in the aubio library, since the same
     153  result can be obtained with vec->phas[channel]. Its purpose is to access
     154  these values from wrappers, as created by swig.
     155
     156  \param s vector to read from
     157  \param channel channel to read from
     158
     159*/
     160smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel);
    109161/** read norm data from a complex buffer
    110162
     
    116168
    117169*/
    118 smpl_t * cvec_get_norm(cvec_t *s);
     170smpl_t ** cvec_get_norm(cvec_t *s);
    119171/** read phase data from a complex buffer
    120172
     
    126178
    127179*/
    128 smpl_t * cvec_get_phas(cvec_t *s);
     180smpl_t ** cvec_get_phas(cvec_t *s);
    129181
    130182/** print out cvec data
  • TabularUnified src/fvec.c

    r8212692 rf650860  
    2222#include "fvec.h"
    2323
    24 fvec_t * new_fvec( uint_t length) {
     24fvec_t * new_fvec( uint_t length, uint_t channels) {
    2525  fvec_t * s = AUBIO_NEW(fvec_t);
    26   uint_t j;
     26  uint_t i,j;
     27  s->channels = channels;
    2728  s->length = length;
    28   s->data = AUBIO_ARRAY(smpl_t, s->length);
    29   for (j=0; j< s->length; j++) {
    30     s->data[j]=0.;
     29  s->data = AUBIO_ARRAY(smpl_t*,s->channels);
     30  for (i=0; i< s->channels; i++) {
     31    s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
     32    for (j=0; j< s->length; j++) {
     33      s->data[i][j]=0.;
     34    }
    3135  }
    3236  return s;
     
    3438
    3539void del_fvec(fvec_t *s) {
     40  uint_t i;
     41  for (i=0; i<s->channels; i++) {
     42    AUBIO_FREE(s->data[i]);
     43  }
    3644  AUBIO_FREE(s->data);
    3745  AUBIO_FREE(s);
    3846}
    3947
    40 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t position) {
    41   s->data[position] = data;
     48void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position) {
     49  s->data[channel][position] = data;
     50}
     51smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position) {
     52  return s->data[channel][position];
     53}
     54void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel) {
     55  s->data[channel] = data;
     56}
     57smpl_t * fvec_get_channel(fvec_t *s, uint_t channel) {
     58  return s->data[channel];
    4259}
    4360
    44 smpl_t fvec_read_sample(fvec_t *s, uint_t position) {
    45   return s->data[position];
    46 }
    47 
    48 smpl_t * fvec_get_data(fvec_t *s) {
     61smpl_t ** fvec_get_data(fvec_t *s) {
    4962  return s->data;
    5063}
     
    5366
    5467void fvec_print(fvec_t *s) {
    55   uint_t j;
    56   for (j=0; j< s->length; j++) {
    57     AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]);
     68  uint_t i,j;
     69  for (i=0; i< s->channels; i++) {
     70    for (j=0; j< s->length; j++) {
     71      AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[i][j]);
     72    }
     73    AUBIO_MSG("\n");
    5874  }
    59   AUBIO_MSG("\n");
    6075}
    6176
    6277void fvec_set(fvec_t *s, smpl_t val) {
    63   uint_t j;
    64   for (j=0; j< s->length; j++) {
    65     s->data[j] = val;
     78  uint_t i,j;
     79  for (i=0; i< s->channels; i++) {
     80    for (j=0; j< s->length; j++) {
     81      s->data[i][j] = val;
     82    }
    6683  }
    6784}
     
    7693
    7794void fvec_rev(fvec_t *s) {
    78   uint_t j;
    79   for (j=0; j< FLOOR(s->length/2); j++) {
    80     ELEM_SWAP(s->data[j], s->data[s->length-1-j]);
     95  uint_t i,j;
     96  for (i=0; i< s->channels; i++) {
     97    for (j=0; j< FLOOR(s->length/2); j++) {
     98      ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
     99    }
    81100  }
    82101}
    83102
    84103void fvec_weight(fvec_t *s, fvec_t *weight) {
    85   uint_t j;
     104  uint_t i,j;
    86105  uint_t length = MIN(s->length, weight->length);
    87   for (j=0; j< length; j++) {
    88     s->data[j] *= weight->data[j];
     106  for (i=0; i< s->channels; i++) {
     107    for (j=0; j< length; j++) {
     108      s->data[i][j] *= weight->data[0][j];
     109    }
    89110  }
    90111}
    91112
    92113void fvec_copy(fvec_t *s, fvec_t *t) {
    93   uint_t j;
     114  uint_t i,j;
     115  uint_t channels = MIN(s->channels, t->channels);
    94116  uint_t length = MIN(s->length, t->length);
     117  if (s->channels != t->channels) {
     118    AUBIO_ERR("warning, trying to copy %d channels to %d channels\n",
     119            s->channels, t->channels);
     120  }
    95121  if (s->length != t->length) {
    96     AUBIO_WRN("trying to copy %d elements to %d elements \n",
     122    AUBIO_ERR("warning, trying to copy %d elements to %d elements \n",
    97123            s->length, t->length);
    98124  }
    99   for (j=0; j< length; j++) {
    100     t->data[j] = s->data[j];
     125  for (i=0; i< channels; i++) {
     126    for (j=0; j< length; j++) {
     127      t->data[i][j] = s->data[i][j];
     128    }
    101129  }
    102130}
  • TabularUnified src/fvec.h

    r8212692 rf650860  
    3838typedef struct {
    3939  uint_t length;   /**< length of buffer */
    40   smpl_t *data;   /**< data array of size [length] */
     40  uint_t channels; /**< number of channels */
     41  smpl_t **data;   /**< data array of size [length] * [channels] */
    4142} fvec_t;
    4243
     
    4445
    4546  \param length the length of the buffer to create
     47  \param channels the number of channels in the buffer
    4648
    4749*/
    48 fvec_t * new_fvec(uint_t length);
     50fvec_t * new_fvec(uint_t length, uint_t channels);
    4951/** fvec_t buffer deletion function
    5052
     
    5658
    5759  Note that this function is not used in the aubio library, since the same
    58   result can be obtained using vec->data[position]. Its purpose is to
     60  result can be obtained using vec->data[channel][position]. Its purpose is to
    5961  access these values from wrappers, as created by swig.
    6062
    6163  \param s vector to read from
     64  \param channel channel to read from
    6265  \param position sample position to read from
    6366
    6467*/
    65 smpl_t fvec_read_sample(fvec_t *s, uint_t position);
     68smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position);
    6669/** write sample value in a buffer
    6770
    6871  Note that this function is not used in the aubio library, since the same
    69   result can be obtained by assigning vec->data[position]. Its purpose
     72  result can be obtained by assigning vec->data[channel][position]. Its purpose
    7073  is to access these values from wrappers, as created by swig.
    7174
    7275  \param s vector to write to
    73   \param data value to write in s->data[position]
     76  \param data value to write in s->data[channel][position]
     77  \param channel channel to write to
    7478  \param position sample position to write to
    7579
    7680*/
    77 void  fvec_write_sample(fvec_t *s, smpl_t data, uint_t position);
     81void  fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position);
     82/** read channel vector from a buffer
    7883
     84  Note that this function is not used in the aubio library, since the same
     85  result can be obtained with vec->data[channel]. Its purpose is to access
     86  these values from wrappers, as created by swig.
     87
     88  \param s vector to read from
     89  \param channel channel to read from
     90
     91*/
     92smpl_t * fvec_get_channel(fvec_t *s, uint_t channel);
     93/** write channel vector into a buffer
     94
     95  Note that this function is not used in the aubio library, since the same
     96  result can be obtained by assigning vec->data[channel]. Its purpose is to
     97  access these values from wrappers, as created by swig.
     98
     99  \param s vector to write to
     100  \param data vector of [length] values to write
     101  \param channel channel to write to
     102
     103*/
     104void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel);
    79105/** read data from a buffer
    80106
     
    86112
    87113*/
    88 smpl_t * fvec_get_data(fvec_t *s);
     114smpl_t ** fvec_get_data(fvec_t *s);
    89115
    90116/** print out fvec data
  • TabularUnified src/lvec.c

    r8212692 rf650860  
    2222#include "lvec.h"
    2323
    24 lvec_t * new_lvec( uint_t length) {
     24lvec_t * new_lvec( uint_t length, uint_t channels) {
    2525  lvec_t * s = AUBIO_NEW(lvec_t);
    26   uint_t j;
     26  uint_t i,j;
     27  s->channels = channels;
    2728  s->length = length;
    28   s->data = AUBIO_ARRAY(lsmp_t, s->length);
    29   for (j=0; j< s->length; j++) {
    30     s->data[j]=0.;
     29  s->data = AUBIO_ARRAY(lsmp_t*,s->channels);
     30  for (i=0; i< s->channels; i++) {
     31    s->data[i] = AUBIO_ARRAY(lsmp_t, s->length);
     32    for (j=0; j< s->length; j++) {
     33      s->data[i][j]=0.;
     34    }
    3135  }
    3236  return s;
     
    3438
    3539void del_lvec(lvec_t *s) {
     40  uint_t i;
     41  for (i=0; i<s->channels; i++) {
     42    AUBIO_FREE(s->data[i]);
     43  }
    3644  AUBIO_FREE(s->data);
    3745  AUBIO_FREE(s);
    3846}
    3947
    40 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position) {
    41   s->data[position] = data;
     48void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_t position) {
     49  s->data[channel][position] = data;
    4250}
    43 lsmp_t lvec_read_sample(lvec_t *s, uint_t position) {
    44   return s->data[position];
     51lsmp_t lvec_read_sample(lvec_t *s, uint_t channel, uint_t position) {
     52  return s->data[channel][position];
     53}
     54void lvec_put_channel(lvec_t *s, lsmp_t * data, uint_t channel) {
     55  s->data[channel] = data;
     56}
     57lsmp_t * lvec_get_channel(lvec_t *s, uint_t channel) {
     58  return s->data[channel];
    4559}
    4660
    47 lsmp_t * lvec_get_data(lvec_t *s) {
     61lsmp_t ** lvec_get_data(lvec_t *s) {
    4862  return s->data;
    4963}
     
    5266
    5367void lvec_print(lvec_t *s) {
    54   uint_t j;
    55   for (j=0; j< s->length; j++) {
    56     AUBIO_MSG(AUBIO_LSMP_FMT " ", s->data[j]);
     68  uint_t i,j;
     69  for (i=0; i< s->channels; i++) {
     70    for (j=0; j< s->length; j++) {
     71      AUBIO_MSG(AUBIO_LSMP_FMT " ", s->data[i][j]);
     72    }
     73    AUBIO_MSG("\n");
    5774  }
    58   AUBIO_MSG("\n");
    5975}
    6076
    6177void lvec_set(lvec_t *s, smpl_t val) {
    62   uint_t j;
    63   for (j=0; j< s->length; j++) {
    64     s->data[j] = val;
     78  uint_t i,j;
     79  for (i=0; i< s->channels; i++) {
     80    for (j=0; j< s->length; j++) {
     81      s->data[i][j] = val;
     82    }
    6583  }
    6684}
  • TabularUnified src/lvec.h

    r8212692 rf650860  
    3939typedef struct {
    4040  uint_t length;   /**< length of buffer */
    41   lsmp_t *data;   /**< data array of size [length] */
     41  uint_t channels; /**< number of channels */
     42  lsmp_t **data;   /**< data array of size [length] * [channels] */
    4243} lvec_t;
    4344
     
    4546
    4647  \param length the length of the buffer to create
     48  \param channels the number of channels in the buffer
    4749
    4850*/
    49 lvec_t * new_lvec(uint_t length);
     51lvec_t * new_lvec(uint_t length, uint_t channels);
    5052/** lvec_t buffer deletion function
    5153
     
    5759
    5860  Note that this function is not used in the aubio library, since the same
    59   result can be obtained using vec->data[position]. Its purpose is to
     61  result can be obtained using vec->data[channel][position]. Its purpose is to
    6062  access these values from wrappers, as created by swig.
    6163
    6264  \param s vector to read from
     65  \param channel channel to read from
    6366  \param position sample position to read from
    6467
    6568*/
    66 lsmp_t lvec_read_sample(lvec_t *s, uint_t position);
     69lsmp_t lvec_read_sample(lvec_t *s, uint_t channel, uint_t position);
    6770/** write sample value in a buffer
    6871
    6972  Note that this function is not used in the aubio library, since the same
    70   result can be obtained by assigning vec->data[position]. Its purpose
     73  result can be obtained by assigning vec->data[channel][position]. Its purpose
    7174  is to access these values from wrappers, as created by swig.
    7275
    7376  \param s vector to write to
    74   \param data value to write in s->data[position]
     77  \param data value to write in s->data[channel][position]
     78  \param channel channel to write to
    7579  \param position sample position to write to
    7680
    7781*/
    78 void  lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position);
     82void  lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_t position);
     83/** read channel vector from a buffer
    7984
     85  Note that this function is not used in the aubio library, since the same
     86  result can be obtained with vec->data[channel]. Its purpose is to access
     87  these values from wrappers, as created by swig.
     88
     89  \param s vector to read from
     90  \param channel channel to read from
     91
     92*/
     93lsmp_t * lvec_get_channel(lvec_t *s, uint_t channel);
     94/** write channel vector into a buffer
     95
     96  Note that this function is not used in the aubio library, since the same
     97  result can be obtained by assigning vec->data[channel]. Its purpose is to
     98  access these values from wrappers, as created by swig.
     99
     100  \param s vector to write to
     101  \param data vector of [length] values to write
     102  \param channel channel to write to
     103
     104*/
     105void lvec_put_channel(lvec_t *s, lsmp_t * data, uint_t channel);
    80106/** read data from a buffer
    81107
     
    87113
    88114*/
    89 lsmp_t * lvec_get_data(lvec_t *s);
     115lsmp_t ** lvec_get_data(lvec_t *s);
    90116
    91117/** print out lvec data
  • TabularUnified src/mathutils.c

    r8212692 rf650860  
    4646new_aubio_window (char_t * window_type, uint_t size)
    4747{
    48   fvec_t * win = new_fvec (size);
    49   smpl_t * w = win->data;
     48  // create fvec of size x 1 channel
     49  fvec_t * win = new_fvec( size, 1);
     50  smpl_t * w = win->data[0];
    5051  uint_t i;
    5152  aubio_window_type wintype;
     
    133134fvec_mean (fvec_t * s)
    134135{
     136  uint_t i, j;
     137  smpl_t tmp = 0.0;
     138  for (i = 0; i < s->channels; i++)
     139    for (j = 0; j < s->length; j++)
     140      tmp += s->data[i][j];
     141  return tmp / (smpl_t) (s->length);
     142}
     143
     144smpl_t
     145fvec_mean_channel (fvec_t * s, uint_t i)
     146{
    135147  uint_t j;
    136148  smpl_t tmp = 0.0;
    137   for (j = 0; j < s->length; j++) {
    138     tmp += s->data[j];
    139   }
     149  for (j = 0; j < s->length; j++)
     150      tmp += s->data[i][j];
    140151  return tmp / (smpl_t) (s->length);
    141152}
     
    144155fvec_sum (fvec_t * s)
    145156{
    146   uint_t j;
     157  uint_t i, j;
    147158  smpl_t tmp = 0.0;
    148   for (j = 0; j < s->length; j++) {
    149     tmp += s->data[j];
     159  for (i = 0; i < s->channels; i++) {
     160    for (j = 0; j < s->length; j++) {
     161      tmp += s->data[i][j];
     162    }
    150163  }
    151164  return tmp;
     
    155168fvec_max (fvec_t * s)
    156169{
    157   uint_t j;
     170  uint_t i, j;
    158171  smpl_t tmp = 0.0;
    159   for (j = 0; j < s->length; j++) {
    160     tmp = (tmp > s->data[j]) ? tmp : s->data[j];
     172  for (i = 0; i < s->channels; i++) {
     173    for (j = 0; j < s->length; j++) {
     174      tmp = (tmp > s->data[i][j]) ? tmp : s->data[i][j];
     175    }
    161176  }
    162177  return tmp;
     
    166181fvec_min (fvec_t * s)
    167182{
    168   uint_t j;
    169   smpl_t tmp = s->data[0];
    170   for (j = 0; j < s->length; j++) {
    171     tmp = (tmp < s->data[j]) ? tmp : s->data[j];
     183  uint_t i, j;
     184  smpl_t tmp = s->data[0][0];
     185  for (i = 0; i < s->channels; i++) {
     186    for (j = 0; j < s->length; j++) {
     187      tmp = (tmp < s->data[i][j]) ? tmp : s->data[i][j];
     188    }
    172189  }
    173190  return tmp;
     
    177194fvec_min_elem (fvec_t * s)
    178195{
    179   uint_t j, pos = 0.;
    180   smpl_t tmp = s->data[0];
    181   for (j = 0; j < s->length; j++) {
    182     pos = (tmp < s->data[j]) ? pos : j;
    183     tmp = (tmp < s->data[j]) ? tmp : s->data[j];
     196  uint_t i, j, pos = 0.;
     197  smpl_t tmp = s->data[0][0];
     198  for (i = 0; i < s->channels; i++) {
     199    for (j = 0; j < s->length; j++) {
     200      pos = (tmp < s->data[i][j]) ? pos : j;
     201      tmp = (tmp < s->data[i][j]) ? tmp : s->data[i][j];
     202    }
    184203  }
    185204  return pos;
     
    189208fvec_max_elem (fvec_t * s)
    190209{
    191   uint_t j, pos = 0;
     210  uint_t i, j, pos = 0;
    192211  smpl_t tmp = 0.0;
    193   for (j = 0; j < s->length; j++) {
    194     pos = (tmp > s->data[j]) ? pos : j;
    195     tmp = (tmp > s->data[j]) ? tmp : s->data[j];
     212  for (i = 0; i < s->channels; i++) {
     213    for (j = 0; j < s->length; j++) {
     214      pos = (tmp > s->data[i][j]) ? pos : j;
     215      tmp = (tmp > s->data[i][j]) ? tmp : s->data[i][j];
     216    }
    196217  }
    197218  return pos;
     
    201222fvec_shift (fvec_t * s)
    202223{
    203   uint_t j;
    204   for (j = 0; j < s->length / 2; j++) {
    205     ELEM_SWAP (s->data[j], s->data[j + s->length / 2]);
     224  uint_t i, j;
     225  for (i = 0; i < s->channels; i++) {
     226    for (j = 0; j < s->length / 2; j++) {
     227      ELEM_SWAP (s->data[i][j], s->data[i][j + s->length / 2]);
     228    }
    206229  }
    207230}
     
    211234{
    212235  smpl_t energy = 0.;
    213   uint_t j;
    214   for (j = 0; j < f->length; j++) {
    215     energy += SQR (f->data[j]);
     236  uint_t i, j;
     237  for (i = 0; i < f->channels; i++) {
     238    for (j = 0; j < f->length; j++) {
     239      energy += SQR (f->data[i][j]);
     240    }
    216241  }
    217242  return energy;
     
    222247{
    223248  smpl_t hfc = 0.;
    224   uint_t j;
    225   for (j = 0; j < v->length; j++) {
    226     hfc += (j + 1) * v->data[j];
     249  uint_t i, j;
     250  for (i = 0; i < v->channels; i++) {
     251    for (j = 0; j < v->length; j++) {
     252      hfc += (i + 1) * v->data[i][j];
     253    }
    227254  }
    228255  return hfc;
     
    239266fvec_alpha_norm (fvec_t * o, smpl_t alpha)
    240267{
    241   uint_t j;
     268  uint_t i, j;
    242269  smpl_t tmp = 0.;
    243   for (j = 0; j < o->length; j++) {
    244     tmp += POW (ABS (o->data[j]), alpha);
     270  for (i = 0; i < o->channels; i++) {
     271    for (j = 0; j < o->length; j++) {
     272      tmp += POW (ABS (o->data[i][j]), alpha);
     273    }
    245274  }
    246275  return POW (tmp / o->length, 1. / alpha);
     
    250279fvec_alpha_normalise (fvec_t * o, smpl_t alpha)
    251280{
    252   uint_t j;
     281  uint_t i, j;
    253282  smpl_t norm = fvec_alpha_norm (o, alpha);
    254   for (j = 0; j < o->length; j++) {
    255     o->data[j] /= norm;
     283  for (i = 0; i < o->channels; i++) {
     284    for (j = 0; j < o->length; j++) {
     285      o->data[i][j] /= norm;
     286    }
    256287  }
    257288}
     
    260291fvec_add (fvec_t * o, smpl_t val)
    261292{
    262   uint_t j;
    263   for (j = 0; j < o->length; j++) {
    264     o->data[j] += val;
     293  uint_t i, j;
     294  for (i = 0; i < o->channels; i++) {
     295    for (j = 0; j < o->length; j++) {
     296      o->data[i][j] += val;
     297    }
    265298  }
    266299}
    267300
    268301void fvec_adapt_thres(fvec_t * vec, fvec_t * tmp,
    269     uint_t post, uint_t pre) {
    270   uint_t length = vec->length, j;
     302    uint_t post, uint_t pre, uint_t channel) {
     303  uint_t length = vec->length, i=channel, j;
    271304  for (j=0;j<length;j++) {
    272     vec->data[j] -= fvec_moving_thres(vec, tmp, post, pre, j);
     305    vec->data[i][j] -= fvec_moving_thres(vec, tmp, post, pre, j, i);
    273306  }
    274307}
     
    276309smpl_t
    277310fvec_moving_thres (fvec_t * vec, fvec_t * tmpvec,
    278     uint_t post, uint_t pre, uint_t pos)
    279 {
    280   uint_t k;
    281   smpl_t *medar = (smpl_t *) tmpvec->data;
     311    uint_t post, uint_t pre, uint_t pos, uint_t channel)
     312{
     313  uint_t i = channel, k;
     314  smpl_t *medar = (smpl_t *) tmpvec->data[i];
    282315  uint_t win_length = post + pre + 1;
    283316  uint_t length = vec->length;
     
    287320      medar[k] = 0.;            /* 0-padding at the beginning */
    288321    for (k = post + 1 - pos; k < win_length; k++)
    289       medar[k] = vec->data[k + pos - post];
     322      medar[k] = vec->data[0][k + pos - post];
    290323    /* the buffer is fully defined */
    291324  } else if (pos + pre < length) {
    292325    for (k = 0; k < win_length; k++)
    293       medar[k] = vec->data[k + pos - post];
     326      medar[k] = vec->data[0][k + pos - post];
    294327    /* pre part of the buffer does not exist */
    295328  } else {
    296329    for (k = 0; k < length - pos + post; k++)
    297       medar[k] = vec->data[k + pos - post];
     330      medar[k] = vec->data[0][k + pos - post];
    298331    for (k = length - pos + post; k < win_length; k++)
    299332      medar[k] = 0.;            /* 0-padding at the end */
    300333  }
    301   return fvec_median (tmpvec);
    302 }
    303 
    304 smpl_t fvec_median (fvec_t * input) {
     334  return fvec_median_channel (tmpvec, i);
     335}
     336
     337smpl_t fvec_median_channel (fvec_t * input, uint_t channel) {
    305338  uint_t n = input->length;
    306   smpl_t * arr = (smpl_t *) input->data;
     339  smpl_t * arr = (smpl_t *) input->data[channel];
    307340  uint_t low, high ;
    308341  uint_t median;
     
    353386}
    354387
    355 smpl_t fvec_quadint (fvec_t * x, uint_t pos) {
     388smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t i) {
    356389  smpl_t s0, s1, s2;
    357390  uint_t x0 = (pos < 1) ? pos : pos - 1;
    358391  uint_t x2 = (pos + 1 < x->length) ? pos + 1 : pos;
    359   if (x0 == pos) return (x->data[pos] <= x->data[x2]) ? pos : x2;
    360   if (x2 == pos) return (x->data[pos] <= x->data[x0]) ? pos : x0;
    361   s0 = x->data[x0];
    362   s1 = x->data[pos];
    363   s2 = x->data[x2];
     392  if (x0 == pos) return (x->data[i][pos] <= x->data[i][x2]) ? pos : x2;
     393  if (x2 == pos) return (x->data[i][pos] <= x->data[i][x0]) ? pos : x0;
     394  s0 = x->data[i][x0];
     395  s1 = x->data[i][pos];
     396  s2 = x->data[i][x2];
    364397  return pos + 0.5 * (s2 - s0 ) / (s2 - 2.* s1 + s0);
    365398}
    366399
    367400uint_t fvec_peakpick(fvec_t * onset, uint_t pos) {
    368   uint_t tmp=0;
    369   tmp = (onset->data[pos] > onset->data[pos-1]
    370       &&  onset->data[pos] > onset->data[pos+1]
    371       &&  onset->data[pos] > 0.);
     401  uint_t i=0, tmp=0;
     402  /*for (i=0;i<onset->channels;i++)*/
     403  tmp = (onset->data[i][pos] > onset->data[i][pos-1]
     404      &&  onset->data[i][pos] > onset->data[i][pos+1]
     405      &&  onset->data[i][pos] > 0.);
    372406  return tmp;
    373407}
     
    478512aubio_zero_crossing_rate (fvec_t * input)
    479513{
    480   uint_t j;
     514  uint_t i = 0, j;
    481515  uint_t zcr = 0;
    482516  for (j = 1; j < input->length; j++) {
    483517    // previous was strictly negative
    484     if (input->data[j - 1] < 0.) {
     518    if (input->data[i][j - 1] < 0.) {
    485519      // current is positive or null
    486       if (input->data[j] >= 0.) {
     520      if (input->data[i][j] >= 0.) {
    487521        zcr += 1;
    488522      }
     
    490524    } else {
    491525      // current is strictly negative
    492       if (input->data[j] < 0.) {
     526      if (input->data[i][j] < 0.) {
    493527        zcr += 1;
    494528      }
     
    501535aubio_autocorr (fvec_t * input, fvec_t * output)
    502536{
    503   uint_t i, j, length = input->length;
     537  uint_t i, j, k, length = input->length;
    504538  smpl_t *data, *acf;
    505539  smpl_t tmp = 0;
    506   data = input->data;
    507   acf = output->data;
    508   for (i = 0; i < length; i++) {
    509     tmp = 0.;
    510     for (j = i; j < length; j++) {
    511       tmp += data[j - i] * data[j];
    512     }
    513     acf[i] = tmp / (smpl_t) (length - i);
     540  for (k = 0; k < input->channels; k++) {
     541    data = input->data[k];
     542    acf = output->data[k];
     543    for (i = 0; i < length; i++) {
     544      tmp = 0.;
     545      for (j = i; j < length; j++) {
     546        tmp += data[j - i] * data[j];
     547      }
     548      acf[i] = tmp / (smpl_t) (length - i);
     549    }
    514550  }
    515551}
  • TabularUnified src/mathutils.h

    r8212692 rf650860  
    4141*/
    4242smpl_t fvec_mean (fvec_t * s);
     43
     44/** compute the mean of a vector channel
     45
     46  \param s vector to compute mean from
     47  \param i channel to compute mean from
     48
     49  \return the mean of v
     50
     51*/
     52smpl_t fvec_mean_channel (fvec_t * s, uint_t i);
    4353
    4454/** find the max of a vector
     
    195205*/
    196206smpl_t fvec_moving_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre,
    197     uint_t pos);
     207    uint_t pos, uint_t channel);
    198208
    199209/** apply adaptive threshold to a vector
     
    208218
    209219*/
    210 void fvec_adapt_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre);
     220void fvec_adapt_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre,
     221    uint_t channel);
    211222
    212223/** returns the median of a vector
     
    221232
    222233  \param v vector to get median from
     234  \param channel channel to get median from
    223235
    224236  \return the median of v
    225237 
    226238*/
    227 smpl_t fvec_median (fvec_t * v);
     239smpl_t fvec_median_channel (fvec_t * v, uint_t channel);
    228240
    229241/** finds exact peak index by quadratic interpolation*/
    230 smpl_t fvec_quadint (fvec_t * x, uint_t pos);
     242smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t channel);
    231243
    232244/** Quadratic interpolation using Lagrange polynomial.
  • TabularUnified src/onset/onset.c

    r8212692 rf650860  
    4848  smpl_t isonset = 0;
    4949  smpl_t wasonset = 0;
     50  uint_t i;
    5051  aubio_pvoc_do (o->pv,input, o->fftgrain);
    5152  aubio_specdesc_do (o->od,o->fftgrain, o->of);
     53  /*if (usedoubled) {
     54    aubio_specdesc_do (o2,fftgrain, onset2);
     55    onset->data[0][0] *= onset2->data[0][0];
     56  }*/
    5257  aubio_peakpicker_do(o->pp, o->of, onset);
    53   isonset = onset->data[0];
    54   wasonset = o->wasonset->data[0];
     58  for (i = 0; i < input->channels; i++) {
     59  isonset = onset->data[i][0];
     60  wasonset = o->wasonset->data[i][0];
    5561  if (isonset > 0.) {
    5662    if (aubio_silence_detection(input, o->silence)==1) {
     
    6874    wasonset++;
    6975  }
    70   o->wasonset->data[0] = wasonset;
    71   onset->data[0] = isonset;
     76  o->wasonset->data[i][0] = wasonset;
     77  onset->data[i][0] = isonset;
     78  }
    7279  return;
    7380}
     
    9198/* Allocate memory for an onset detection */
    9299aubio_onset_t * new_aubio_onset (char_t * onset_mode,
    93     uint_t buf_size, uint_t hop_size, uint_t samplerate)
     100    uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate)
    94101{
    95102  aubio_onset_t * o = AUBIO_NEW(aubio_onset_t);
     
    98105  o->minioi    = 4;
    99106  o->silence   = -70;
    100   o->wasonset  = new_fvec(1);
     107  o->wasonset  = new_fvec(1, channels);
    101108  o->samplerate = samplerate;
    102109  o->hop_size = hop_size;
    103   o->pv = new_aubio_pvoc(buf_size, hop_size);
    104   o->pp = new_aubio_peakpicker();
     110  o->pv = new_aubio_pvoc(buf_size, hop_size, channels);
     111  o->pp = new_aubio_peakpicker(channels);
    105112  aubio_peakpicker_set_threshold (o->pp, o->threshold);
    106   o->od = new_aubio_specdesc(onset_mode,buf_size);
    107   o->fftgrain = new_cvec(buf_size);
    108   o->of = new_fvec(1);
     113  o->od = new_aubio_specdesc(onset_mode,buf_size,channels);
     114  o->fftgrain = new_cvec(buf_size,channels);
     115  o->of = new_fvec(1, channels);
    109116  /*if (usedoubled)    {
    110     o2 = new_aubio_specdesc(onset_type2,buffer_size);
    111     onset2 = new_fvec(1);
     117    o2 = new_aubio_specdesc(onset_type2,buffer_size,channels);
     118    onset2 = new_fvec(1 , channels);
    112119  }*/
    113120  return o;
  • TabularUnified src/onset/onset.h

    r8212692 rf650860  
    5050  \param buf_size buffer size for phase vocoder
    5151  \param hop_size hop size for phase vocoder
     52  \param channels number of channels
    5253  \param samplerate sampling rate of the input signal
    5354
    5455*/
    5556aubio_onset_t * new_aubio_onset (char_t * method,
    56     uint_t buf_size, uint_t hop_size, uint_t samplerate);
     57    uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate);
    5758
    5859/** execute onset detection
  • TabularUnified src/onset/peakpicker.c

    r8212692 rf650860  
    2828
    2929/** function pointer to thresholding function */
    30 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input);
     30typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input, uint_t channel);
    3131/** function pointer to peak-picking function */
    3232typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos);
     
    6969  fvec_t *scratch;
    7070
     71  /** number of channels to analyse */
     72  uint_t channels;
     73
    7174        /** \bug should be used to calculate filter coefficients */
    7275  /* cutoff: low-pass filter cutoff [0.34, 1] */
     
    9497  smpl_t mean = 0., median = 0.;
    9598  uint_t length = p->win_post + p->win_pre + 1;
    96   uint_t j = 0;
    97 
    98   /* store onset in onset_keep */
    99   /* shift all elements but last, then write last */
    100   for (j = 0; j < length - 1; j++) {
    101     onset_keep->data[j] = onset_keep->data[j + 1];
    102     onset_proc->data[j] = onset_keep->data[j];
     99  uint_t i, j = 0;
     100
     101  for (i = 0; i < p->channels; i++) {
     102    /* store onset in onset_keep */
     103    /* shift all elements but last, then write last */
     104    for (j = 0; j < length - 1; j++) {
     105      onset_keep->data[i][j] = onset_keep->data[i][j + 1];
     106      onset_proc->data[i][j] = onset_keep->data[i][j];
     107    }
     108    onset_keep->data[i][length - 1] = onset->data[i][0];
     109    onset_proc->data[i][length - 1] = onset->data[i][0];
    103110  }
    104   onset_keep->data[length - 1] = onset->data[0];
    105   onset_proc->data[length - 1] = onset->data[0];
    106111
    107112  /* filter onset_proc */
     
    109114  aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch);
    110115
    111   /* calculate mean and median for onset_proc */
    112   mean = fvec_mean (onset_proc);
    113   /* copy to scratch */
    114   for (j = 0; j < length; j++)
    115     scratch->data[j] = onset_proc->data[j];
    116   median = p->thresholdfn (scratch);
    117 
    118   /* shift peek array */
    119   for (j = 0; j < 3 - 1; j++)
    120     onset_peek->data[j] = onset_peek->data[j + 1];
    121   /* calculate new tresholded value */
    122   thresholded->data[0] =
    123       onset_proc->data[p->win_post] - median - mean * p->threshold;
    124   onset_peek->data[2] = thresholded->data[0];
    125   out->data[0] = (p->pickerfn) (onset_peek, 1);
    126   if (out->data[0]) {
    127     out->data[0] = fvec_quadint (onset_peek, 1);
     116  for (i = 0; i < p->channels; i++) {
     117    /* calculate mean and median for onset_proc */
     118    mean = fvec_mean_channel (onset_proc, i);
     119    /* copy to scratch */
     120    for (j = 0; j < length; j++)
     121      scratch->data[i][j] = onset_proc->data[i][j];
     122    median = p->thresholdfn (scratch, i);
     123
     124    /* shift peek array */
     125    for (j = 0; j < 3 - 1; j++)
     126      onset_peek->data[i][j] = onset_peek->data[i][j + 1];
     127    /* calculate new tresholded value */
     128    thresholded->data[i][0] =
     129        onset_proc->data[i][p->win_post] - median - mean * p->threshold;
     130    onset_peek->data[i][2] = thresholded->data[i][0];
     131    out->data[i][0] = (p->pickerfn) (onset_peek, 1);
     132    if (out->data[i][0]) {
     133      out->data[i][0] = fvec_quadint (onset_peek, 1, i);
     134    }
    128135  }
    129136}
     
    166173
    167174aubio_peakpicker_t *
    168 new_aubio_peakpicker ()
     175new_aubio_peakpicker (uint_t channels)
    169176{
    170177  aubio_peakpicker_t *t = AUBIO_NEW (aubio_peakpicker_t);
     
    172179  t->win_post = 5;
    173180  t->win_pre = 1;
    174 
    175   t->thresholdfn = (aubio_thresholdfn_t) (fvec_median); /* (fvec_mean); */
     181  //channels = 1;
     182  t->channels = channels;
     183
     184  t->thresholdfn = (aubio_thresholdfn_t) (fvec_median_channel); /* (fvec_mean); */
    176185  t->pickerfn = (aubio_pickerfn_t) (fvec_peakpick);
    177186
    178   t->scratch = new_fvec (t->win_post + t->win_pre + 1);
    179   t->onset_keep = new_fvec (t->win_post + t->win_pre + 1);
    180   t->onset_proc = new_fvec (t->win_post + t->win_pre + 1);
    181   t->onset_peek = new_fvec (3);
    182   t->thresholded = new_fvec (1);
     187  t->scratch = new_fvec (t->win_post + t->win_pre + 1, channels);
     188  t->onset_keep = new_fvec (t->win_post + t->win_pre + 1, channels);
     189  t->onset_proc = new_fvec (t->win_post + t->win_pre + 1, channels);
     190  t->onset_peek = new_fvec (3, channels);
     191  t->thresholded = new_fvec (1, channels);
    183192
    184193  /* cutoff: low-pass filter with cutoff reduced frequency at 0.34
     
    186195   */
    187196  t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789,
    188       -0.59488894, 0.23484048);
     197      -0.59488894, 0.23484048, channels);
    189198
    190199  return t;
  • TabularUnified src/onset/peakpicker.h

    r8212692 rf650860  
    3636
    3737/** peak-picker creation function */
    38 aubio_peakpicker_t * new_aubio_peakpicker(void);
     38aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels);
    3939/** real time peak picking function */
    4040void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out);
  • TabularUnified src/pitch/pitch.c

    r8212692 rf650860  
    114114aubio_pitch_t *
    115115new_aubio_pitch (char_t * pitch_mode,
    116     uint_t bufsize, uint_t hopsize, uint_t samplerate)
     116    uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate)
    117117{
    118118  aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t);
     
    142142  switch (p->type) {
    143143    case aubio_pitcht_yin:
    144       p->buf = new_fvec (bufsize);
     144      p->buf = new_fvec (bufsize, channels);
    145145      p->yin = new_aubio_pitchyin (bufsize);
    146146      p->callback = aubio_pitch_do_yin;
     
    148148      break;
    149149    case aubio_pitcht_mcomb:
    150       p->pv = new_aubio_pvoc (bufsize, hopsize);
    151       p->fftgrain = new_cvec (bufsize);
    152       p->mcomb = new_aubio_pitchmcomb (bufsize, hopsize);
    153       p->filter = new_aubio_filter_c_weighting (samplerate);
     150      p->pv = new_aubio_pvoc (bufsize, hopsize, channels);
     151      p->fftgrain = new_cvec (bufsize, channels);
     152      p->mcomb = new_aubio_pitchmcomb (bufsize, hopsize, channels);
     153      p->filter = new_aubio_filter_c_weighting (samplerate, channels);
    154154      p->callback = aubio_pitch_do_mcomb;
    155155      break;
    156156    case aubio_pitcht_fcomb:
    157       p->buf = new_fvec (bufsize);
    158       p->fcomb = new_aubio_pitchfcomb (bufsize, hopsize);
     157      p->buf = new_fvec (bufsize, channels);
     158      p->fcomb = new_aubio_pitchfcomb (bufsize, hopsize, channels);
    159159      p->callback = aubio_pitch_do_fcomb;
    160160      break;
    161161    case aubio_pitcht_schmitt:
    162       p->buf = new_fvec (bufsize);
     162      p->buf = new_fvec (bufsize, channels);
    163163      p->schmitt = new_aubio_pitchschmitt (bufsize);
    164164      p->callback = aubio_pitch_do_schmitt;
    165165      break;
    166166    case aubio_pitcht_yinfft:
    167       p->buf = new_fvec (bufsize);
     167      p->buf = new_fvec (bufsize, channels);
    168168      p->yinfft = new_aubio_pitchyinfft (bufsize);
    169169      p->callback = aubio_pitch_do_yinfft;
     
    211211aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf)
    212212{
    213   uint_t j = 0, overlap_size = 0;
     213  uint_t i, j = 0, overlap_size = 0;
    214214  overlap_size = p->buf->length - ibuf->length;
    215   for (j = 0; j < overlap_size; j++) {
    216     p->buf->data[j] = p->buf->data[j + ibuf->length];
    217   }
    218   for (j = 0; j < ibuf->length; j++) {
    219     p->buf->data[j + overlap_size] = ibuf->data[j];
     215  for (i = 0; i < p->buf->channels; i++) {
     216    for (j = 0; j < overlap_size; j++) {
     217      p->buf->data[i][j] = p->buf->data[i][j + ibuf->length];
     218    }
     219  }
     220  for (i = 0; i < ibuf->channels; i++) {
     221    for (j = 0; j < ibuf->length; j++) {
     222      p->buf->data[i][j + overlap_size] = ibuf->data[i][j];
     223    }
    220224  }
    221225}
     
    279283aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
    280284{
     285  uint_t i;
    281286  p->callback (p, ibuf, obuf);
    282   obuf->data[0] = p->freqconv (obuf->data[0], p->srate, p->bufsize);
     287  for (i = 0; i < obuf->channels; i++) {
     288    p->freqconv (obuf->data[i][0], p->srate, p->bufsize);
     289  }
    283290}
    284291
     
    286293aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
    287294{
     295  uint_t i;
    288296  aubio_filter_do (p->filter, ibuf);
    289297  aubio_pvoc_do (p->pv, ibuf, p->fftgrain);
    290298  aubio_pitchmcomb_do (p->mcomb, p->fftgrain, obuf);
    291   obuf->data[0] = aubio_bintofreq (obuf->data[0], p->srate, p->bufsize);
     299  for (i = 0; i < obuf->channels; i++) {
     300    obuf->data[i][0] = aubio_bintofreq (obuf->data[i][0], p->srate, p->bufsize);
     301  }
    292302}
    293303
     
    296306{
    297307  smpl_t pitch = 0.;
     308  uint_t i;
    298309  aubio_pitch_slideblock (p, ibuf);
    299310  aubio_pitchyin_do (p->yin, p->buf, obuf);
    300   pitch = obuf->data[0];
    301   if (pitch > 0) {
    302     pitch = p->srate / (pitch + 0.);
    303   } else {
    304     pitch = 0.;
    305   }
    306   obuf->data[0] = pitch;
     311  for (i = 0; i < obuf->channels; i++) {
     312    pitch = obuf->data[i][0];
     313    if (pitch > 0) {
     314      pitch = p->srate / (pitch + 0.);
     315    } else {
     316      pitch = 0.;
     317    }
     318    obuf->data[i][0] = pitch;
     319  }
    307320}
    308321
     
    312325{
    313326  smpl_t pitch = 0.;
     327  uint_t i;
    314328  aubio_pitch_slideblock (p, ibuf);
    315329  aubio_pitchyinfft_do (p->yinfft, p->buf, obuf);
    316   pitch = obuf->data[0];
    317   if (pitch > 0) {
    318     pitch = p->srate / (pitch + 0.);
    319   } else {
    320     pitch = 0.;
    321   }
    322   obuf->data[0] = pitch;
     330  for (i = 0; i < obuf->channels; i++) {
     331    pitch = obuf->data[i][0];
     332    if (pitch > 0) {
     333      pitch = p->srate / (pitch + 0.);
     334    } else {
     335      pitch = 0.;
     336    }
     337    obuf->data[i][0] = pitch;
     338  }
    323339}
    324340
     
    326342aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
    327343{
     344  uint_t i;
    328345  aubio_pitch_slideblock (p, ibuf);
    329346  aubio_pitchfcomb_do (p->fcomb, p->buf, out);
    330   out->data[0] = aubio_bintofreq (out->data[0], p->srate, p->bufsize);
     347  for (i = 0; i < out->channels; i++) {
     348    out->data[i][0] = aubio_bintofreq (out->data[i][0], p->srate, p->bufsize);
     349  }
    331350}
    332351
     
    335354{
    336355  smpl_t period, pitch = 0.;
     356  uint_t i;
    337357  aubio_pitch_slideblock (p, ibuf);
    338358  aubio_pitchschmitt_do (p->schmitt, p->buf, out);
    339   period = out->data[0];
    340   if (period > 0) {
    341     pitch = p->srate / period;
    342   } else {
    343     pitch = 0.;
    344   }
    345   out->data[0] = pitch;
    346 }
     359  for (i = 0; i < out->channels; i++) {
     360    period = out->data[i][0];
     361    if (period > 0) {
     362      pitch = p->srate / period;
     363    } else {
     364      pitch = 0.;
     365    }
     366    out->data[i][0] = pitch;
     367  }
     368}
  • TabularUnified src/pitch/pitch.h

    r8212692 rf650860  
    4141
    4242  \param o pitch detection object as returned by new_aubio_pitch()
    43   \param in input signal of size [hop_size]
    44   \param out output pitch candidates of size [1]
     43  \param in input signal of size [hop_size x channels]
     44  \param out output pitch candidates of size [1 x channels]
    4545
    4646*/
     
    6767  \param buf_size size of the input buffer to analyse
    6868  \param hop_size step size between two consecutive analysis instant
     69  \param channels number of channels to analyse
    6970  \param samplerate sampling rate of the signal
    7071
    7172*/
    7273aubio_pitch_t *new_aubio_pitch (char_t * method,
    73     uint_t buf_size, uint_t hop_size, uint_t samplerate);
     74    uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate);
    7475
    7576/** set the output unit of the pitch detection object
  • TabularUnified src/pitch/pitchfcomb.c

    r8212692 rf650860  
    4949
    5050aubio_pitchfcomb_t *
    51 new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize)
     51new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t channels)
    5252{
    5353  aubio_pitchfcomb_t *p = AUBIO_NEW (aubio_pitchfcomb_t);
    5454  p->fftSize = bufsize;
    5555  p->stepSize = hopsize;
    56   p->winput = new_fvec (bufsize);
    57   p->fftOut = new_cvec (bufsize);
    58   p->fftLastPhase = new_fvec (bufsize);
    59   p->fft = new_aubio_fft (bufsize);
     56  p->winput = new_fvec (bufsize, 1);
     57  p->fftOut = new_cvec (bufsize, 1);
     58  p->fftLastPhase = new_fvec (bufsize, channels);
     59  p->fft = new_aubio_fft (bufsize, 1);
    6060  p->win = new_aubio_window ("hanning", bufsize);
    6161  return p;
     
    6666aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output)
    6767{
    68   uint_t k, l, maxharm = 0;
     68  uint_t i, k, l, maxharm = 0;
    6969  smpl_t phaseDifference = TWO_PI * (smpl_t) p->stepSize / (smpl_t) p->fftSize;
    7070  aubio_fpeak_t peaks[MAX_PEAKS];
    7171
    72   for (k = 0; k < MAX_PEAKS; k++) {
    73     peaks[k].db = -200.;
    74     peaks[k].bin = 0.;
    75   }
     72  for (i = 0; i < input->channels; i++) {
    7673
    77   for (k = 0; k < input->length; k++) {
    78     p->winput->data[k] = p->win->data[k] * input->data[k];
    79   }
    80   aubio_fft_do (p->fft, p->winput, p->fftOut);
     74    for (k = 0; k < MAX_PEAKS; k++) {
     75      peaks[k].db = -200.;
     76      peaks[k].bin = 0.;
     77    }
    8178
    82   for (k = 0; k <= p->fftSize / 2; k++) {
    83     smpl_t
    84         magnitude =
    85         20. * LOG10 (2. * p->fftOut->norm[k] / (smpl_t) p->fftSize),
    86         phase = p->fftOut->phas[k], tmp, bin;
     79    for (k = 0; k < input->length; k++) {
     80      p->winput->data[0][k] = p->win->data[0][k] * input->data[i][k];
     81    }
     82    aubio_fft_do (p->fft, p->winput, p->fftOut);
    8783
    88     /* compute phase difference */
    89     tmp = phase - p->fftLastPhase->data[k];
    90     p->fftLastPhase->data[k] = phase;
     84    for (k = 0; k <= p->fftSize / 2; k++) {
     85      smpl_t
     86          magnitude =
     87          20. * LOG10 (2. * p->fftOut->norm[0][k] / (smpl_t) p->fftSize),
     88          phase = p->fftOut->phas[0][k], tmp, bin;
    9189
    92     /* subtract expected phase difference */
    93     tmp -= (smpl_t) k *phaseDifference;
     90      /* compute phase difference */
     91      tmp = phase - p->fftLastPhase->data[i][k];
     92      p->fftLastPhase->data[i][k] = phase;
    9493
    95     /* map delta phase into +/- Pi interval */
    96     tmp = aubio_unwrap2pi (tmp);
     94      /* subtract expected phase difference */
     95      tmp -= (smpl_t) k *phaseDifference;
    9796
    98     /* get deviation from bin frequency from the +/- Pi interval */
    99     tmp = p->fftSize / (smpl_t) p->stepSize * tmp / (TWO_PI);
     97      /* map delta phase into +/- Pi interval */
     98      tmp = aubio_unwrap2pi (tmp);
    10099
    101     /* compute the k-th partials' true bin */
    102     bin = (smpl_t) k + tmp;
     100      /* get deviation from bin frequency from the +/- Pi interval */
     101      tmp = p->fftSize / (smpl_t) p->stepSize * tmp / (TWO_PI);
    103102
    104     if (bin > 0.0 && magnitude > peaks[0].db) {       // && magnitude < 0) {
    105       memmove (peaks + 1, peaks, sizeof (aubio_fpeak_t) * (MAX_PEAKS - 1));
    106       peaks[0].bin = bin;
    107       peaks[0].db = magnitude;
     103      /* compute the k-th partials' true bin */
     104      bin = (smpl_t) k + tmp;
     105
     106      if (bin > 0.0 && magnitude > peaks[0].db) {       // && magnitude < 0) {
     107        memmove (peaks + 1, peaks, sizeof (aubio_fpeak_t) * (MAX_PEAKS - 1));
     108        peaks[0].bin = bin;
     109        peaks[0].db = magnitude;
     110      }
    108111    }
    109   }
    110112
    111   k = 0;
    112   for (l = 1; l < MAX_PEAKS && peaks[l].bin > 0.0; l++) {
    113     sint_t harmonic;
    114     for (harmonic = 5; harmonic > 1; harmonic--) {
    115       if (peaks[0].bin / peaks[l].bin < harmonic + .02 &&
    116           peaks[0].bin / peaks[l].bin > harmonic - .02) {
    117         if (harmonic > (sint_t) maxharm && peaks[0].db < peaks[l].db / 2) {
    118           maxharm = harmonic;
    119           k = l;
     113    k = 0;
     114    for (l = 1; l < MAX_PEAKS && peaks[l].bin > 0.0; l++) {
     115      sint_t harmonic;
     116      for (harmonic = 5; harmonic > 1; harmonic--) {
     117        if (peaks[0].bin / peaks[l].bin < harmonic + .02 &&
     118            peaks[0].bin / peaks[l].bin > harmonic - .02) {
     119          if (harmonic > (sint_t) maxharm && peaks[0].db < peaks[l].db / 2) {
     120            maxharm = harmonic;
     121            k = l;
     122          }
    120123        }
    121124      }
    122125    }
     126    output->data[i][0] = peaks[k].bin;
     127    /* quick hack to clean output a bit */
     128    if (peaks[k].bin > 5000.)
     129      output->data[i][0] = 0.;
    123130  }
    124   output->data[0] = peaks[k].bin;
    125   /* quick hack to clean output a bit */
    126   if (peaks[k].bin > 5000.)
    127     output->data[0] = 0.;
    128131}
    129132
  • TabularUnified src/pitch/pitchfcomb.h

    r8212692 rf650860  
    5757  \param buf_size size of the input buffer to analyse
    5858  \param hop_size step size between two consecutive analysis instant
     59  \param channels number of channels to detect pitch on
    5960 
    6061*/
    61 aubio_pitchfcomb_t *new_aubio_pitchfcomb (uint_t buf_size, uint_t hop_size);
     62aubio_pitchfcomb_t *new_aubio_pitchfcomb (uint_t buf_size, uint_t hop_size,
     63    uint_t channels);
    6264
    6365/** deletion of the pitch detection object
  • TabularUnified src/pitch/pitchmcomb.c

    r8212692 rf650860  
    104104aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output)
    105105{
    106   uint_t j;
     106  uint_t i, j;
    107107  smpl_t instfreq;
    108108  fvec_t *newmag = (fvec_t *) p->newmag;
    109109  //smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta;
    110110  /* copy incoming grain to newmag */
    111   for (j = 0; j < newmag->length; j++)
    112     newmag->data[j] = fftgrain->norm[j];
    113   /* detect only if local energy > 10. */
    114   //if (fvec_local_energy(newmag)>10.) {
    115   //hfc = fvec_local_hfc(newmag); //not used
    116   aubio_pitchmcomb_spectral_pp (p, newmag);
    117   aubio_pitchmcomb_combdet (p, newmag);
    118   //aubio_pitchmcomb_sort_cand_freq(p->candidates,p->ncand);
    119   //return p->candidates[p->goodcandidate]->ebin;
    120   j = (uint_t) FLOOR (p->candidates[p->goodcandidate]->ebin + .5);
    121   instfreq = aubio_unwrap2pi (fftgrain->phas[j]
    122       - p->theta->data[j] - j * p->phasediff);
    123   instfreq *= p->phasefreq;
    124   /* store phase for next run */
    125   for (j = 0; j < p->theta->length; j++) {
    126     p->theta->data[j] = fftgrain->phas[j];
    127   }
    128   //return p->candidates[p->goodcandidate]->ebin;
    129   output->data[0] =
    130       FLOOR (p->candidates[p->goodcandidate]->ebin + .5) + instfreq;
    131   /*} else {
    132      return -1.;
    133      } */
     111  for (i = 0; i < fftgrain->channels; i++) {
     112    for (j = 0; j < newmag->length; j++)
     113      newmag->data[0][j] = fftgrain->norm[i][j];
     114    /* detect only if local energy > 10. */
     115    //if (fvec_local_energy(newmag)>10.) {
     116    //hfc = fvec_local_hfc(newmag); //not used
     117    aubio_pitchmcomb_spectral_pp (p, newmag);
     118    aubio_pitchmcomb_combdet (p, newmag);
     119    //aubio_pitchmcomb_sort_cand_freq(p->candidates,p->ncand);
     120    //return p->candidates[p->goodcandidate]->ebin;
     121    j = (uint_t) FLOOR (p->candidates[p->goodcandidate]->ebin + .5);
     122    instfreq = aubio_unwrap2pi (fftgrain->phas[i][j]
     123        - p->theta->data[i][j] - j * p->phasediff);
     124    instfreq *= p->phasefreq;
     125    /* store phase for next run */
     126    for (j = 0; j < p->theta->length; j++) {
     127      p->theta->data[i][j] = fftgrain->phas[i][j];
     128    }
     129    //return p->candidates[p->goodcandidate]->ebin;
     130    output->data[i][0] =
     131        FLOOR (p->candidates[p->goodcandidate]->ebin + .5) + instfreq;
     132    /*} else {
     133       return -1.;
     134       } */
     135  }
    134136}
    135137
     
    137139aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands)
    138140{
    139   uint_t j;
     141  uint_t i = 0, j;
    140142  uint_t k;
    141143  fvec_t *newmag = (fvec_t *) p->newmag;
     
    145147  /* copy incoming grain to newmag */
    146148  for (j = 0; j < newmag->length; j++)
    147     newmag->data[j] = fftgrain->norm[j];
     149    newmag->data[i][j] = fftgrain->norm[i][j];
    148150  /* detect only if local energy > 10. */
    149151  if (fvec_local_energy (newmag) > 10.) {
     
    170172  fvec_t *mag = (fvec_t *) p->scratch;
    171173  fvec_t *tmp = (fvec_t *) p->scratch2;
    172   uint_t j;
     174  uint_t i = 0, j;
    173175  uint_t length = mag->length;
    174176  /* copy newmag to mag (scracth) */
    175177  for (j = 0; j < length; j++) {
    176     mag->data[j] = newmag->data[j];
     178    mag->data[i][j] = newmag->data[i][j];
    177179  }
    178180  fvec_min_removal (mag);       /* min removal          */
     
    180182  /* skipped *//* low pass filtering   */
    181183  /** \bug fvec_moving_thres may write out of bounds */
    182   fvec_adapt_thres (mag, tmp, p->win_post, p->win_pre);      /* adaptative threshold */
     184  fvec_adapt_thres (mag, tmp, p->win_post, p->win_pre, i);      /* adaptative threshold */
    183185  fvec_add (mag, -p->threshold);        /* fixed threshold      */
    184186  {
     
    188190    count = aubio_pitchmcomb_quadpick (peaks, mag);
    189191    for (j = 0; j < count; j++)
    190       peaks[j].mag = newmag->data[peaks[j].bin];
     192      peaks[j].mag = newmag->data[i][peaks[j].bin];
    191193    /* reset non peaks */
    192194    for (j = count; j < length; j++)
     
    259261        candidate[l]->ecomb[k] = peaks[position].ebin;
    260262        candidate[l]->ene +=    /* ecomb rounded to nearest int */
    261             POW (newmag->data[(uint_t) FLOOR (candidate[l]->ecomb[k] + .5)],
     263            POW (newmag->data[0][(uint_t) FLOOR (candidate[l]->ecomb[k] + .5)],
    262264            0.25);
    263265        candidate[l]->len += 1. / curlen;
     
    288290aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, fvec_t * X)
    289291{
    290   uint_t j, ispeak, count = 0;
    291   for (j = 1; j < X->length - 1; j++) {
    292     ispeak = fvec_peakpick (X, j);
    293     if (ispeak) {
    294       count += ispeak;
    295       spectral_peaks[count - 1].bin = j;
    296       spectral_peaks[count - 1].ebin = fvec_quadint (X, j) - 1.;
    297     }
    298   }
     292  uint_t i, j, ispeak, count = 0;
     293  for (i = 0; i < X->channels; i++)
     294    for (j = 1; j < X->length - 1; j++) {
     295      ispeak = fvec_peakpick (X, j);
     296      if (ispeak) {
     297        count += ispeak;
     298        spectral_peaks[count - 1].bin = j;
     299        spectral_peaks[count - 1].ebin = fvec_quadint (X, j, i) - 1.;
     300      }
     301    }
    299302  return count;
    300303}
     
    361364
    362365aubio_pitchmcomb_t *
    363 new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize)
     366new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize, uint_t channels)
    364367{
    365368  aubio_pitchmcomb_t *p = AUBIO_NEW (aubio_pitchmcomb_t);
     
    383386  //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348);
    384387  /* allocate temp memory */
    385   p->newmag = new_fvec (spec_size);
     388  p->newmag = new_fvec (spec_size, 1);
    386389  /* array for median */
    387   p->scratch = new_fvec (spec_size);
     390  p->scratch = new_fvec (spec_size, 1);
    388391  /* array for phase */
    389   p->theta = new_fvec (spec_size);
     392  p->theta = new_fvec (spec_size, channels);
    390393  /* array for adaptative threshold */
    391   p->scratch2 = new_fvec (p->win_post + p->win_pre + 1);
     394  p->scratch2 = new_fvec (p->win_post + p->win_pre + 1, 1);
    392395  /* array of spectral peaks */
    393396  p->peaks = AUBIO_ARRAY (aubio_spectralpeak_t, spec_size);
  • TabularUnified src/pitch/pitchmcomb.h

    r8212692 rf650860  
    5757  \param buf_size size of the input buffer to analyse
    5858  \param hop_size step size between two consecutive analysis instant
     59  \param channels number of channels to analyse
    5960  \param samplerate sampling rate of the signal
    6061 
    6162*/
    62 aubio_pitchmcomb_t *new_aubio_pitchmcomb (uint_t buf_size, uint_t hop_size);
     63aubio_pitchmcomb_t *new_aubio_pitchmcomb (uint_t buf_size, uint_t hop_size,
     64    uint_t channels);
    6365
    6466/** deletion of the pitch detection object
  • TabularUnified src/pitch/pitchschmitt.c

    r8212692 rf650860  
    5151    fvec_t * output)
    5252{
    53   uint_t j;
    54   for (j = 0; j < input->length; j++) {
    55     p->buf[j] = input->data[j] * 32768.;
     53  uint_t i, j;
     54  for (i = 0; i < input->channels; i++) {
     55    for (j = 0; j < input->length; j++) {
     56      p->buf[j] = input->data[i][j] * 32768.;
     57    }
     58    output->data[i][0] = aubio_schmittS16LE (p, input->length, p->buf);
    5659  }
    57   output->data[0] = aubio_schmittS16LE (p, input->length, p->buf);
    5860}
    5961
  • TabularUnified src/pitch/pitchyin.c

    r8212692 rf650860  
    6565{
    6666  aubio_pitchyin_t *o = AUBIO_NEW (aubio_pitchyin_t);
    67   o->yin = new_fvec (bufsize / 2);
     67  o->yin = new_fvec (bufsize / 2, 1);
    6868  o->tol = 0.15;
    6969  return o;
     
    8181aubio_pitchyin_diff (fvec_t * input, fvec_t * yin)
    8282{
    83   uint_t j, tau;
     83  uint_t c, j, tau;
    8484  smpl_t tmp;
    85   for (tau = 0; tau < yin->length; tau++) {
    86     yin->data[tau] = 0.;
    87   }
    88   for (tau = 1; tau < yin->length; tau++) {
    89     for (j = 0; j < yin->length; j++) {
    90       tmp = input->data[j] - input->data[j + tau];
    91       yin->data[tau] += SQR (tmp);
     85  for (c = 0; c < input->channels; c++) {
     86    for (tau = 0; tau < yin->length; tau++) {
     87      yin->data[c][tau] = 0.;
     88    }
     89    for (tau = 1; tau < yin->length; tau++) {
     90      for (j = 0; j < yin->length; j++) {
     91        tmp = input->data[c][j] - input->data[c][j + tau];
     92        yin->data[c][tau] += SQR (tmp);
     93      }
    9294    }
    9395  }
     
    98100aubio_pitchyin_getcum (fvec_t * yin)
    99101{
    100   uint_t tau;
     102  uint_t c, tau;
    101103  smpl_t tmp;
    102   tmp = 0.;
    103   yin->data[0] = 1.;
    104   //AUBIO_DBG("%f\t",yin->data[0]);
    105   for (tau = 1; tau < yin->length; tau++) {
    106     tmp += yin->data[tau];
    107     yin->data[tau] *= tau / tmp;
    108     //AUBIO_DBG("%f\t",yin->data[tau]);
     104  for (c = 0; c < yin->channels; c++) {
     105    tmp = 0.;
     106    yin->data[c][0] = 1.;
     107    //AUBIO_DBG("%f\t",yin->data[c][0]);
     108    for (tau = 1; tau < yin->length; tau++) {
     109      tmp += yin->data[c][tau];
     110      yin->data[c][tau] *= tau / tmp;
     111      //AUBIO_DBG("%f\t",yin->data[c][tau]);
     112    }
     113    //AUBIO_DBG("\n");
    109114  }
    110   //AUBIO_DBG("\n");
    111115}
    112116
     
    114118aubio_pitchyin_getpitch (fvec_t * yin)
    115119{
    116   uint_t tau = 1;
     120  uint_t c = 0, tau = 1;
    117121  do {
    118     if (yin->data[tau] < 0.1) {
    119       while (yin->data[tau + 1] < yin->data[tau]) {
     122    if (yin->data[c][tau] < 0.1) {
     123      while (yin->data[c][tau + 1] < yin->data[c][tau]) {
    120124        tau++;
    121125      }
     
    135139  smpl_t tol = o->tol;
    136140  fvec_t *yin = o->yin;
    137   uint_t j, tau = 0;
     141  uint_t c, j, tau = 0;
    138142  sint_t period;
    139143  smpl_t tmp = 0., tmp2 = 0.;
    140   yin->data[0] = 1.;
    141   for (tau = 1; tau < yin->length; tau++) {
    142     yin->data[tau] = 0.;
    143     for (j = 0; j < yin->length; j++) {
    144       tmp = input->data[j] - input->data[j + tau];
    145       yin->data[tau] += SQR (tmp);
     144  for (c = 0; c < input->channels; c++) {
     145    yin->data[c][0] = 1.;
     146    for (tau = 1; tau < yin->length; tau++) {
     147      yin->data[c][tau] = 0.;
     148      for (j = 0; j < yin->length; j++) {
     149        tmp = input->data[c][j] - input->data[c][j + tau];
     150        yin->data[c][tau] += SQR (tmp);
     151      }
     152      tmp2 += yin->data[c][tau];
     153      yin->data[c][tau] *= tau / tmp2;
     154      period = tau - 3;
     155      if (tau > 4 && (yin->data[c][period] < tol) &&
     156          (yin->data[c][period] < yin->data[c][period + 1])) {
     157        out->data[c][0] = fvec_quadint (yin, period, c);
     158        goto beach;
     159      }
    146160    }
    147     tmp2 += yin->data[tau];
    148     yin->data[tau] *= tau / tmp2;
    149     period = tau - 3;
    150     if (tau > 4 && (yin->data[period] < tol) &&
    151         (yin->data[period] < yin->data[period + 1])) {
    152       out->data[0] = fvec_quadint (yin, period);
    153       goto beach;
    154     }
     161    out->data[c][0] = fvec_quadint (yin, fvec_min_elem (yin), c);
     162  beach:
     163    continue;
    155164  }
    156   out->data[0] = fvec_quadint (yin, fvec_min_elem (yin));
    157 beach:
    158   return;
     165  //return 0;
    159166}
    160167
  • TabularUnified src/pitch/pitchyinfft.c

    r8212692 rf650860  
    5656{
    5757  aubio_pitchyinfft_t *p = AUBIO_NEW (aubio_pitchyinfft_t);
    58   p->winput = new_fvec (bufsize);
    59   p->fft = new_aubio_fft (bufsize);
    60   p->fftout = new_cvec (bufsize);
    61   p->sqrmag = new_fvec (bufsize);
    62   p->res = new_cvec (bufsize);
    63   p->yinfft = new_fvec (bufsize / 2 + 1);
     58  p->winput = new_fvec (bufsize, 1);
     59  p->fft = new_aubio_fft (bufsize, 1);
     60  p->fftout = new_cvec (bufsize, 1);
     61  p->sqrmag = new_fvec (bufsize, 1);
     62  p->res = new_cvec (bufsize, 1);
     63  p->yinfft = new_fvec (bufsize / 2 + 1, 1);
    6464  p->tol = 0.85;
    6565  p->win = new_aubio_window ("hanningz", bufsize);
    66   p->weight = new_fvec (bufsize / 2 + 1);
    67   uint_t i = 0, j = 1;
    68   smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
    69   for (i = 0; i < p->weight->length; i++) {
    70     freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) 44100.;
    71     while (freq > freqs[j]) {
    72       j += 1;
     66  p->weight = new_fvec (bufsize / 2 + 1, 1);
     67  {
     68    uint_t i = 0, j = 1;
     69    smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
     70    for (i = 0; i < p->weight->length; i++) {
     71      freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) 44100.;
     72      while (freq > freqs[j]) {
     73        j += 1;
     74      }
     75      a0 = weight[j - 1];
     76      f0 = freqs[j - 1];
     77      a1 = weight[j];
     78      f1 = freqs[j];
     79      if (f0 == f1) {           // just in case
     80        p->weight->data[0][i] = a0;
     81      } else if (f0 == 0) {     // y = ax+b
     82        p->weight->data[0][i] = (a1 - a0) / f1 * freq + a0;
     83      } else {
     84        p->weight->data[0][i] = (a1 - a0) / (f1 - f0) * freq +
     85            (a0 - (a1 - a0) / (f1 / f0 - 1.));
     86      }
     87      while (freq > freqs[j]) {
     88        j += 1;
     89      }
     90      //AUBIO_DBG("%f\n",p->weight->data[0][i]);
     91      p->weight->data[0][i] = DB2LIN (p->weight->data[0][i]);
     92      //p->weight->data[0][i] = SQRT(DB2LIN(p->weight->data[0][i]));
    7393    }
    74     a0 = weight[j - 1];
    75     f0 = freqs[j - 1];
    76     a1 = weight[j];
    77     f1 = freqs[j];
    78     if (f0 == f1) {           // just in case
    79       p->weight->data[i] = a0;
    80     } else if (f0 == 0) {     // y = ax+b
    81       p->weight->data[i] = (a1 - a0) / f1 * freq + a0;
    82     } else {
    83       p->weight->data[i] = (a1 - a0) / (f1 - f0) * freq +
    84           (a0 - (a1 - a0) / (f1 / f0 - 1.));
    85     }
    86     while (freq > freqs[j]) {
    87       j += 1;
    88     }
    89     //AUBIO_DBG("%f\n",p->weight->data[i]);
    90     p->weight->data[i] = DB2LIN (p->weight->data[i]);
    91     //p->weight->data[i] = SQRT(DB2LIN(p->weight->data[i]));
    9294  }
    9395  return p;
     
    9799aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output)
    98100{
    99   uint_t tau, l;
     101  uint_t i, tau, l;
    100102  uint_t halfperiod;
    101103  smpl_t tmp, sum;
    102104  cvec_t *res = (cvec_t *) p->res;
    103105  fvec_t *yin = (fvec_t *) p->yinfft;
    104   l = 0;
    105   tmp = 0.;
    106   sum = 0.;
    107   for (l = 0; l < input->length; l++) {
    108     p->winput->data[l] = p->win->data[l] * input->data[l];
    109   }
    110   aubio_fft_do (p->fft, p->winput, p->fftout);
    111   for (l = 0; l < p->fftout->length; l++) {
    112     p->sqrmag->data[l] = SQR (p->fftout->norm[l]);
    113     p->sqrmag->data[l] *= p->weight->data[l];
    114   }
    115   for (l = 1; l < p->fftout->length; l++) {
    116     p->sqrmag->data[(p->fftout->length - 1) * 2 - l] =
    117         SQR (p->fftout->norm[l]);
    118     p->sqrmag->data[(p->fftout->length - 1) * 2 - l] *=
    119         p->weight->data[l];
    120   }
    121   for (l = 0; l < p->sqrmag->length / 2 + 1; l++) {
    122     sum += p->sqrmag->data[l];
    123   }
    124   sum *= 2.;
    125   aubio_fft_do (p->fft, p->sqrmag, res);
    126   yin->data[0] = 1.;
    127   for (tau = 1; tau < yin->length; tau++) {
    128     yin->data[tau] = sum - res->norm[tau] * COS (res->phas[tau]);
    129     tmp += yin->data[tau];
    130     yin->data[tau] *= tau / tmp;
    131   }
    132   tau = fvec_min_elem (yin);
    133   if (yin->data[tau] < p->tol) {
    134     /* no interpolation */
    135     //return tau;
    136     /* 3 point quadratic interpolation */
    137     //return fvec_quadint_min(yin,tau,1);
    138     /* additional check for (unlikely) octave doubling in higher frequencies */
    139     if (tau > 35) {
    140       output->data[0] = fvec_quadint (yin, tau);
     106  for (i = 0; i < input->channels; i++) {
     107    l = 0;
     108    tmp = 0.;
     109    sum = 0.;
     110    for (l = 0; l < input->length; l++) {
     111      p->winput->data[0][l] = p->win->data[0][l] * input->data[i][l];
     112    }
     113    aubio_fft_do (p->fft, p->winput, p->fftout);
     114    for (l = 0; l < p->fftout->length; l++) {
     115      p->sqrmag->data[0][l] = SQR (p->fftout->norm[0][l]);
     116      p->sqrmag->data[0][l] *= p->weight->data[0][l];
     117    }
     118    for (l = 1; l < p->fftout->length; l++) {
     119      p->sqrmag->data[0][(p->fftout->length - 1) * 2 - l] =
     120          SQR (p->fftout->norm[0][l]);
     121      p->sqrmag->data[0][(p->fftout->length - 1) * 2 - l] *=
     122          p->weight->data[0][l];
     123    }
     124    for (l = 0; l < p->sqrmag->length / 2 + 1; l++) {
     125      sum += p->sqrmag->data[0][l];
     126    }
     127    sum *= 2.;
     128    aubio_fft_do (p->fft, p->sqrmag, res);
     129    yin->data[0][0] = 1.;
     130    for (tau = 1; tau < yin->length; tau++) {
     131      yin->data[0][tau] = sum - res->norm[0][tau] * COS (res->phas[0][tau]);
     132      tmp += yin->data[0][tau];
     133      yin->data[0][tau] *= tau / tmp;
     134    }
     135    tau = fvec_min_elem (yin);
     136    if (yin->data[0][tau] < p->tol) {
     137      /* no interpolation */
     138      //return tau;
     139      /* 3 point quadratic interpolation */
     140      //return fvec_quadint_min(yin,tau,1);
     141      /* additional check for (unlikely) octave doubling in higher frequencies */
     142      if (tau > 35) {
     143        output->data[i][0] = fvec_quadint (yin, tau, i);
     144      } else {
     145        /* should compare the minimum value of each interpolated peaks */
     146        halfperiod = FLOOR (tau / 2 + .5);
     147        if (yin->data[0][halfperiod] < p->tol)
     148          output->data[i][0] = fvec_quadint (yin, halfperiod, i);
     149        else
     150          output->data[i][0] = fvec_quadint (yin, tau, i);
     151      }
    141152    } else {
    142       /* should compare the minimum value of each interpolated peaks */
    143       halfperiod = FLOOR (tau / 2 + .5);
    144       if (yin->data[halfperiod] < p->tol)
    145         output->data[0] = fvec_quadint (yin, halfperiod);
    146       else
    147         output->data[0] = fvec_quadint (yin, tau);
     153      output->data[i][0] = 0.;
    148154    }
    149   } else {
    150     output->data[0] = 0.;
    151155  }
    152156}
  • TabularUnified src/spectral/fft.c

    r8212692 rf650860  
    7575struct _aubio_fft_t {
    7676  uint_t winsize;
     77  uint_t channels;
    7778  uint_t fft_size;
    7879  real_t *in, *out;
     
    8283};
    8384
    84 aubio_fft_t * new_aubio_fft(uint_t winsize) {
     85aubio_fft_t * new_aubio_fft(uint_t winsize, uint_t channels) {
    8586  aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
    8687  uint_t i;
    8788  s->winsize  = winsize;
     89  s->channels = channels;
    8890  /* allocate memory */
    8991  s->in       = AUBIO_ARRAY(real_t,winsize);
    9092  s->out      = AUBIO_ARRAY(real_t,winsize);
    91   s->compspec = new_fvec(winsize);
     93  s->compspec = new_fvec(winsize,channels);
    9294  /* create plans */
    9395#ifdef HAVE_COMPLEX_H
     
    134136
    135137void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) {
    136   uint_t j;
    137   for (j=0; j < s->winsize; j++) {
    138     s->in[j] = input->data[j];
    139   }
    140   fftw_execute(s->pfw);
    141 #ifdef HAVE_COMPLEX_H
    142   compspec->data[0] = REAL(s->specdata[0]);
    143   for (j = 1; j < s->fft_size -1 ; j++) {
    144     compspec->data[j] = REAL(s->specdata[j]);
    145     compspec->data[compspec->length - j] = IMAG(s->specdata[j]);
    146   }
    147   compspec->data[s->fft_size-1] = REAL(s->specdata[s->fft_size-1]);
    148 #else
    149   for (j = 0; j < s->fft_size; j++) {
    150     compspec->data[j] = s->specdata[j];
    151   }
    152 #endif
     138  uint_t i, j;
     139  for (i = 0; i < s->channels; i++) {
     140    for (j=0; j < s->winsize; j++) {
     141      s->in[j] = input->data[i][j];
     142    }
     143    fftw_execute(s->pfw);
     144#ifdef HAVE_COMPLEX_H
     145    compspec->data[i][0] = REAL(s->specdata[0]);
     146    for (j = 1; j < s->fft_size -1 ; j++) {
     147      compspec->data[i][j] = REAL(s->specdata[j]);
     148      compspec->data[i][compspec->length - j] = IMAG(s->specdata[j]);
     149    }
     150    compspec->data[i][s->fft_size-1] = REAL(s->specdata[s->fft_size-1]);
     151#else
     152    for (j = 0; j < s->fft_size; j++) {
     153      compspec->data[i][j] = s->specdata[j];
     154    }
     155#endif
     156  }
    153157}
    154158
    155159void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) {
    156   uint_t j;
     160  uint_t i, j;
    157161  const smpl_t renorm = 1./(smpl_t)s->winsize;
    158 #ifdef HAVE_COMPLEX_H
    159   s->specdata[0] = compspec->data[0];
    160   for (j=1; j < s->fft_size - 1; j++) {
    161     s->specdata[j] = compspec->data[j] +
    162       I * compspec->data[compspec->length - j];
    163   }
    164   s->specdata[s->fft_size - 1] = compspec->data[s->fft_size - 1];
    165 #else
    166   for (j=0; j < s->fft_size; j++) {
    167     s->specdata[j] = compspec->data[j];
    168   }
    169 #endif
    170   fftw_execute(s->pbw);
    171   for (j = 0; j < output->length; j++) {
    172     output->data[j] = s->out[j]*renorm;
     162  for (i = 0; i < compspec->channels; i++) {
     163#ifdef HAVE_COMPLEX_H
     164    s->specdata[0] = compspec->data[i][0];
     165    for (j=1; j < s->fft_size - 1; j++) {
     166      s->specdata[j] = compspec->data[i][j] +
     167        I * compspec->data[i][compspec->length - j];
     168    }
     169    s->specdata[s->fft_size - 1] = compspec->data[i][s->fft_size - 1];
     170#else
     171    for (j=0; j < s->fft_size; j++) {
     172      s->specdata[j] = compspec->data[i][j];
     173    }
     174#endif
     175    fftw_execute(s->pbw);
     176    for (j = 0; j < output->length; j++) {
     177      output->data[i][j] = s->out[j]*renorm;
     178    }
    173179  }
    174180}
     
    185191
    186192void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) {
    187   uint_t j;
    188   if (compspec->data[0] < 0) {
    189     spectrum->phas[0] = PI;
    190   } else {
    191     spectrum->phas[0] = 0.;
    192   }
    193   for (j=1; j < spectrum->length - 1; j++) {
    194     spectrum->phas[j] = ATAN2(compspec->data[compspec->length-j],
    195         compspec->data[j]);
    196   }
    197   if (compspec->data[compspec->length/2] < 0) {
    198     spectrum->phas[spectrum->length - 1] = PI;
    199   } else {
    200     spectrum->phas[spectrum->length - 1] = 0.;
     193  uint_t i, j;
     194  for (i = 0; i < spectrum->channels; i++) {
     195    if (compspec->data[i][0] < 0) {
     196      spectrum->phas[i][0] = PI;
     197    } else {
     198      spectrum->phas[i][0] = 0.;
     199    }
     200    for (j=1; j < spectrum->length - 1; j++) {
     201      spectrum->phas[i][j] = ATAN2(compspec->data[i][compspec->length-j],
     202          compspec->data[i][j]);
     203    }
     204    if (compspec->data[i][compspec->length/2] < 0) {
     205      spectrum->phas[i][spectrum->length - 1] = PI;
     206    } else {
     207      spectrum->phas[i][spectrum->length - 1] = 0.;
     208    }
    201209  }
    202210}
    203211
    204212void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) {
    205   uint_t j = 0;
    206   spectrum->norm[0] = ABS(compspec->data[0]);
    207   for (j=1; j < spectrum->length - 1; j++) {
    208     spectrum->norm[j] = SQRT(SQR(compspec->data[j])
    209         + SQR(compspec->data[compspec->length - j]) );
    210   }
    211   spectrum->norm[spectrum->length-1] =
    212     ABS(compspec->data[compspec->length/2]);
     213  uint_t i, j = 0;
     214  for (i = 0; i < spectrum->channels; i++) {
     215    spectrum->norm[i][0] = ABS(compspec->data[i][0]);
     216    for (j=1; j < spectrum->length - 1; j++) {
     217      spectrum->norm[i][j] = SQRT(SQR(compspec->data[i][j])
     218          + SQR(compspec->data[i][compspec->length - j]) );
     219    }
     220    spectrum->norm[i][spectrum->length-1] =
     221      ABS(compspec->data[i][compspec->length/2]);
     222  }
    213223}
    214224
    215225void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) {
    216   uint_t j;
    217   for (j = 1; j < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; j++) {
    218     compspec->data[compspec->length - j] =
    219       spectrum->norm[j]*SIN(spectrum->phas[j]);
     226  uint_t i, j;
     227  for (i = 0; i < compspec->channels; i++) {
     228    for (j = 1; j < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; j++) {
     229      compspec->data[i][compspec->length - j] =
     230        spectrum->norm[i][j]*SIN(spectrum->phas[i][j]);
     231    }
    220232  }
    221233}
    222234
    223235void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec) {
    224   uint_t j;
    225   for (j = 0; j < compspec->length / 2 + 1; j++) {
    226     compspec->data[j] =
    227       spectrum->norm[j]*COS(spectrum->phas[j]);
    228   }
    229 }
     236  uint_t i, j;
     237  for (i = 0; i < compspec->channels; i++) {
     238    for (j = 0; j < compspec->length / 2 + 1; j++) {
     239      compspec->data[i][j] =
     240        spectrum->norm[i][j]*COS(spectrum->phas[i][j]);
     241    }
     242  }
     243}
  • TabularUnified src/spectral/fft.h

    r8212692 rf650860  
    4545
    4646  \param size length of the FFT
     47  \param channels number of channels
    4748
    4849*/
    49 aubio_fft_t * new_aubio_fft (uint_t size);
     50aubio_fft_t * new_aubio_fft(uint_t size, uint_t channels);
    5051/** delete FFT object
    5152
  • TabularUnified src/spectral/filterbank.c

    r8212692 rf650860  
    2222#include "aubio_priv.h"
    2323#include "fvec.h"
    24 #include "fmat.h"
    2524#include "cvec.h"
    2625#include "spectral/filterbank.h"
     
    3231  uint_t win_s;
    3332  uint_t n_filters;
    34   fmat_t *filters;
     33  fvec_t *filters;
    3534};
    3635
     
    4342  fb->n_filters = n_filters;
    4443
    45   /* allocate filter tables, a matrix of length win_s and of height n_filters */
    46   fb->filters = new_fmat (win_s / 2 + 1, n_filters);
     44  /* allocate filter tables, an fvec of length win_s and of filter_cnt channel */
     45  fb->filters = new_fvec (win_s / 2 + 1, n_filters);
    4746
    4847  return fb;
     
    5251del_aubio_filterbank (aubio_filterbank_t * fb)
    5352{
    54   del_fmat (fb->filters);
     53  del_fvec (fb->filters);
    5554  AUBIO_FREE (fb);
    5655}
     
    5958aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out)
    6059{
    61   uint_t j, fn;
     60  uint_t i, j, fn;
    6261
    6362  /* apply filter to all input channel, provided out has enough channels */
     63  uint_t max_channels = MIN (in->channels, out->channels);
    6464  uint_t max_filters = MIN (f->n_filters, out->length);
    6565  uint_t max_length = MIN (in->length, f->filters->length);
     
    6868  fvec_zeros (out);
    6969
    70   /* for each filter */
    71   for (fn = 0; fn < max_filters; fn++) {
     70  /* apply filters on all channels */
     71  for (i = 0; i < max_channels; i++) {
    7272
    73     /* for each sample */
    74     for (j = 0; j < max_length; j++) {
    75       out->data[fn] += in->norm[j] * f->filters->data[fn][j];
     73    /* for each filter */
     74    for (fn = 0; fn < max_filters; fn++) {
     75
     76      /* for each sample */
     77      for (j = 0; j < max_length; j++) {
     78        out->data[i][fn] += in->norm[i][j] * f->filters->data[fn][j];
     79      }
    7680    }
    7781  }
     
    8084}
    8185
    82 fmat_t *
     86fvec_t *
    8387aubio_filterbank_get_coeffs (aubio_filterbank_t * f)
    8488{
     
    8791
    8892uint_t
    89 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filter_coeffs)
     93aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fvec_t * filters)
    9094{
    91   fmat_copy(filter_coeffs, f->filters);
     95  fvec_copy(filters, f->filters);
    9296  return 0;
    9397}
  • TabularUnified src/spectral/filterbank.h

    r8212692 rf650860  
    6363void aubio_filterbank_do (aubio_filterbank_t * fb, cvec_t * in, fvec_t * out);
    6464
    65 /** return a pointer to the matrix object containing all filter coefficients
     65/** return a pointer to the fvec object containing all filter coefficients
    6666
    6767  \param f filterbank object to get coefficients from
    6868
    6969 */
    70 fmat_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f);
     70fvec_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f);
    7171
    7272/** copy filter coefficients to the filterbank
     
    7676
    7777 */
    78 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filters);
     78uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fvec_t * filters);
    7979
    8080#ifdef __cplusplus
  • TabularUnified src/spectral/filterbank_mel.c

    r8212692 rf650860  
    2121
    2222#include "aubio_priv.h"
    23 #include "fmat.h"
    2423#include "fvec.h"
    2524#include "cvec.h"
     
    3231{
    3332
    34   fmat_t *filters = aubio_filterbank_get_coeffs (fb);
    35   uint_t n_filters = filters->height, win_s = filters->length;
     33  fvec_t *filters = aubio_filterbank_get_coeffs (fb);
     34  uint_t n_filters = filters->channels, win_s = filters->length;
    3635
    3736  uint_t fn;                    /* filter counter */
     
    5049  }
    5150
    52   if (freqs->data[freqs->length - 1] > samplerate / 2) {
     51  if (freqs->data[0][freqs->length - 1] > samplerate / 2) {
    5352    AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \
    54 %fHz\n", samplerate / 2, freqs->data[freqs->length - 1]);
     53%fHz\n", samplerate / 2, freqs->data[0][freqs->length - 1]);
    5554  }
    5655
    5756  /* convenience reference to lower/center/upper frequency for each triangle */
    58   fvec_t *lower_freqs = new_fvec (n_filters);
    59   fvec_t *upper_freqs = new_fvec (n_filters);
    60   fvec_t *center_freqs = new_fvec (n_filters);
     57  fvec_t *lower_freqs = new_fvec (n_filters, 1);
     58  fvec_t *upper_freqs = new_fvec (n_filters, 1);
     59  fvec_t *center_freqs = new_fvec (n_filters, 1);
    6160
    6261  /* height of each triangle */
    63   fvec_t *triangle_heights = new_fvec (n_filters);
     62  fvec_t *triangle_heights = new_fvec (n_filters, 1);
    6463
    6564  /* lookup table of each bin frequency in hz */
    66   fvec_t *fft_freqs = new_fvec (win_s);
     65  fvec_t *fft_freqs = new_fvec (win_s, 1);
    6766
    6867  /* fill up the lower/center/upper */
    6968  for (fn = 0; fn < n_filters; fn++) {
    70     lower_freqs->data[fn] = freqs->data[fn];
    71     center_freqs->data[fn] = freqs->data[fn + 1];
    72     upper_freqs->data[fn] = freqs->data[fn + 2];
     69    lower_freqs->data[0][fn] = freqs->data[0][fn];
     70    center_freqs->data[0][fn] = freqs->data[0][fn + 1];
     71    upper_freqs->data[0][fn] = freqs->data[0][fn + 2];
    7372  }
    7473
    7574  /* compute triangle heights so that each triangle has unit area */
    7675  for (fn = 0; fn < n_filters; fn++) {
    77     triangle_heights->data[fn] =
    78         2. / (upper_freqs->data[fn] - lower_freqs->data[fn]);
     76    triangle_heights->data[0][fn] =
     77        2. / (upper_freqs->data[0][fn] - lower_freqs->data[0][fn]);
    7978  }
    8079
    8180  /* fill fft_freqs lookup table, which assigns the frequency in hz to each bin */
    8281  for (bin = 0; bin < win_s; bin++) {
    83     fft_freqs->data[bin] =
     82    fft_freqs->data[0][bin] =
    8483        aubio_bintofreq (bin, samplerate, (win_s - 1) * 2);
    8584  }
    8685
    8786  /* zeroing of all filters */
    88   fmat_zeros (filters);
     87  fvec_zeros (filters);
    8988
    90   if (fft_freqs->data[1] >= lower_freqs->data[0]) {
     89  if (fft_freqs->data[0][1] >= lower_freqs->data[0][0]) {
    9190    /* - 1 to make sure we don't miss the smallest power of two */
    9291    uint_t min_win_s =
    93         (uint_t) FLOOR (samplerate / lower_freqs->data[0]) - 1;
     92        (uint_t) FLOOR (samplerate / lower_freqs->data[0][0]) - 1;
    9493    AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \
    9594band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n",
    96         fft_freqs->data[1], lower_freqs->data[0],
    97         upper_freqs->data[0], (win_s - 1) * 2,
     95        fft_freqs->data[0][1], lower_freqs->data[0][0],
     96        upper_freqs->data[0][0], (win_s - 1) * 2,
    9897        aubio_next_power_of_two (min_win_s));
    9998  }
     
    104103    /* skip first elements */
    105104    for (bin = 0; bin < win_s - 1; bin++) {
    106       if (fft_freqs->data[bin] <= lower_freqs->data[fn] &&
    107           fft_freqs->data[bin + 1] > lower_freqs->data[fn]) {
     105      if (fft_freqs->data[0][bin] <= lower_freqs->data[0][fn] &&
     106          fft_freqs->data[0][bin + 1] > lower_freqs->data[0][fn]) {
    108107        bin++;
    109108        break;
     
    113112    /* compute positive slope step size */
    114113    smpl_t riseInc =
    115         triangle_heights->data[fn] /
    116         (center_freqs->data[fn] - lower_freqs->data[fn]);
     114        triangle_heights->data[0][fn] /
     115        (center_freqs->data[0][fn] - lower_freqs->data[0][fn]);
    117116
    118117    /* compute coefficients in positive slope */
    119118    for (; bin < win_s - 1; bin++) {
    120119      filters->data[fn][bin] =
    121           (fft_freqs->data[bin] - lower_freqs->data[fn]) * riseInc;
     120          (fft_freqs->data[0][bin] - lower_freqs->data[0][fn]) * riseInc;
    122121
    123       if (fft_freqs->data[bin + 1] >= center_freqs->data[fn]) {
     122      if (fft_freqs->data[0][bin + 1] >= center_freqs->data[0][fn]) {
    124123        bin++;
    125124        break;
     
    129128    /* compute negative slope step size */
    130129    smpl_t downInc =
    131         triangle_heights->data[fn] /
    132         (upper_freqs->data[fn] - center_freqs->data[fn]);
     130        triangle_heights->data[0][fn] /
     131        (upper_freqs->data[0][fn] - center_freqs->data[0][fn]);
    133132
    134133    /* compute coefficents in negative slope */
    135134    for (; bin < win_s - 1; bin++) {
    136135      filters->data[fn][bin] +=
    137           (upper_freqs->data[fn] - fft_freqs->data[bin]) * downInc;
     136          (upper_freqs->data[0][fn] - fft_freqs->data[0][bin]) * downInc;
    138137
    139138      if (filters->data[fn][bin] < 0.) {
     
    141140      }
    142141
    143       if (fft_freqs->data[bin + 1] >= upper_freqs->data[fn])
     142      if (fft_freqs->data[0][bin + 1] >= upper_freqs->data[0][fn])
    144143        break;
    145144    }
     
    177176
    178177  /* buffers to compute filter frequencies */
    179   fvec_t *freqs = new_fvec (n_filters + 2);
     178  fvec_t *freqs = new_fvec (n_filters + 2, 1);
    180179
    181180  /* first step: fill all the linear filter frequencies */
    182181  for (fn = 0; fn < linearFilters; fn++) {
    183     freqs->data[fn] = lowestFrequency + fn * linearSpacing;
     182    freqs->data[0][fn] = lowestFrequency + fn * linearSpacing;
    184183  }
    185   smpl_t lastlinearCF = freqs->data[fn - 1];
     184  smpl_t lastlinearCF = freqs->data[0][fn - 1];
    186185
    187186  /* second step: fill all the log filter frequencies */
    188187  for (fn = 0; fn < logFilters + 2; fn++) {
    189     freqs->data[fn + linearFilters] =
     188    freqs->data[0][fn + linearFilters] =
    190189        lastlinearCF * (POW (logSpacing, fn + 1));
    191190  }
  • TabularUnified src/spectral/mfcc.c

    r8212692 rf650860  
    2222#include "aubio_priv.h"
    2323#include "fvec.h"
    24 #include "fmat.h"
    2524#include "cvec.h"
    2625#include "mathutils.h"
     
    4140  aubio_filterbank_t *fb;   /** filter bank */
    4241  fvec_t *in_dct;           /** input buffer for dct * [fb->n_filters] */
    43   fmat_t *dct_coeffs;       /** DCT transform n_filters * n_coeffs */
     42  fvec_t *dct_coeffs;       /** DCT transform n_filters * n_coeffs */
    4443};
    4544
     
    6564
    6665  /* allocating buffers */
    67   mfcc->in_dct = new_fvec (n_filters);
     66  mfcc->in_dct = new_fvec (n_filters, 1);
    6867
    69   mfcc->dct_coeffs = new_fmat (n_coefs, n_filters);
     68  mfcc->dct_coeffs = new_fvec (n_coefs, n_filters);
    7069
    7170  /* compute DCT transform dct_coeffs[i][j] as
     
    101100aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out)
    102101{
    103   uint_t j, k;
     102  uint_t i, j, k;
    104103
    105104  /* compute filterbank */
     
    116115
    117116  /* compute discrete cosine transform */
    118   for (j = 0; j < mf->n_filters; j++) {
    119     for (k = 0; k < mf->n_coefs; k++) {
    120       out->data[k] += mf->in_dct->data[j]
    121           * mf->dct_coeffs->data[j][k];
     117  for (i = 0; i < out->channels; i++) {
     118    for (j = 0; j < mf->n_filters; j++) {
     119      for (k = 0; k < mf->n_coefs; k++) {
     120        out->data[i][k] += mf->in_dct->data[i][j]
     121            * mf->dct_coeffs->data[j][k];
     122      }
    122123    }
    123124  }
  • TabularUnified src/spectral/phasevoc.c

    r8212692 rf650860  
    3030  uint_t win_s;       /** grain length */
    3131  uint_t hop_s;       /** overlap step */
     32  uint_t channels;    /** number of channels */
    3233  aubio_fft_t * fft;  /** fft object */
    3334  fvec_t * synth;     /** cur output grain [win_s] */
     
    4849
    4950void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {
    50   /* slide  */
    51   aubio_pvoc_swapbuffers(pv->data->data,pv->dataold->data,
    52       datanew->data,pv->win_s,pv->hop_s);
     51  uint_t i;
     52  for (i=0; i<pv->channels; i++) {
     53    /* slide  */
     54    aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i],
     55        datanew->data[i],pv->win_s,pv->hop_s);
     56  }
    5357  /* windowing */
    5458  fvec_weight(pv->data, pv->w);
     
    6064
    6165void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) {
     66  uint_t i;
    6267  /* calculate rfft */
    6368  aubio_fft_rdo(pv->fft,fftgrain,pv->synth);
    6469  /* unshift */
    6570  fvec_shift(pv->synth);
    66   aubio_pvoc_addsynth(pv->synth->data,pv->synthold->data,
    67       synthnew->data,pv->win_s,pv->hop_s);
     71  for (i=0; i<pv->channels; i++) {
     72    aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
     73        synthnew->data[i],pv->win_s,pv->hop_s);
     74  }
    6875}
    6976
    70 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s) {
     77aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) {
    7178  aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
    7279
     
    8188  }
    8289
    83   pv->fft      = new_aubio_fft (win_s);
     90  pv->fft      = new_aubio_fft(win_s,channels);
    8491
    8592  /* remember old */
    86   pv->data     = new_fvec (win_s);
    87   pv->synth    = new_fvec (win_s);
     93  pv->data     = new_fvec (win_s, channels);
     94  pv->synth    = new_fvec (win_s, channels);
    8895
    8996  /* new input output */
    90   pv->dataold  = new_fvec  (win_s-hop_s);
    91   pv->synthold = new_fvec (win_s-hop_s);
     97  pv->dataold  = new_fvec  (win_s-hop_s, channels);
     98  pv->synthold = new_fvec (win_s-hop_s, channels);
    9299  pv->w        = new_aubio_window ("hanningz", win_s);
    93100
     101  pv->channels = channels;
    94102  pv->hop_s    = hop_s;
    95103  pv->win_s    = win_s;
  • TabularUnified src/spectral/phasevoc.h

    r8212692 rf650860  
    2626  using a HanningZ window and a swapped version of the signal to simplify the
    2727  phase relationships across frames. The window sizes and overlap are specified
    28   at creation time.
     28  at creation time. Multiple channels are fully supported.
    2929
    3030*/
     
    4444  \param win_s size of analysis buffer (and length the FFT transform)
    4545  \param hop_s step size between two consecutive analysis
     46  \param channels number of channels
    4647
    4748*/
    48 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s);
     49aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels);
    4950/** delete phase vocoder object
    5051
     
    5657/** compute spectral frame
    5758 
    58   This function accepts an input vector of size [hop_s]. The
     59  This function accepts an input vector of size [channels]x[hop_s]. The
    5960  analysis buffer is rotated and filled with the new data. After windowing of
    6061  this signal window, the Fourier transform is computed and returned in
     
    7071
    7172  This function takes an input spectral frame fftgrain of size
    72   [buf_s] and computes its inverse Fourier transform. Overlap-add
     73  [channels]x[buf_s] and computes its inverse Fourier transform. Overlap-add
    7374  synthesis is then computed using the previously synthetised frames, and the
    7475  output stored in out.
     
    9394*/
    9495uint_t aubio_pvoc_get_hop(aubio_pvoc_t* pv);
     96/** get channel number
     97 
     98  \param pv phase vocoder to get the number of channels from
     99
     100*/
     101uint_t aubio_pvoc_get_channels(aubio_pvoc_t* pv);
    95102
    96103#ifdef __cplusplus
  • TabularUnified src/spectral/specdesc.c

    r8212692 rf650860  
    8989void aubio_specdesc_energy  (aubio_specdesc_t *o UNUSED,
    9090    cvec_t * fftgrain, fvec_t * onset) {
    91   uint_t j;
    92   onset->data[0] = 0.;
    93   for (j=0;j<fftgrain->length;j++) {
    94     onset->data[0] += SQR(fftgrain->norm[j]);
     91  uint_t i,j;
     92  for (i=0;i<fftgrain->channels;i++) {
     93    onset->data[i][0] = 0.;
     94    for (j=0;j<fftgrain->length;j++) {
     95      onset->data[i][0] += SQR(fftgrain->norm[i][j]);
     96    }
    9597  }
    9698}
     
    99101void aubio_specdesc_hfc(aubio_specdesc_t *o UNUSED,
    100102    cvec_t * fftgrain, fvec_t * onset){
    101   uint_t j;
    102   onset->data[0] = 0.;
    103   for (j=0;j<fftgrain->length;j++) {
    104     onset->data[0] += (j+1)*fftgrain->norm[j];
     103  uint_t i,j;
     104  for (i=0;i<fftgrain->channels;i++) {
     105    onset->data[i][0] = 0.;
     106    for (j=0;j<fftgrain->length;j++) {
     107      onset->data[i][0] += (j+1)*fftgrain->norm[i][j];
     108    }
    105109  }
    106110}
     
    109113/* Complex Domain Method onset detection function */
    110114void aubio_specdesc_complex (aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset) {
    111   uint_t j;
     115  uint_t i, j;
    112116  uint_t nbins = fftgrain->length;
    113   onset->data[0] = 0.;
    114   for (j=0;j<nbins; j++)  {
    115     // compute the predicted phase
    116     o->dev1->data[j] = 2. * o->theta1->data[j] - o->theta2->data[j];
    117     // compute the euclidean distance in the complex domain
    118     // sqrt ( r_1^2 + r_2^2 - 2 * r_1 * r_2 * \cos ( \phi_1 - \phi_2 ) )
    119     onset->data[0] +=
    120       SQRT (ABS (SQR (o->oldmag->data[j]) + SQR (fftgrain->norm[j])
    121             - 2. * o->oldmag->data[j] * fftgrain->norm[j]
    122             * COS (o->dev1->data[j] - fftgrain->phas[j])));
    123     /* swap old phase data (need to remember 2 frames behind)*/
    124     o->theta2->data[j] = o->theta1->data[j];
    125     o->theta1->data[j] = fftgrain->phas[j];
    126     /* swap old magnitude data (1 frame is enough) */
    127     o->oldmag->data[j] = fftgrain->norm[j];
     117  for (i=0;i<fftgrain->channels; i++)  {
     118    onset->data[i][0] = 0.;
     119    for (j=0;j<nbins; j++)  {
     120      // compute the predicted phase
     121      o->dev1->data[i][j] = 2. * o->theta1->data[i][j] - o->theta2->data[i][j];
     122      // compute the euclidean distance in the complex domain
     123      // sqrt ( r_1^2 + r_2^2 - 2 * r_1 * r_2 * \cos ( \phi_1 - \phi_2 ) )
     124      onset->data[i][0] +=
     125        SQRT (ABS (SQR (o->oldmag->data[i][j]) + SQR (fftgrain->norm[i][j])
     126              - 2. * o->oldmag->data[i][j] * fftgrain->norm[i][j]
     127              * COS (o->dev1->data[i][j] - fftgrain->phas[i][j])));
     128      /* swap old phase data (need to remember 2 frames behind)*/
     129      o->theta2->data[i][j] = o->theta1->data[i][j];
     130      o->theta1->data[i][j] = fftgrain->phas[i][j];
     131      /* swap old magnitude data (1 frame is enough) */
     132      o->oldmag->data[i][j] = fftgrain->norm[i][j];
     133    }
    128134  }
    129135}
     
    133139void aubio_specdesc_phase(aubio_specdesc_t *o,
    134140    cvec_t * fftgrain, fvec_t * onset){
    135   uint_t j;
     141  uint_t i, j;
    136142  uint_t nbins = fftgrain->length;
    137   onset->data[0] = 0.0;
    138   o->dev1->data[0]=0.;
    139   for ( j=0;j<nbins; j++ )  {
    140     o->dev1->data[j] =
    141       aubio_unwrap2pi(
    142           fftgrain->phas[j]
    143           -2.0*o->theta1->data[j]
    144           +o->theta2->data[j]);
    145     if ( o->threshold < fftgrain->norm[j] )
    146       o->dev1->data[j] = ABS(o->dev1->data[j]);
    147     else
    148       o->dev1->data[j] = 0.0;
    149     /* keep a track of the past frames */
    150     o->theta2->data[j] = o->theta1->data[j];
    151     o->theta1->data[j] = fftgrain->phas[j];
    152   }
    153   /* apply o->histogram */
    154   aubio_hist_dyn_notnull(o->histog,o->dev1);
    155   /* weight it */
    156   aubio_hist_weight(o->histog);
    157   /* its mean is the result */
    158   onset->data[0] = aubio_hist_mean(o->histog); 
    159   //onset->data[0] = fvec_mean(o->dev1);
     143  for (i=0;i<fftgrain->channels; i++)  {
     144    onset->data[i][0] = 0.0;
     145    o->dev1->data[i][0]=0.;
     146    for ( j=0;j<nbins; j++ )  {
     147      o->dev1->data[i][j] =
     148        aubio_unwrap2pi(
     149            fftgrain->phas[i][j]
     150            -2.0*o->theta1->data[i][j]
     151            +o->theta2->data[i][j]);
     152      if ( o->threshold < fftgrain->norm[i][j] )
     153        o->dev1->data[i][j] = ABS(o->dev1->data[i][j]);
     154      else
     155        o->dev1->data[i][j] = 0.0;
     156      /* keep a track of the past frames */
     157      o->theta2->data[i][j] = o->theta1->data[i][j];
     158      o->theta1->data[i][j] = fftgrain->phas[i][j];
     159    }
     160    /* apply o->histogram */
     161    aubio_hist_dyn_notnull(o->histog,o->dev1);
     162    /* weight it */
     163    aubio_hist_weight(o->histog);
     164    /* its mean is the result */
     165    onset->data[i][0] = aubio_hist_mean(o->histog); 
     166    //onset->data[i][0] = fvec_mean(o->dev1);
     167  }
    160168}
    161169
     
    163171void aubio_specdesc_specdiff(aubio_specdesc_t *o,
    164172    cvec_t * fftgrain, fvec_t * onset){
    165   uint_t j;
     173  uint_t i, j;
    166174  uint_t nbins = fftgrain->length;
    167     onset->data[0] = 0.0;
     175  for (i=0;i<fftgrain->channels; i++)  {
     176    onset->data[i][0] = 0.0;
    168177    for (j=0;j<nbins; j++)  {
    169       o->dev1->data[j] = SQRT(
    170           ABS(SQR( fftgrain->norm[j])
    171             - SQR(o->oldmag->data[j])));
    172       if (o->threshold < fftgrain->norm[j] )
    173         o->dev1->data[j] = ABS(o->dev1->data[j]);
     178      o->dev1->data[i][j] = SQRT(
     179          ABS(SQR( fftgrain->norm[i][j])
     180            - SQR(o->oldmag->data[i][j])));
     181      if (o->threshold < fftgrain->norm[i][j] )
     182        o->dev1->data[i][j] = ABS(o->dev1->data[i][j]);
    174183      else
    175         o->dev1->data[j] = 0.0;
    176       o->oldmag->data[j] = fftgrain->norm[j];
     184        o->dev1->data[i][j] = 0.0;
     185      o->oldmag->data[i][j] = fftgrain->norm[i][j];
    177186    }
    178187
     
    183192    aubio_hist_weight(o->histog);
    184193    /* its mean is the result */
    185     onset->data[0] = aubio_hist_mean(o->histog); 
     194    onset->data[i][0] = aubio_hist_mean(o->histog); 
     195
     196  }
    186197}
    187198
     
    190201 * negative (1.+) and infinite values (+1.e-10) */
    191202void aubio_specdesc_kl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
    192   uint_t j;
    193     onset->data[0] = 0.;
     203  uint_t i,j;
     204  for (i=0;i<fftgrain->channels;i++) {
     205    onset->data[i][0] = 0.;
    194206    for (j=0;j<fftgrain->length;j++) {
    195       onset->data[0] += fftgrain->norm[j]
    196         *LOG(1.+fftgrain->norm[j]/(o->oldmag->data[j]+1.e-10));
    197       o->oldmag->data[j] = fftgrain->norm[j];
    198     }
    199     if (isnan(onset->data[0])) onset->data[0] = 0.;
     207      onset->data[i][0] += fftgrain->norm[i][j]
     208        *LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
     209      o->oldmag->data[i][j] = fftgrain->norm[i][j];
     210    }
     211    if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
     212  }
    200213}
    201214
     
    204217 * negative (1.+) and infinite values (+1.e-10) */
    205218void aubio_specdesc_mkl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
    206   uint_t j;
    207     onset->data[0] = 0.;
     219  uint_t i,j;
     220  for (i=0;i<fftgrain->channels;i++) {
     221    onset->data[i][0] = 0.;
    208222    for (j=0;j<fftgrain->length;j++) {
    209       onset->data[0] += LOG(1.+fftgrain->norm[j]/(o->oldmag->data[j]+1.e-10));
    210       o->oldmag->data[j] = fftgrain->norm[j];
    211     }
    212     if (isnan(onset->data[0])) onset->data[0] = 0.;
     223      onset->data[i][0] += LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
     224      o->oldmag->data[i][j] = fftgrain->norm[i][j];
     225    }
     226    if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
     227  }
    213228}
    214229
    215230/* Spectral flux */
    216231void aubio_specdesc_specflux(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
    217   uint_t j;
    218   onset->data[0] = 0.;
    219   for (j=0;j<fftgrain->length;j++) {
    220     if (fftgrain->norm[j] > o->oldmag->data[j])
    221       onset->data[0] += fftgrain->norm[j] - o->oldmag->data[j];
    222     o->oldmag->data[j] = fftgrain->norm[j];
     232  uint_t i, j;
     233  for (i=0;i<fftgrain->channels;i++) {
     234    onset->data[i][0] = 0.;
     235    for (j=0;j<fftgrain->length;j++) {
     236      if (fftgrain->norm[i][j] > o->oldmag->data[i][j])
     237        onset->data[i][0] += fftgrain->norm[i][j] - o->oldmag->data[i][j];
     238      o->oldmag->data[i][j] = fftgrain->norm[i][j];
     239    }
    223240  }
    224241}
     
    235252 */
    236253aubio_specdesc_t *
    237 new_aubio_specdesc (char_t * onset_mode, uint_t size){
     254new_aubio_specdesc (char_t * onset_mode,
     255    uint_t size, uint_t channels){
    238256  aubio_specdesc_t * o = AUBIO_NEW(aubio_specdesc_t);
    239257  uint_t rsize = size/2+1;
     
    285303      /* the other approaches will need some more memory spaces */
    286304    case aubio_onset_complex:
    287       o->oldmag = new_fvec(rsize);
    288       o->dev1   = new_fvec(rsize);
    289       o->theta1 = new_fvec(rsize);
    290       o->theta2 = new_fvec(rsize);
     305      o->oldmag = new_fvec(rsize,channels);
     306      o->dev1   = new_fvec(rsize,channels);
     307      o->theta1 = new_fvec(rsize,channels);
     308      o->theta2 = new_fvec(rsize,channels);
    291309      break;
    292310    case aubio_onset_phase:
    293       o->dev1   = new_fvec(rsize);
    294       o->theta1 = new_fvec(rsize);
    295       o->theta2 = new_fvec(rsize);
    296       o->histog = new_aubio_hist(0.0, PI, 10);
     311      o->dev1   = new_fvec(rsize,channels);
     312      o->theta1 = new_fvec(rsize,channels);
     313      o->theta2 = new_fvec(rsize,channels);
     314      o->histog = new_aubio_hist(0.0, PI, 10, channels);
    297315      o->threshold = 0.1;
    298316      break;
    299317    case aubio_onset_specdiff:
    300       o->oldmag = new_fvec(rsize);
    301       o->dev1   = new_fvec(rsize);
    302       o->histog = new_aubio_hist(0.0, PI, 10);
     318      o->oldmag = new_fvec(rsize,channels);
     319      o->dev1   = new_fvec(rsize,channels);
     320      o->histog = new_aubio_hist(0.0, PI, 10, channels);
    303321      o->threshold = 0.1;
    304322      break;
     
    306324    case aubio_onset_mkl:
    307325    case aubio_onset_specflux:
    308       o->oldmag = new_fvec(rsize);
     326      o->oldmag = new_fvec(rsize,channels);
    309327      break;
    310328    default:
  • TabularUnified src/spectral/specdesc.h

    r8212692 rf650860  
    2525  All of the following spectral description functions take as arguments the FFT
    2626  of a windowed signal (as created with aubio_pvoc). They output one smpl_t per
    27   buffer (stored in a vector of size [1]).
     27  buffer and per channel (stored in a vector of size [channels]x[1]).
    2828 
    2929  A list of the spectral description methods currently available follows.
     
    168168  \param method spectral description method
    169169  \param buf_size length of the input spectrum frame
     170  \param channels number of input channels
    170171
    171172*/
    172 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size);
     173aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size,
     174    uint_t channels);
    173175
    174176/** deletion of a spectral descriptor
  • TabularUnified src/spectral/statistics.c

    r8212692 rf650860  
    2424
    2525smpl_t
    26 cvec_sum (cvec_t * s)
     26cvec_sum_channel (cvec_t * s, uint_t i)
    2727{
    2828  uint_t j;
    2929  smpl_t tmp = 0.0;
    30   for (j = 0; j < s->length; j++) {
    31     tmp += s->norm[j];
    32   }
     30  for (j = 0; j < s->length; j++)
     31      tmp += s->norm[i][j];
    3332  return tmp;
    3433}
    3534
    3635smpl_t
    37 cvec_mean (cvec_t * s)
     36cvec_mean_channel (cvec_t * s, uint_t i)
    3837{
    39   return cvec_sum (s) / (smpl_t) (s->length);
     38  return cvec_sum_channel(s, i) / (smpl_t) (s->length);
    4039}
    4140
    4241smpl_t
    43 cvec_centroid (cvec_t * spec)
     42cvec_centroid_channel (cvec_t * spec, uint_t i)
    4443{
    4544  smpl_t sum = 0., sc = 0.;
    4645  uint_t j;
    47   sum = cvec_sum (spec);
     46  sum = cvec_sum_channel (spec, i);
    4847  if (sum == 0.) {
    4948    return 0.;
    5049  } else {
    5150    for (j = 0; j < spec->length; j++) {
    52       sc += (smpl_t) j *spec->norm[j];
     51      sc += (smpl_t) j *spec->norm[i][j];
    5352    }
    5453    return sc / sum;
     
    5756
    5857smpl_t
    59 cvec_moment (cvec_t * spec, uint_t order)
     58cvec_moment_channel (cvec_t * spec, uint_t i, uint_t order)
    6059{
    6160  smpl_t sum = 0., centroid = 0., sc = 0.;
    6261  uint_t j;
    63   sum = cvec_sum (spec);
     62  sum = cvec_sum_channel (spec, i);
    6463  if (sum == 0.) {
    6564    return 0.;
    6665  } else {
    67     centroid = cvec_centroid (spec);
     66    centroid = cvec_centroid_channel (spec, i);
    6867    for (j = 0; j < spec->length; j++) {
    69       sc += (smpl_t) POW(j - centroid, order) * spec->norm[j];
     68      sc += (smpl_t) POW(j - centroid, order) * spec->norm[i][j];
    7069    }
    7170    return sc / sum;
     
    7776    fvec_t * desc)
    7877{
    79   desc->data[0] = cvec_centroid (spec);
     78  uint_t i;
     79  for (i = 0; i < spec->channels; i++) {
     80    desc->data[i][0] = cvec_centroid_channel (spec, i);
     81  }
    8082}
    8183
     
    8486    fvec_t * desc)
    8587{
    86   desc->data[0] = cvec_moment (spec, 2);
     88  uint_t i;
     89  for (i = 0; i < spec->channels; i++) {
     90    desc->data[i][0] = cvec_moment_channel (spec, i, 2);
     91  }
    8792}
    8893
     
    9196    fvec_t * desc)
    9297{
    93   smpl_t spread;
    94   spread = cvec_moment (spec, 2);
    95   if (spread == 0) {
    96     desc->data[0] = 0.;
    97   } else {
    98     desc->data[0] = cvec_moment (spec, 3);
    99     desc->data[0] /= POW ( SQRT (spread), 3);
     98  uint_t i; smpl_t spread;
     99  for (i = 0; i < spec->channels; i++) {
     100    spread = cvec_moment_channel (spec, i, 2);
     101    if (spread == 0) {
     102      desc->data[i][0] = 0.;
     103    } else {
     104      desc->data[i][0] = cvec_moment_channel (spec, i, 3);
     105      desc->data[i][0] /= POW ( SQRT (spread), 3);
     106    }
    100107  }
    101108}
     
    105112    fvec_t * desc)
    106113{
    107   smpl_t spread;
    108   spread = cvec_moment (spec, 2);
    109   if (spread == 0) {
    110     desc->data[0] = 0.;
    111   } else {
    112     desc->data[0] = cvec_moment (spec, 4);
    113     desc->data[0] /= SQR (spread);
     114  uint_t i; smpl_t spread;
     115  for (i = 0; i < spec->channels; i++) {
     116    spread = cvec_moment_channel (spec, i, 2);
     117    if (spread == 0) {
     118      desc->data[i][0] = 0.;
     119    } else {
     120      desc->data[i][0] = cvec_moment_channel (spec, i, 4);
     121      desc->data[i][0] /= SQR (spread);
     122    }
    114123  }
    115124}
     
    119128    fvec_t * desc)
    120129{
    121   uint_t j;
     130  uint_t i, j;
    122131  smpl_t norm = 0, sum = 0.;
    123132  // compute N * sum(j**2) - sum(j)**2
     
    128137  // sum_0^N(j) = length * (length + 1) / 2
    129138  norm -= SQR( (spec->length) * (spec->length - 1.) / 2. );
    130   sum = cvec_sum (spec);
    131   desc->data[0] = 0.;
    132   if (sum == 0.) {
    133     return;
    134   } else {
    135     for (j = 0; j < spec->length; j++) {
    136       desc->data[0] += j * spec->norm[j];
     139  for (i = 0; i < spec->channels; i++) {
     140    sum = cvec_sum_channel (spec, i);
     141    desc->data[i][0] = 0.;
     142    if (sum == 0.) {
     143      break;
     144    } else {
     145      for (j = 0; j < spec->length; j++) {
     146        desc->data[i][0] += j * spec->norm[i][j];
     147      }
     148      desc->data[i][0] *= spec->length;
     149      desc->data[i][0] -= sum * spec->length * (spec->length - 1) / 2.;
     150      desc->data[i][0] /= norm;
     151      desc->data[i][0] /= sum;
    137152    }
    138     desc->data[0] *= spec->length;
    139     desc->data[0] -= sum * spec->length * (spec->length - 1) / 2.;
    140     desc->data[0] /= norm;
    141     desc->data[0] /= sum;
    142153  }
    143154}
     
    147158    fvec_t * desc)
    148159{
    149   uint_t j; smpl_t sum;
    150   sum = cvec_sum (spec);
    151   desc->data[0] = 0;
    152   if (sum == 0.) {
    153     return;
    154   } else {
    155     sum -= spec->norm[0];
    156     for (j = 1; j < spec->length; j++) {
    157       desc->data[0] += (spec->norm[j] - spec->norm[0]) / j;
     160  uint_t i, j; smpl_t sum;
     161  for (i = 0; i < spec->channels; i++) {
     162    sum = cvec_sum_channel (spec, i);
     163    desc->data[i][0] = 0;
     164    if (sum == 0.) {
     165      break;
     166    } else {
     167      sum -= spec->norm[i][0];
     168      for (j = 1; j < spec->length; j++) {
     169        desc->data[i][0] += (spec->norm[i][j] - spec->norm[i][0]) / j;
     170      }
     171      desc->data[i][0] /= sum;
    158172    }
    159     desc->data[0] /= sum;
    160173  }
    161174}
     
    165178    fvec_t *desc)
    166179{
    167   uint_t j; smpl_t cumsum, rollsum;
    168   cumsum = 0.; rollsum = 0.;
    169   for (j = 0; j < spec->length; j++) {
    170     cumsum += SQR (spec->norm[j]);
    171   }
    172   if (cumsum == 0) {
    173     desc->data[0] = 0.;
    174   } else {
    175     cumsum *= 0.95;
    176     j = 0;
    177     while (rollsum < cumsum) {
    178       rollsum += SQR (spec->norm[j]);
    179       j++;
     180  uint_t i, j; smpl_t cumsum, rollsum;
     181  for (i = 0; i < spec->channels; i++) {
     182    cumsum = 0.; rollsum = 0.;
     183    for (j = 0; j < spec->length; j++) {
     184      cumsum += SQR (spec->norm[i][j]);
    180185    }
    181     desc->data[0] = j;
     186    if (cumsum == 0) {
     187      desc->data[i][0] = 0.;
     188    } else {
     189      cumsum *= 0.95;
     190      j = 0;
     191      while (rollsum < cumsum) {
     192        rollsum += SQR (spec->norm[i][j]);
     193        j++;
     194      }
     195      desc->data[i][0] = j;
     196    }
    182197  }
    183198}
  • TabularUnified src/spectral/tss.c

    r8212692 rf650860  
    4444    cvec_t * trans, cvec_t * stead)
    4545{
    46   uint_t j;
     46  uint_t i,j;
    4747  uint_t test;
    4848  uint_t nbins     = input->length;
     49  uint_t channels  = input->channels;
    4950  smpl_t alpha     = o->alpha;
    5051  smpl_t beta      = o->beta;
    5152  smpl_t parm      = o->parm;
    52   smpl_t * dev    = (smpl_t *)o->dev->data;
    53   smpl_t * oft1   = (smpl_t *)o->oft1->data;
    54   smpl_t * oft2   = (smpl_t *)o->oft2->data;
    55   smpl_t * theta1 = (smpl_t *)o->theta1->data;
    56   smpl_t * theta2 = (smpl_t *)o->theta2->data;
     53  smpl_t ** dev    = (smpl_t **)o->dev->data;
     54  smpl_t ** oft1   = (smpl_t **)o->oft1->data;
     55  smpl_t ** oft2   = (smpl_t **)o->oft2->data;
     56  smpl_t ** theta1 = (smpl_t **)o->theta1->data;
     57  smpl_t ** theta2 = (smpl_t **)o->theta2->data;
    5758  /* second phase derivative */
    58   for (j=0;j<nbins; j++){
    59     dev[j] = aubio_unwrap2pi(input->phas[j]
    60         -2.0*theta1[j]+theta2[j]);
    61     theta2[j] = theta1[j];
    62     theta1[j] = input->phas[j];
    63   }
     59  for (i=0;i<channels; i++){
     60    for (j=0;j<nbins; j++){
     61      dev[i][j] = aubio_unwrap2pi(input->phas[i][j]
     62          -2.0*theta1[i][j]+theta2[i][j]);
     63      theta2[i][j] = theta1[i][j];
     64      theta1[i][j] = input->phas[i][j];
     65    }
    6466
    65   for (j=0;j<nbins; j++){
    66     /* transient analysis */
    67     test = (ABS(dev[j]) > parm*oft1[j]);
    68     trans->norm[j] = input->norm[j] * test;
    69     trans->phas[j] = input->phas[j] * test;
    70   }
     67    for (j=0;j<nbins; j++){
     68      /* transient analysis */
     69      test = (ABS(dev[i][j]) > parm*oft1[i][j]);
     70      trans->norm[i][j] = input->norm[i][j] * test;
     71      trans->phas[i][j] = input->phas[i][j] * test;
     72    }
    7173
    72   for (j=0;j<nbins; j++){
    73     /* steady state analysis */
    74     test = (ABS(dev[j]) < parm*oft2[j]);
    75     stead->norm[j] = input->norm[j] * test;
    76     stead->phas[j] = input->phas[j] * test;
     74    for (j=0;j<nbins; j++){
     75      /* steady state analysis */
     76      test = (ABS(dev[i][j]) < parm*oft2[i][j]);
     77      stead->norm[i][j] = input->norm[i][j] * test;
     78      stead->phas[i][j] = input->phas[i][j] * test;
    7779
    78     /*increase sstate probability for sines */
    79     test = (trans->norm[j]==0.);
    80     oft1[j]  = test;
    81     test = (stead->norm[j]==0.);
    82     oft2[j]  = test;
    83     test = (trans->norm[j]>0.);
    84     oft1[j] += alpha*test;
    85     test = (stead->norm[j]>0.);
    86     oft2[j] += alpha*test;
    87     test = (oft1[j]>1. && trans->norm[j]>0.);
    88     oft1[j] += beta*test;
    89     test = (oft2[j]>1. && stead->norm[j]>0.);
    90     oft2[j] += beta*test;
     80      /*increase sstate probability for sines */
     81      test = (trans->norm[i][j]==0.);
     82      oft1[i][j]  = test;
     83      test = (stead->norm[i][j]==0.);
     84      oft2[i][j]  = test;
     85      test = (trans->norm[i][j]>0.);
     86      oft1[i][j] += alpha*test;
     87      test = (stead->norm[i][j]>0.);
     88      oft2[i][j] += alpha*test;
     89      test = (oft1[i][j]>1. && trans->norm[i][j]>0.);
     90      oft1[i][j] += beta*test;
     91      test = (oft2[i][j]>1. && stead->norm[i][j]>0.);
     92      oft2[i][j] += beta*test;
     93    }
    9194  }
    9295}
     
    98101}
    99102
    100 aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size)
     103aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size, uint_t channels)
    101104{
    102105  aubio_tss_t * o = AUBIO_NEW(aubio_tss_t);
     
    107110  o->beta = 4.;
    108111  o->parm = o->threshold*o->thrsfact;
    109   o->theta1 = new_fvec(rsize);
    110   o->theta2 = new_fvec(rsize);
    111   o->oft1 = new_fvec(rsize);
    112   o->oft2 = new_fvec(rsize);
    113   o->dev = new_fvec(rsize);
     112  o->theta1 = new_fvec(rsize,channels);
     113  o->theta2 = new_fvec(rsize,channels);
     114  o->oft1 = new_fvec(rsize,channels);
     115  o->oft2 = new_fvec(rsize,channels);
     116  o->dev = new_fvec(rsize,channels);
    114117  return o;
    115118}
  • TabularUnified src/spectral/tss.h

    r8212692 rf650860  
    4949  \param buf_size buffer size
    5050  \param hop_size step size
     51  \param channels number of input channels
    5152
    5253*/
    53 aubio_tss_t *new_aubio_tss (uint_t buf_size, uint_t hop_size);
     54aubio_tss_t *new_aubio_tss (uint_t buf_size, uint_t hop_size, uint_t channels);
    5455
    5556/** delete tss object
  • TabularUnified src/tempo/beattracking.c

    r8212692 rf650860  
    5555
    5656aubio_beattracking_t *
    57 new_aubio_beattracking (uint_t winlen)
     57new_aubio_beattracking (uint_t winlen, uint_t channels)
    5858{
    5959
     
    7979  p->rayparam = rayparam;
    8080  p->step = step;
    81   p->rwv = new_fvec (laglen);
    82   p->gwv = new_fvec (laglen);
    83   p->dfwv = new_fvec (winlen);
    84   p->dfrev = new_fvec (winlen);
    85   p->acf = new_fvec (winlen);
    86   p->acfout = new_fvec (laglen);
    87   p->phwv = new_fvec (2 * laglen);
    88   p->phout = new_fvec (winlen);
     81  p->rwv = new_fvec (laglen, 1);
     82  p->gwv = new_fvec (laglen, 1);
     83  p->dfwv = new_fvec (winlen, 1);
     84  p->dfrev = new_fvec (winlen, channels);
     85  p->acf = new_fvec (winlen, channels);
     86  p->acfout = new_fvec (laglen, channels);
     87  p->phwv = new_fvec (2 * laglen, 1);
     88  p->phout = new_fvec (winlen, channels);
    8989
    9090  p->timesig = 0;
     
    9292  /* exponential weighting, dfwv = 0.5 when i =  43 */
    9393  for (i = 0; i < winlen; i++) {
    94     p->dfwv->data[i] = (EXP ((LOG (2.0) / rayparam) * (i + 1)))
     94    p->dfwv->data[0][i] = (EXP ((LOG (2.0) / rayparam) * (i + 1)))
    9595        / dfwvnorm;
    9696  }
    9797
    9898  for (i = 0; i < (laglen); i++) {
    99     p->rwv->data[i] = ((smpl_t) (i + 1.) / SQR ((smpl_t) rayparam)) *
     99    p->rwv->data[0][i] = ((smpl_t) (i + 1.) / SQR ((smpl_t) rayparam)) *
    100100        EXP ((-SQR ((smpl_t) (i + 1.)) / (2. * SQR ((smpl_t) rayparam))));
    101101  }
     
    161161    for (a = 1; a <= numelem; a++) {
    162162      for (b = (1 - a); b < a; b++) {
    163         bt->acfout->data[i] += bt->acf->data[a * (i + 1) + b - 1]
     163        bt->acfout->data[0][i] += bt->acf->data[0][a * (i + 1) + b - 1]
    164164            * 1. / (2. * a - 1.);
    165165      }
     
    171171  /* find non-zero Rayleigh period */
    172172  maxindex = fvec_max_elem (bt->acfout);
    173   bt->rp = maxindex ? fvec_quadint (bt->acfout, maxindex) : 1;
     173  bt->rp = maxindex ? fvec_quadint (bt->acfout, maxindex, 0) : 1;
    174174  //rp = (maxindex==127) ? 43 : maxindex; //rayparam
    175175  bt->rp = (maxindex == bt->acfout->length - 1) ? bt->rayparam : maxindex;      //rayparam
     
    191191  for (i = 0; i < bp; i++) {
    192192    for (k = 0; k < kmax; k++) {
    193       bt->phout->data[i] += bt->dfrev->data[i + (uint_t) ROUND (bp * k)];
     193      bt->phout->data[0][i] += bt->dfrev->data[0][i + (uint_t) ROUND (bp * k)];
    194194    }
    195195  }
     
    204204    phase = step - bt->lastbeat;
    205205  } else {
    206     phase = fvec_quadint (bt->phout, maxindex);
     206    phase = fvec_quadint (bt->phout, maxindex, 0);
    207207  }
    208208  /* take back one frame delay */
     
    237237  if (beat >= 0) {
    238238    //AUBIO_DBG ("beat: %d, %f, %f\n", i, bp, beat);
    239     output->data[i] = beat;
     239    output->data[0][i] = beat;
    240240    i++;
    241241  }
     
    244244    beat += bp;
    245245    //AUBIO_DBG ("beat: %d, %f, %f\n", i, bp, beat);
    246     output->data[i] = beat;
     246    output->data[0][i] = beat;
    247247    i++;
    248248  }
     
    250250  bt->lastbeat = beat;
    251251  /* store the number of beats in this frame as the first element */
    252   output->data[0] = i;
     252  output->data[0][0] = i;
    253253}
    254254
     
    260260  if (acflen > 6 * gp + 2) {
    261261    for (k = -2; k < 2; k++) {
    262       three_energy += acf->data[3 * gp + k];
    263       four_energy += acf->data[4 * gp + k];
     262      three_energy += acf->data[0][3 * gp + k];
     263      four_energy += acf->data[0][4 * gp + k];
    264264    }
    265265  } else {
    266266    /*Expanded to be more accurate in time sig estimation */
    267267    for (k = -2; k < 2; k++) {
    268       three_energy += acf->data[3 * gp + k] + acf->data[6 * gp + k];
    269       four_energy += acf->data[4 * gp + k] + acf->data[2 * gp + k];
     268      three_energy += acf->data[0][3 * gp + k] + acf->data[0][6 * gp + k];
     269      four_energy += acf->data[0][4 * gp + k] + acf->data[0][2 * gp + k];
    270270    }
    271271  }
     
    301301      for (a = 1; a <= bt->timesig; a++) {
    302302        for (b = (1 - a); b < a; b++) {
    303           acfout->data[i] += acf->data[a * (i + 1) + b - 1];
     303          acfout->data[0][i] += acf->data[0][a * (i + 1) + b - 1];
    304304        }
    305305      }
    306306    }
    307307    fvec_weight (acfout, bt->gwv);
    308     gp = fvec_quadint (acfout, fvec_max_elem (acfout));
     308    gp = fvec_quadint (acfout, fvec_max_elem (acfout), 0);
    309309    /*
    310310       while(gp<32) gp =gp*2;
     
    351351    bt->timesig = fvec_gettimesig (acf, acflen, gp);
    352352    for (j = 0; j < laglen; j++)
    353       bt->gwv->data[j] =
     353      bt->gwv->data[0][j] =
    354354          EXP (-.5 * SQR ((smpl_t) (j + 1. - gp)) / SQR (bt->g_var));
    355355    flagconst = 0;
     
    363363    if (step > bt->lastbeat) {
    364364      for (j = 0; j < 2 * laglen; j++) {
    365         bt->phwv->data[j] =
     365        bt->phwv->data[0][j] =
    366366            EXP (-.5 * SQR ((smpl_t) (1. + j - step +
    367367                    bt->lastbeat)) / (bp / 8.));
     
    410410{
    411411  if (bt->timesig != 0 && bt->counter == 0 && bt->flagstep == 0) {
    412     return 5168. / fvec_quadint (bt->acfout, bt->bp);
     412    return 5168. / fvec_quadint (bt->acfout, bt->bp, 0);
    413413  } else {
    414414    return 0.;
  • TabularUnified src/tempo/beattracking.h

    r8212692 rf650860  
    4848
    4949  \param hop_size number of onset detection samples [512]
     50  \param channels number (not functionnal) [1]
    5051
    5152*/
    52 aubio_beattracking_t * new_aubio_beattracking(uint_t hop_size);
     53aubio_beattracking_t * new_aubio_beattracking(uint_t hop_size, uint_t channels);
    5354
    5455/** track the beat
  • TabularUnified src/tempo/tempo.c

    r8212692 rf650860  
    5959  /*if (usedoubled) {
    6060    aubio_specdesc_do(o2,fftgrain, onset2);
    61     onset->data[0] *= onset2->data[0];
     61    onset->data[0][0] *= onset2->data[0][0];
    6262  }*/
    6363  /* execute every overlap_size*step */
     
    6767    /* rotate dfframe */
    6868    for (i = 0 ; i < winlen - step; i++ )
    69       o->dfframe->data[i] = o->dfframe->data[i+step];
     69      o->dfframe->data[0][i] = o->dfframe->data[0][i+step];
    7070    for (i = winlen - step ; i < winlen; i++ )
    71       o->dfframe->data[i] = 0.;
     71      o->dfframe->data[0][i] = 0.;
    7272    o->blockpos = -1;
    7373  }
    7474  o->blockpos++;
    7575  aubio_peakpicker_do (o->pp, o->of, o->onset);
    76   tempo->data[1] = o->onset->data[0];
     76  tempo->data[0][1] = o->onset->data[0][0];
    7777  thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
    78   o->dfframe->data[winlen - step + o->blockpos] = thresholded->data[0];
     78  o->dfframe->data[0][winlen - step + o->blockpos] = thresholded->data[0][0];
    7979  /* end of second level loop */
    80   tempo->data[0] = 0; /* reset tactus */
     80  tempo->data[0][0] = 0; /* reset tactus */
    8181  i=0;
    82   for (i = 1; i < o->out->data[0]; i++ ) {
     82  for (i = 1; i < o->out->data[0][0]; i++ ) {
    8383    /* if current frame is a predicted tactus */
    84     if (o->blockpos == FLOOR(o->out->data[i])) {
    85       tempo->data[0] = o->out->data[i] - FLOOR(o->out->data[i]); /* set tactus */
     84    if (o->blockpos == FLOOR(o->out->data[0][i])) {
     85      tempo->data[0][0] = o->out->data[0][i] - FLOOR(o->out->data[0][i]); /* set tactus */
    8686      /* test for silence */
    8787      if (aubio_silence_detection(input, o->silence)==1) {
    88         tempo->data[1] = 0; /* unset onset */
     88        tempo->data[0][1] = 0; /* unset onset */
    8989      }
    9090    }
     
    105105/* Allocate memory for an tempo detection */
    106106aubio_tempo_t * new_aubio_tempo (char_t * onset_mode,
    107     uint_t buf_size, uint_t hop_size, uint_t samplerate)
     107    uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate)
    108108{
    109109  aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t);
     
    115115  o->silence = -90.;
    116116  o->blockpos = 0;
    117   o->dfframe  = new_fvec(o->winlen);
    118   o->fftgrain = new_cvec(buf_size);
    119   o->out      = new_fvec(o->step);
    120   o->pv       = new_aubio_pvoc(buf_size, hop_size);
    121   o->pp       = new_aubio_peakpicker();
     117  o->dfframe  = new_fvec(o->winlen,channels);
     118  o->fftgrain = new_cvec(buf_size, channels);
     119  o->out      = new_fvec(o->step,channels);
     120  o->pv       = new_aubio_pvoc(buf_size, hop_size, channels);
     121  o->pp       = new_aubio_peakpicker(channels);
    122122  aubio_peakpicker_set_threshold (o->pp, o->threshold);
    123   o->od       = new_aubio_specdesc(onset_mode,buf_size);
    124   o->of       = new_fvec(1);
    125   o->bt       = new_aubio_beattracking(o->winlen);
    126   o->onset    = new_fvec(1);
     123  o->od       = new_aubio_specdesc(onset_mode,buf_size,channels);
     124  o->of       = new_fvec(1, channels);
     125  o->bt       = new_aubio_beattracking(o->winlen,channels);
     126  o->onset    = new_fvec(1, channels);
    127127  /*if (usedoubled)    {
    128     o2 = new_aubio_specdesc(type_onset2,buffer_size);
    129     onset2 = new_fvec(1);
     128    o2 = new_aubio_specdesc(type_onset2,buffer_size,channels);
     129    onset2 = new_fvec(1 , channels);
    130130  }*/
    131131  return o;
  • TabularUnified src/tempo/tempo.h

    r8212692 rf650860  
    4040/** create tempo detection object */
    4141aubio_tempo_t * new_aubio_tempo (char_t * method,
    42     uint_t buf_size, uint_t hop_size, uint_t samplerate);
     42    uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate);
    4343
    4444/** execute tempo detection */
  • TabularUnified src/temporal/a_weighting.c

    r8212692 rf650860  
    3232  lvec_t *bs = aubio_filter_get_feedforward (f);
    3333  lvec_t *as = aubio_filter_get_feedback (f);
    34   lsmp_t *b = bs->data, *a = as->data;
     34  lsmp_t *b = bs->data[0], *a = as->data[0];
    3535  uint_t order = aubio_filter_get_order (f);
    3636
     
    241241
    242242aubio_filter_t *
    243 new_aubio_filter_a_weighting (uint_t samplerate)
     243new_aubio_filter_a_weighting (uint_t channels, uint_t samplerate)
    244244{
    245   aubio_filter_t *f = new_aubio_filter (7);
     245  aubio_filter_t *f = new_aubio_filter (7, channels);
    246246  aubio_filter_set_a_weighting (f, samplerate);
    247247  return f;
  • TabularUnified src/temporal/a_weighting.h

    r8212692 rf650860  
    6161/** create new A-design filter
    6262
     63  \param channels number of channels to allocate
    6364  \param samplerate sampling frequency of the signal to filter. Should be one of
    6465  8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, and
     
    6869
    6970*/
    70 aubio_filter_t *new_aubio_filter_a_weighting (uint_t samplerate);
     71aubio_filter_t *new_aubio_filter_a_weighting (uint_t channels,
     72    uint_t samplerate);
    7173
    7274/** set feedback and feedforward coefficients of a A-weighting filter
  • TabularUnified src/temporal/biquad.c

    r8212692 rf650860  
    3636    return AUBIO_FAIL;
    3737  }
    38   bs->data[0] = b0;
    39   bs->data[1] = b1;
    40   bs->data[2] = b2;
    41   as->data[0] = 1.;
    42   as->data[1] = a1;
    43   as->data[1] = a2;
     38  bs->data[0][0] = b0;
     39  bs->data[0][1] = b1;
     40  bs->data[0][2] = b2;
     41  as->data[0][0] = 1.;
     42  as->data[0][1] = a1;
     43  as->data[0][1] = a2;
    4444  return AUBIO_OK;
    4545}
    4646
    4747aubio_filter_t *
    48 new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2, lsmp_t a1, lsmp_t a2)
     48new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2, lsmp_t a1, lsmp_t a2,
     49    uint_t channels)
    4950{
    50   aubio_filter_t *f = new_aubio_filter (3);
     51  aubio_filter_t *f = new_aubio_filter (3, channels);
    5152  aubio_filter_set_biquad (f, b0, b1, b2, a1, a2);
    5253  return f;
  • TabularUnified src/temporal/biquad.h

    r8212692 rf650860  
    6262  \param a1 feedback filter coefficient
    6363  \param a2 feedback filter coefficient
     64  \param channels number of channels to allocate
    6465
    6566*/
    6667aubio_filter_t *new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2,
    67     lsmp_t a1, lsmp_t a2);
     68    lsmp_t a1, lsmp_t a2, uint_t channels);
    6869
    6970#ifdef __cplusplus
  • TabularUnified src/temporal/c_weighting.c

    r8212692 rf650860  
    3232  lvec_t *bs = aubio_filter_get_feedforward (f);
    3333  lvec_t *as = aubio_filter_get_feedback (f);
    34   lsmp_t *b = bs->data, *a = as->data;
     34  lsmp_t *b = bs->data[0], *a = as->data[0];
    3535  uint_t order = aubio_filter_get_order (f);
    3636
     
    197197}
    198198
    199 aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate) {
    200   aubio_filter_t * f = new_aubio_filter(5);
     199aubio_filter_t * new_aubio_filter_c_weighting (uint_t channels, uint_t samplerate) {
     200  aubio_filter_t * f = new_aubio_filter(5, channels);
    201201  aubio_filter_set_c_weighting (f, samplerate);
    202202  return f;
  • TabularUnified src/temporal/c_weighting.h

    r8212692 rf650860  
    6161/** create new C-design filter
    6262
     63  \param channels number of channels to allocate
    6364  \param samplerate sampling frequency of the signal to filter. Should be one of
    6465  8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, and
     
    6869
    6970*/
    70 aubio_filter_t *new_aubio_filter_c_weighting (uint_t samplerate);
     71aubio_filter_t *new_aubio_filter_c_weighting (uint_t channels,
     72    uint_t samplerate);
    7173
    7274/** set feedback and feedforward coefficients of a C-weighting filter
  • TabularUnified src/temporal/filter.c

    r8212692 rf650860  
    4949aubio_filter_do (aubio_filter_t * f, fvec_t * in)
    5050{
    51   uint_t j, l, order = f->order;
    52   lsmp_t *x = f->x->data;
    53   lsmp_t *y = f->y->data;
    54   lsmp_t *a = f->a->data;
    55   lsmp_t *b = f->b->data;
     51  uint_t i, j, l, order = f->order;
     52  lsmp_t *x;
     53  lsmp_t *y;
     54  lsmp_t *a = f->a->data[0];
     55  lsmp_t *b = f->b->data[0];
    5656
    57   for (j = 0; j < in->length; j++) {
    58     /* new input */
    59     x[0] = KILL_DENORMAL (in->data[j]);
    60     y[0] = b[0] * x[0];
    61     for (l = 1; l < order; l++) {
    62       y[0] += b[l] * x[l];
    63       y[0] -= a[l] * y[l];
     57  for (i = 0; i < in->channels; i++) {
     58    x = f->x->data[i];
     59    y = f->y->data[i];
     60    for (j = 0; j < in->length; j++) {
     61      /* new input */
     62      x[0] = KILL_DENORMAL (in->data[i][j]);
     63      y[0] = b[0] * x[0];
     64      for (l = 1; l < order; l++) {
     65        y[0] += b[l] * x[l];
     66        y[0] -= a[l] * y[l];
     67      }
     68      /* new output */
     69      in->data[i][j] = y[0];
     70      /* store for next sample */
     71      for (l = order - 1; l > 0; l--) {
     72        x[l] = x[l - 1];
     73        y[l] = y[l - 1];
     74      }
    6475    }
    65     /* new output */
    66     in->data[j] = y[0];
    67     /* store for next sample */
    68     for (l = order - 1; l > 0; l--) {
    69       x[l] = x[l - 1];
    70       y[l] = y[l - 1];
    71     }
     76    /* store for next run */
     77    f->x->data[i] = x;
     78    f->y->data[i] = y;
    7279  }
    7380}
     
    7784aubio_filter_do_filtfilt (aubio_filter_t * f, fvec_t * in, fvec_t * tmp)
    7885{
    79   uint_t j;
     86  uint_t j, i = 0;
    8087  uint_t length = in->length;
    8188  /* apply filtering */
     
    8491  /* mirror */
    8592  for (j = 0; j < length; j++)
    86     tmp->data[length - j - 1] = in->data[j];
     93    tmp->data[i][length - j - 1] = in->data[i][j];
    8794  /* apply filtering on mirrored */
    8895  aubio_filter_do (f, tmp);
     
    9097  /* invert back */
    9198  for (j = 0; j < length; j++)
    92     in->data[j] = tmp->data[length - j - 1];
     99    in->data[i][j] = tmp->data[i][length - j - 1];
    93100}
    94101
     
    132139
    133140aubio_filter_t *
    134 new_aubio_filter (uint_t order)
     141new_aubio_filter (uint_t order, uint_t channels)
    135142{
    136143  aubio_filter_t *f = AUBIO_NEW (aubio_filter_t);
    137   f->x = new_lvec (order);
    138   f->y = new_lvec (order);
    139   f->a = new_lvec (order);
    140   f->b = new_lvec (order);
     144  f->x = new_lvec (order, channels);
     145  f->y = new_lvec (order, channels);
     146  f->a = new_lvec (order, 1);
     147  f->b = new_lvec (order, 1);
    141148  /* by default, samplerate is not set */
    142149  f->samplerate = 0;
    143150  f->order = order;
    144151  /* set default to identity */
    145   f->a->data[1] = 1.;
     152  f->a->data[0][1] = 1.;
    146153  return f;
    147154}
  • TabularUnified src/temporal/filter.h

    r8212692 rf650860  
    2626  Digital filter
    2727
    28   This object stores a digital filter of order \f$n\f$.
     28  This object stores a digital filter of order \f$n\f$ for \f$c\f$ channels.
    2929  It contains the following data:
    3030    - \f$ n*1 b_i \f$ feedforward coefficients
     
    151151/** create new filter object
    152152
    153   This function creates a new ::aubio_filter_t object, given the order of the
    154   filter.
     153  This function creates a new ::aubio_filter_t object, given an order
     154  and a specific number of channels.
    155155
    156156  \param order order of the filter (number of coefficients)
     157  \param channels number of channels to allocate
    157158
    158159  \return the newly created filter object
    159160
    160161*/
    161 aubio_filter_t *new_aubio_filter (uint_t order);
     162aubio_filter_t *new_aubio_filter (uint_t order, uint_t channels);
    162163
    163164/** delete a filter object
  • TabularUnified src/temporal/resampler.c

    r8212692 rf650860  
    6161aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output)
    6262{
     63  uint_t i;
    6364  s->proc->input_frames = input->length;
    6465  s->proc->output_frames = output->length;
    6566  s->proc->src_ratio = (double) s->ratio;
    66   /* make SRC_PROC data point to input outputs */
    67   s->proc->data_in = (float *) input->data;
    68   s->proc->data_out = (float *) output->data;
    69   /* do resampling */
    70   src_process (s->stat, s->proc);
     67  for (i = 0; i < input->channels; i++) {
     68    /* make SRC_PROC data point to input outputs */
     69    s->proc->data_in = (float *) input->data[i];
     70    s->proc->data_out = (float *) output->data[i];
     71    /* do resampling */
     72    src_process (s->stat, s->proc);
     73  }
    7174}
    7275
     
    8487
    8588void
    86 del_aubio_resampler (aubio_resampler_t * s UNUSED)
     89del_aubio_resampler (aubio_resampler_t * s)
    8790{
    8891}
    8992
    9093void
    91 aubio_resampler_do (aubio_resampler_t * s UNUSED, fvec_t * input UNUSED, fvec_t * output UNUSED)
     94aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output)
    9295{
    9396}
  • TabularUnified src/utils/hist.c

    r8212692 rf650860  
    3232  fvec_t * hist;
    3333  uint_t nelems;
     34  uint_t channels;
    3435  fvec_t * cent;
    3536  aubio_scale_t *scaler;
     
    3940 * Object creation/deletion calls
    4041 */
    41 aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems){
     42aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems, uint_t channels){
    4243  aubio_hist_t * s = AUBIO_NEW(aubio_hist_t);
    4344  smpl_t step = (ihig-ilow)/(smpl_t)(nelems);
    4445  smpl_t accum = step;
    4546  uint_t i;
     47  s->channels = channels;
    4648  s->nelems = nelems;
    47   s->hist = new_fvec(nelems);
    48   s->cent = new_fvec(nelems);
     49  s->hist = new_fvec(nelems, channels);
     50  s->cent = new_fvec(nelems, 1);
    4951
    5052  /* use scale to map ilow/ihig -> 0/nelems */
    5153  s->scaler = new_aubio_scale(ilow,ihig,0,nelems);
    5254  /* calculate centers now once */
    53   s->cent->data[0] = ilow + 0.5 * step;
     55  s->cent->data[0][0] = ilow + 0.5 * step;
    5456  for (i=1; i < s->nelems; i++, accum+=step )
    55     s->cent->data[i] = s->cent->data[0] + accum;
     57    s->cent->data[0][i] = s->cent->data[0][0] + accum;
    5658
    5759  return s;
     
    6971 */
    7072void aubio_hist_do (aubio_hist_t *s, fvec_t *input) {
    71   uint_t j;
     73  uint_t i,j;
    7274  sint_t tmp = 0;
    7375  aubio_scale_do(s->scaler, input);
    7476  /* reset data */
    75   fvec_zeros(s->hist);
     77  for (i=0; i < s->channels; i++)
     78    for (j=0; j < s->nelems; j++)
     79      s->hist->data[i][j] = 0;
    7680  /* run accum */
    77   for (j=0;  j < input->length; j++)
    78   {
    79     tmp = (sint_t)FLOOR(input->data[j]);
    80     if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) {
    81       s->hist->data[tmp] += 1;
     81  for (i=0; i < input->channels; i++)
     82    for (j=0;  j < input->length; j++)
     83    {
     84      tmp = (sint_t)FLOOR(input->data[i][j]);
     85      if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
     86        s->hist->data[i][tmp] += 1;
    8287    }
    83   }
    8488}
    8589
    8690void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input) {
    87   uint_t j;
     91  uint_t i,j;
    8892  sint_t tmp = 0;
    8993  aubio_scale_do(s->scaler, input);
    9094  /* reset data */
    91   fvec_zeros(s->hist);
     95  for (i=0; i < s->channels; i++)
     96    for (j=0; j < s->nelems; j++)
     97      s->hist->data[i][j] = 0;
    9298  /* run accum */
    93   for (j=0;  j < input->length; j++) {
    94     if (input->data[j] != 0) {
    95       tmp = (sint_t)FLOOR(input->data[j]);
    96       if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
    97         s->hist->data[tmp] += 1;
     99  for (i=0; i < input->channels; i++)
     100    for (j=0;  j < input->length; j++) {
     101      if (input->data[i][j] != 0) {
     102        tmp = (sint_t)FLOOR(input->data[i][j]);
     103        if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
     104          s->hist->data[i][tmp] += 1;
     105      }
    98106    }
    99   }
    100107}
    101108
    102109
    103110void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input) {
    104   uint_t i;
     111  uint_t i,j;
    105112  sint_t tmp = 0;
    106113  smpl_t ilow = fvec_min(input);
     
    112119
    113120  /* recalculate centers */
    114   s->cent->data[0] = ilow + 0.5f * step;
     121  s->cent->data[0][0] = ilow + 0.5f * step;
    115122  for (i=1; i < s->nelems; i++)
    116     s->cent->data[i] = s->cent->data[0] + i * step;
     123    s->cent->data[0][i] = s->cent->data[0][0] + i * step;
    117124
    118125  /* scale */
     
    120127
    121128  /* reset data */
    122   fvec_zeros(s->hist);
     129  for (i=0; i < s->channels; i++)
     130    for (j=0; j < s->nelems; j++)
     131      s->hist->data[i][j] = 0;
    123132  /* run accum */
    124   for (i=0;  i < input->length; i++) {
    125     if (input->data[i] != 0) {
    126       tmp = (sint_t)FLOOR(input->data[i]);
    127       if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
    128         s->hist->data[tmp] += 1;
     133  for (i=0; i < input->channels; i++)
     134    for (j=0;  j < input->length; j++) {
     135      if (input->data[i][j] != 0) {
     136        tmp = (sint_t)FLOOR(input->data[i][j]);
     137        if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
     138          s->hist->data[i][tmp] += 1;
     139      }
    129140    }
    130   }
    131141}
    132142
    133143void aubio_hist_weight (aubio_hist_t *s) {
    134   uint_t j;
    135   for (j=0; j < s->nelems; j++) {
    136     s->hist->data[j] *= s->cent->data[j];
    137   }
     144  uint_t i,j;
     145  for (i=0; i < s->channels; i++)
     146    for (j=0; j < s->nelems; j++) {
     147      s->hist->data[i][j] *= s->cent->data[0][j];
     148    }
    138149}
    139150
    140151smpl_t aubio_hist_mean (aubio_hist_t *s) {
    141   uint_t j;
     152  uint_t i,j;
    142153  smpl_t tmp = 0.0;
    143   for (j=0; j < s->nelems; j++)
    144     tmp += s->hist->data[j];
     154  for (i=0; i < s->channels; i++)
     155    for (j=0; j < s->nelems; j++)
     156      tmp += s->hist->data[i][j];
    145157  return tmp/(smpl_t)(s->nelems);
    146158}
  • TabularUnified src/utils/hist.h

    r8212692 rf650860  
    4040 * \param fhig maximum input
    4141 * \param nelems number of histogram columns
     42 * \param channels number of channels
    4243 */
    43 aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems);
     44aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems, uint_t channels);
    4445/** histogram deletion */
    4546void del_aubio_hist(aubio_hist_t *s);
  • TabularUnified src/utils/scale.c

    r8212692 rf650860  
    7070void aubio_scale_do (aubio_scale_t *s, fvec_t *input)
    7171{
    72   uint_t j;
    73   for (j=0;  j < input->length; j++){
    74     input->data[j] -= s->ilow;
    75     input->data[j] *= s->scaler;
    76     input->data[j] += s->olow;
     72  uint_t i, j;
     73  for (i=0; i < input->channels; i++){
     74    for (j=0;  j < input->length; j++){
     75      input->data[i][j] -= s->ilow;
     76      input->data[i][j] *= s->scaler;
     77      input->data[i][j] += s->olow;
     78    }
    7779  }
    7880}
  • TabularUnified src/vecutils.c

    r8212692 rf650860  
    99void TYPE ## _ ## OPNAME (TYPE ## _t *o) \
    1010{ \
    11   uint_t j; \
    12   for (j = 0; j < o->length; j++) { \
    13     o->OBJ[j] = OP (o->OBJ[j]); \
     11  uint_t i,j; \
     12  for (i = 0; i < o->channels; i++) { \
     13    for (j = 0; j < o->length; j++) { \
     14      o->OBJ[i][j] = OP (o->OBJ[i][j]); \
     15    } \
    1416  } \
    1517}
     
    3335void fvec_pow (fvec_t *s, smpl_t power)
    3436{
    35   uint_t j;
    36   for (j = 0; j < s->length; j++) {
    37     s->data[j] = POW(s->data[j], power);
     37  uint_t i,j;
     38  for (i = 0; i < s->channels; i++) {
     39    for (j = 0; j < s->length; j++) {
     40      s->data[i][j] = POW(s->data[i][j], power);
     41    }
    3842  }
    3943}
     
    4145void cvec_pow (cvec_t *s, smpl_t power)
    4246{
    43   uint_t j;
    44   for (j = 0; j < s->length; j++) {
    45     s->norm[j] = POW(s->norm[j], power);
     47  uint_t i,j;
     48  for (i = 0; i < s->channels; i++) {
     49    for (j = 0; j < s->length; j++) {
     50      s->norm[i][j] = POW(s->norm[i][j], power);
     51    }
    4652  }
    4753}
  • TabularUnified swig/aubio.i

    r8212692 rf650860  
    1212
    1313/* fvec */
    14 fvec_t * new_fvec(uint_t length);
     14fvec_t * new_fvec(uint_t length, uint_t channels);
    1515void del_fvec(fvec_t *s);
    16 smpl_t fvec_read_sample(fvec_t *s, uint_t position);
    17 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t position);
    18 smpl_t * fvec_get_data(fvec_t *s);
     16smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position);
     17void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position);
     18smpl_t * fvec_get_channel(fvec_t *s, uint_t channel);
     19void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel);
     20smpl_t ** fvec_get_data(fvec_t *s);
    1921
    2022/* cvec */
    21 cvec_t * new_cvec(uint_t length);
     23cvec_t * new_cvec(uint_t length, uint_t channels);
    2224void del_cvec(cvec_t *s);
    23 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position);
    24 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position);
    25 smpl_t cvec_read_norm(cvec_t *s, uint_t position);
    26 smpl_t cvec_read_phas(cvec_t *s, uint_t position);
    27 smpl_t * cvec_get_norm(cvec_t *s);
    28 smpl_t * cvec_get_phas(cvec_t *s);
     25void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
     26void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
     27smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position);
     28smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position);
     29void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel);
     30void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel);
     31smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel);
     32smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel);
     33smpl_t ** cvec_get_norm(cvec_t *s);
     34smpl_t ** cvec_get_phas(cvec_t *s);
    2935
    3036
    3137/* fft */
    32 aubio_fft_t * new_aubio_fft(uint_t size);
     38aubio_fft_t * new_aubio_fft(uint_t size, uint_t channels);
    3339void del_aubio_fft(aubio_fft_t * s);
    3440void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum);
     
    4450
    4551/* filter */
    46 aubio_filter_t * new_aubio_filter(uint_t order);
     52aubio_filter_t * new_aubio_filter(uint_t order, uint_t channels);
    4753void aubio_filter_do(aubio_filter_t * b, fvec_t * in);
    4854void aubio_filter_do_outplace(aubio_filter_t * b, fvec_t * in, fvec_t * out);
     
    5157
    5258/* a_weighting */
    53 aubio_filter_t * new_aubio_filter_a_weighting (uint_t samplerate);
     59aubio_filter_t * new_aubio_filter_a_weighting (uint_t channels, uint_t samplerate);
    5460uint_t aubio_filter_set_a_weighting (aubio_filter_t * b, uint_t samplerate);
    5561
    5662/* c_weighting */
    57 aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate);
     63aubio_filter_t * new_aubio_filter_c_weighting (uint_t channels, uint_t samplerate);
    5864uint_t aubio_filter_set_c_weighting (aubio_filter_t * b, uint_t samplerate);
    5965
    6066/* biquad */
    61 aubio_filter_t * new_aubio_filter_biquad(lsmp_t b1, lsmp_t b2, lsmp_t b3, lsmp_t a2, lsmp_t a3);
     67aubio_filter_t * new_aubio_filter_biquad(lsmp_t b1, lsmp_t b2, lsmp_t b3, lsmp_t a2, lsmp_t a3, uint_t channels);
    6268uint_t aubio_filter_set_biquad (aubio_filter_t * b, lsmp_t b1, lsmp_t b2, lsmp_t b3, lsmp_t a2, lsmp_t a3);
    6369
     
    8894
    8995/* pvoc */
    90 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s);
     96aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels);
    9197void del_aubio_pvoc(aubio_pvoc_t *pv);
    9298void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t *in, cvec_t * fftgrain);
     
    95101/* pitch detection */
    96102aubio_pitch_t *new_aubio_pitch (char *pitch_mode,
    97     uint_t bufsize, uint_t hopsize, uint_t samplerate);
     103    uint_t bufsize, uint_t hopsize, uint_t channels, uint_t samplerate);
    98104void aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    99105uint_t aubio_pitch_set_tolerance(aubio_pitch_t *p, smpl_t thres);
     
    103109/* tempo */
    104110aubio_tempo_t * new_aubio_tempo (char_t * mode,
    105     uint_t buf_size, uint_t hop_size, uint_t samplerate);
     111    uint_t buf_size, uint_t hop_size, uint_t channels, uint_t samplerate);
    106112void aubio_tempo_do (aubio_tempo_t *o, fvec_t * input, fvec_t * tempo);
    107113uint_t aubio_tempo_set_silence(aubio_tempo_t * o, smpl_t silence);
     
    114120void aubio_specdesc_do (aubio_specdesc_t * o, cvec_t * fftgrain,
    115121  fvec_t * desc);
    116 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size);
     122aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size,
     123  uint_t channels);
    117124void del_aubio_specdesc (aubio_specdesc_t * o);
    118125
    119126/* peak picker */
    120 aubio_peakpicker_t * new_aubio_peakpicker();
     127aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels);
    121128void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out);
    122129fvec_t * aubio_peakpicker_get_thresholded_input(aubio_peakpicker_t * p);
     
    133140aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * existingfile, const char * outputname);
    134141void aubio_sndfile_info(aubio_sndfile_t * file);
    135 int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t ** write);
    136 int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t ** read);
     142int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t * write);
     143int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t * read);
    137144int del_aubio_sndfile(aubio_sndfile_t * file);
    138145uint_t aubio_sndfile_channels(aubio_sndfile_t * file);
  • TabularUnified tests/src/temporal/test-aweighting.c

    r8212692 rf650860  
    88  uint_t nrates = 6;
    99  uint_t samplerate, i = 0;
     10  uint_t channels = 2;
    1011
    1112  for ( samplerate = rates[i]; i < nrates ; i++ ) {
    12     f = new_aubio_filter_a_weighting (samplerate);
     13    f = new_aubio_filter_a_weighting (channels, samplerate);
    1314    del_aubio_filter (f);
    1415
    15     f = new_aubio_filter (7);
     16    f = new_aubio_filter (7, channels*2);
    1617    aubio_filter_set_a_weighting (f, samplerate);
    1718    del_aubio_filter (f);
     
    1920
    2021  // samplerate unknown
    21   f = new_aubio_filter_a_weighting (4200);
     22  f = new_aubio_filter_a_weighting (channels, 4200);
    2223  del_aubio_filter (f);
    2324
    2425  // order to small
    25   f = new_aubio_filter (2);
     26  f = new_aubio_filter (2, channels*2);
    2627  aubio_filter_set_a_weighting (f, samplerate);
    2728  del_aubio_filter (f);
    2829
    2930  // order to big
    30   f = new_aubio_filter (12);
     31  f = new_aubio_filter (12, channels*2);
    3132  aubio_filter_set_a_weighting (f, samplerate);
    3233  del_aubio_filter (f);
  • TabularUnified tests/src/temporal/test-cweighting.c

    r8212692 rf650860  
    88  uint_t nrates = 6;
    99  uint_t samplerate, i = 0;
     10  uint_t channels = 2;
    1011
    1112  for ( samplerate = rates[i]; i < nrates ; i++ ) {
    12     f = new_aubio_filter_c_weighting (samplerate);
     13    f = new_aubio_filter_c_weighting (channels, samplerate);
    1314    del_aubio_filter (f);
    1415
    15     f = new_aubio_filter (5);
     16    f = new_aubio_filter (5, channels*2);
    1617    aubio_filter_set_c_weighting (f, samplerate);
    1718    del_aubio_filter (f);
     
    1920
    2021  // samplerate unknown
    21   f = new_aubio_filter_c_weighting (4200);
     22  f = new_aubio_filter_c_weighting (channels, 4200);
    2223  del_aubio_filter (f);
    2324
    2425  // order to small
    25   f = new_aubio_filter (2);
     26  f = new_aubio_filter (2, channels*2);
    2627  aubio_filter_set_c_weighting (f, samplerate);
    2728  del_aubio_filter (f);
    2829
    2930  // order to big
    30   f = new_aubio_filter (12);
     31  f = new_aubio_filter (12, channels*2);
    3132  aubio_filter_set_c_weighting (f, samplerate);
    3233  del_aubio_filter (f);
  • TabularUnified tests/src/test-beattracking.c

    r8212692 rf650860  
    77        /* allocate some memory */
    88        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 */
     9        uint_t channels   = 1;                          /* number of channel */
     10        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
     11        fvec_t * out      = new_fvec (win_s/4, channels);     /* input buffer */
    1112 
    1213        /* allocate fft and other memory space */
    13         aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s);
     14        aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s, channels);
    1415
    1516        uint_t i = 0;
  • TabularUnified tests/src/test-biquad.c

    r8212692 rf650860  
    44        /* allocate some memory */
    55        uint_t win_s      = 1024;                       /* window size */
    6         fvec_t * in       = new_fvec (win_s); /* input buffer */
    7         aubio_filter_t * o = new_aubio_filter_biquad(0.3,0.2,0.1,0.2,0.3);
     6        uint_t channels   = 1;                          /* number of channel */
     7        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
     8        aubio_filter_t * o = new_aubio_filter_biquad(0.3,0.2,0.1,0.2,0.3, channels);
    89
    910        aubio_filter_do_filtfilt(o,in,in);
  • TabularUnified tests/src/test-cvec.c

    r8212692 rf650860  
    44        /* allocate some memory */
    55        uint_t win_s      = 1024;                       /* window size */
    6         cvec_t * sp       = new_cvec (win_s); /* input buffer */
     6        uint_t channels   = 1;                          /* number of channel */
     7        cvec_t * sp       = new_cvec (win_s, channels); /* input buffer */
    78        del_cvec(sp);
    89
  • TabularUnified tests/src/test-fft.c

    r8212692 rf650860  
    55        /* allocate some memory */
    66        uint_t win_s      = 8;                       /* window size        */
    7         fvec_t * in       = new_fvec (win_s); /* input buffer       */
    8         cvec_t * fftgrain = new_cvec (win_s); /* fft norm and phase */
    9         fvec_t * out      = new_fvec (win_s); /* output buffer      */
    10         in->data[0] = 1;
    11         in->data[1] = 2;
    12         in->data[2] = 3;
    13         in->data[3] = 4;
    14         in->data[4] = 5;
    15         in->data[5] = 6;
    16         in->data[6] = 5;
    17         in->data[7] = 6;
     7        uint_t channels   = 1;                        /* number of channels */
     8        fvec_t * in       = new_fvec (win_s, channels); /* input buffer       */
     9        cvec_t * fftgrain = new_cvec (win_s, channels); /* fft norm and phase */
     10        fvec_t * out      = new_fvec (win_s, channels); /* output buffer      */
     11        in->data[0][0] = 1;
     12        in->data[0][1] = 2;
     13        in->data[0][2] = 3;
     14        in->data[0][3] = 4;
     15        in->data[0][4] = 5;
     16        in->data[0][5] = 6;
     17        in->data[0][6] = 5;
     18        in->data[0][7] = 6;
    1819        /* allocate fft and other memory space */
    19         aubio_fft_t * fft = new_aubio_fft(win_s);
     20        aubio_fft_t * fft = new_aubio_fft(win_s,channels);
    2021        /* fill input with some data */
    2122        fvec_print(in);
  • TabularUnified tests/src/test-filter.c

    r8212692 rf650860  
    66  /* allocate some memory */
    77  uint_t win_s = 32;            /* window size */
    8   fvec_t *in = new_fvec (win_s);      /* input buffer */
    9   fvec_t *out = new_fvec (win_s);     /* input buffer */
     8  uint_t channels = 1;          /* number of channel */
     9  fvec_t *in = new_fvec (win_s, channels);      /* input buffer */
     10  fvec_t *out = new_fvec (win_s, channels);     /* input buffer */
    1011
    1112
    12   aubio_filter_t *o = new_aubio_filter_c_weighting (44100);
    13   in->data[12] = 0.5;
     13  aubio_filter_t *o = new_aubio_filter_c_weighting (channels, 44100);
     14  in->data[0][12] = 0.5;
    1415  fvec_print (in);
    1516  aubio_filter_do (o, in);
     
    1718  del_aubio_filter (o);
    1819
    19   o = new_aubio_filter_c_weighting (44100);
    20   in->data[12] = 0.5;
     20  o = new_aubio_filter_c_weighting (channels, 44100);
     21  in->data[0][12] = 0.5;
    2122  fvec_print (in);
    2223  aubio_filter_do_outplace (o, in, out);
     
    2425  del_aubio_filter (o);
    2526
    26   o = new_aubio_filter_c_weighting (44100);
    27   in->data[12] = 0.5;
     27  o = new_aubio_filter_c_weighting (channels, 44100);
     28  in->data[0][12] = 0.5;
    2829  fvec_print (in);
    2930  aubio_filter_do_filtfilt (o, in, out);
  • TabularUnified tests/src/test-filterbank.c

    r8212692 rf650860  
    99  /* allocate some memory */
    1010  uint_t win_s = 1024;          /* window size */
     11  uint_t channels = 2;          /* number of channel */
    1112  uint_t n_filters = 13;        /* number of filters */
    12   cvec_t *in = new_cvec (win_s);      /* input buffer */
    13   fvec_t *out = new_fvec (win_s);     /* input buffer */
    14   fmat_t *coeffs = NULL;
     13  cvec_t *in = new_cvec (win_s, channels);      /* input buffer */
     14  fvec_t *out = new_fvec (win_s, channels);     /* input buffer */
     15  fvec_t *coeffs = NULL;
    1516
    1617  /* allocate fft and other memory space */
     
    2223  }
    2324
    24   /*
    2525  if (fvec_max (coeffs) != 0.) {
    2626    return -1;
     
    3030    return -1;
    3131  }
    32   */
    3332
    34   fmat_print (coeffs);
     33  fvec_print (coeffs);
    3534
    3635  aubio_filterbank_do (o, in, out);
  • TabularUnified tests/src/test-filterbank_mel.c

    r8212692 rf650860  
    99  /* allocate some memory */
    1010  uint_t win_s = 512;           /* fft size */
     11  uint_t channels = 2;          /* number of channel */
    1112  uint_t n_filters = 40;        /* number of filters */
    12   cvec_t *in = new_cvec (win_s);      /* input buffer */
    13   fvec_t *out = new_fvec (win_s);     /* input buffer */
    14   fmat_t *coeffs = NULL;
     13  cvec_t *in = new_cvec (win_s, channels);      /* input buffer */
     14  fvec_t *out = new_fvec (win_s, channels);     /* input buffer */
     15  fvec_t *coeffs = NULL;
    1516  smpl_t samplerate = 16000.;
    1617
     
    2627  }
    2728
    28   //fmat_print (coeffs);
     29  //fvec_print (coeffs);
    2930
    3031  //fprintf(stderr, "%f\n", fvec_sum(coeffs));
  • TabularUnified tests/src/test-fvec.c

    r8212692 rf650860  
    44        /* allocate some memory */
    55        uint_t win_s      = 1024;                       /* window size */
    6         fvec_t * in       = new_fvec (win_s); /* input buffer */
     6        uint_t channels   = 1;                          /* number of channel */
     7        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
    78        del_fvec(in);
    89
  • TabularUnified tests/src/test-hist.c

    r8212692 rf650860  
    88  uint_t length;
    99  for (length = 1; length < 10; length ++ ) {
    10     aubio_hist_t *o = new_aubio_hist(0, 1, length);
     10    aubio_hist_t *o = new_aubio_hist(0, 1, length, 5);
    1111    fvec_t *t = new_aubio_window("hanning", length);
    1212    aubio_hist_do(o,t);
  • TabularUnified tests/src/test-mfcc.c

    r8212692 rf650860  
    66  /* allocate some memory */
    77  uint_t win_s = 512;           /* fft size */
     8  uint_t channels = 1;          /* number of channel */
    89  uint_t n_filters = 40;        /* number of filters */
    910  uint_t n_coefs = 13;          /* number of coefficients */
    10   cvec_t *in = new_cvec (win_s);      /* input buffer */
    11   fvec_t *out = new_fvec (n_coefs);     /* input buffer */
     11  cvec_t *in = new_cvec (win_s, channels);      /* input buffer */
     12  fvec_t *out = new_fvec (n_coefs, channels);     /* input buffer */
    1213  smpl_t samplerate = 16000.;
    1314
  • TabularUnified tests/src/test-onset.c

    r8212692 rf650860  
    44        /* allocate some memory */
    55        uint_t win_s      = 1024;                       /* window size */
    6         fvec_t * in       = new_fvec (win_s/4); /* input buffer */
    7         fvec_t * out      = new_fvec (2);     /* input buffer */
    8         aubio_onset_t * onset  = new_aubio_onset("complex", win_s, win_s/4, 44100.);
     6        uint_t channels   = 1;                          /* number of channel */
     7        fvec_t * in       = new_fvec (win_s/4, channels); /* input buffer */
     8        fvec_t * out      = new_fvec (2, channels);     /* input buffer */
     9        aubio_onset_t * onset  = new_aubio_onset("complex", win_s, win_s/4, channels, 44100.);
    910        uint_t i = 0;
    1011
  • TabularUnified tests/src/test-onsetdetection.c

    r8212692 rf650860  
    88{
    99  uint_t win_s = 1024;          /* window size */
    10   cvec_t *in = new_cvec (win_s);      /* input buffer */
    11   fvec_t *out = new_fvec (1); /* input buffer */
     10  uint_t channels = 1;          /* number of channel */
     11  cvec_t *in = new_cvec (win_s, channels);      /* input buffer */
     12  fvec_t *out = new_fvec (1, channels); /* input buffer */
    1213
    1314  aubio_specdesc_t *o;
    1415 
    15   o = new_aubio_specdesc ("energy", win_s);
     16  o = new_aubio_specdesc ("energy", win_s, channels);
    1617  aubio_specdesc_do (o, in, out);
    1718  del_aubio_specdesc (o);
    1819
    19   o = new_aubio_specdesc ("energy", win_s);
     20  o = new_aubio_specdesc ("energy", win_s, channels);
    2021  aubio_specdesc_do (o, in, out);
    2122  del_aubio_specdesc (o);
    2223
    23   o = new_aubio_specdesc ("hfc", win_s);
     24  o = new_aubio_specdesc ("hfc", win_s, channels);
    2425  aubio_specdesc_do (o, in, out);
    2526  del_aubio_specdesc (o);
    2627
    27   o = new_aubio_specdesc ("complex", win_s);
     28  o = new_aubio_specdesc ("complex", win_s, channels);
    2829  aubio_specdesc_do (o, in, out);
    2930  del_aubio_specdesc (o);
    3031
    31   o = new_aubio_specdesc ("phase", win_s);
     32  o = new_aubio_specdesc ("phase", win_s, channels);
    3233  aubio_specdesc_do (o, in, out);
    3334  del_aubio_specdesc (o);
    3435
    35   o = new_aubio_specdesc ("kl", win_s);
     36  o = new_aubio_specdesc ("kl", win_s, channels);
    3637  aubio_specdesc_do (o, in, out);
    3738  del_aubio_specdesc (o);
    3839
    39   o = new_aubio_specdesc ("mkl", win_s);
     40  o = new_aubio_specdesc ("mkl", win_s, channels);
    4041  aubio_specdesc_do (o, in, out);
    4142  del_aubio_specdesc (o);
  • TabularUnified tests/src/test-peakpick.c

    r8212692 rf650860  
    66        /* allocate some memory */
    77        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_peakpicker_t * o = new_aubio_peakpicker();
     8        uint_t channels   = 1;                          /* number of channel */
     9        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
     10        fvec_t * out      = new_fvec (1, channels); /* input buffer */
     11        aubio_peakpicker_t * o = new_aubio_peakpicker(1);
    1112        aubio_peakpicker_set_threshold (o, 0.3);
    1213
  • TabularUnified tests/src/test-phasevoc-jack.c

    r8212692 rf650860  
    2222uint_t pos      = 0;  /* frames%dspblocksize for jack loop */
    2323
    24 fvec_t * in[2];
    25 cvec_t * fftgrain[2];
    26 fvec_t * out[2];
     24fvec_t * in;
     25cvec_t * fftgrain;
     26fvec_t * out;
    2727
    28 aubio_pvoc_t * pv[2];
     28aubio_pvoc_t * pv;
    2929
    3030int aubio_process(float **input, float **output, int nframes);
     
    3232int main(){
    3333        /* allocate some memory */
    34   uint_t i;
    35     for (i=0;i<channels;i++) {
    36         in[i]       = new_fvec (hop_s); /* input buffer       */
    37         fftgrain[i] = new_cvec (win_s); /* fft norm and phase */
    38         out[i]      = new_fvec (hop_s); /* output buffer      */
     34        in       = new_fvec (hop_s, channels); /* input buffer       */
     35        fftgrain = new_cvec (win_s, channels); /* fft norm and phase */
     36        out      = new_fvec (hop_s, channels); /* output buffer      */
    3937        /* allocate fft and other memory space */
    40         pv[i] = new_aubio_pvoc(win_s,hop_s);
    41     }
     38        pv = new_aubio_pvoc(win_s,hop_s,channels);
    4239
    4340#ifdef HAVE_JACK
     
    5653#endif
    5754       
    58     for (i=0;i<channels;i++) {
    59         del_aubio_pvoc(pv[i]);
    60         del_cvec(fftgrain[i]);
    61         del_fvec(in[i]);
    62         del_fvec(out[i]);
    63     }
     55        del_aubio_pvoc(pv);
     56        del_cvec(fftgrain);
     57        del_fvec(in);
     58        del_fvec(out);
    6459        aubio_cleanup();
    6560        return 0;
     
    7267    for (i=0;i<channels;i++) {
    7368      /* write input to datanew */
    74       fvec_write_sample(in[i], input[i][j], pos);
     69      fvec_write_sample(in, input[i][j], i, pos);
    7570      /* put synthnew in output */
    76       output[i][j] = fvec_read_sample(out[i], pos);
     71      output[i][j] = fvec_read_sample(out, i, pos);
    7772    }
    7873    /*time for fft*/
    7974    if (pos == hop_s-1) {
    8075      /* block loop */
    81     for (i=0;i<channels;i++) {
    82       aubio_pvoc_do (pv[i], in[i], fftgrain[i]);
     76      aubio_pvoc_do (pv,in, fftgrain);
    8377      // zero phases of first channel
    84       for (i=0;i<fftgrain[i]->length;i++) fftgrain[0]->phas[i] = 0.;
     78      for (i=0;i<fftgrain->length;i++) fftgrain->phas[0][i] = 0.;
    8579      // double phases of second channel
    86       for (i=0;i<fftgrain[i]->length;i++) {
    87         fftgrain[1]->phas[i] =
    88           aubio_unwrap2pi (fftgrain[1]->phas[i] * 2.);
     80      for (i=0;i<fftgrain->length;i++) {
     81        fftgrain->phas[1][i] =
     82          aubio_unwrap2pi (fftgrain->phas[1][i] * 2.);
    8983      }
    9084      // copy second channel to third one
    91       aubio_pvoc_rdo(pv[i], fftgrain[i], out[i]);
     85      aubio_pvoc_rdo(pv,fftgrain,out);
    9286      pos = -1;
    93     }
    9487    }
    9588    pos++;
  • TabularUnified tests/src/test-phasevoc.c

    r8212692 rf650860  
    77        uint_t win_s    = 1024; /* window size                       */
    88        uint_t hop_s    = 256;  /* hop size                          */
     9        uint_t channels = 4;  /* number of channels                */
    910        /* allocate some memory */
    10         fvec_t * in       = new_fvec (hop_s); /* input buffer       */
    11         cvec_t * fftgrain = new_cvec (win_s); /* fft norm and phase */
    12         fvec_t * out      = new_fvec (hop_s); /* output buffer      */
     11        fvec_t * in       = new_fvec (hop_s, channels); /* input buffer       */
     12        cvec_t * fftgrain = new_cvec (win_s, channels); /* fft norm and phase */
     13        fvec_t * out      = new_fvec (hop_s, channels); /* output buffer      */
    1314        /* allocate fft and other memory space */
    14         aubio_pvoc_t * pv = new_aubio_pvoc(win_s,hop_s);
     15        aubio_pvoc_t * pv = new_aubio_pvoc(win_s,hop_s,channels);
    1516        /* fill input with some data */
    1617        printf("initialised\n");
  • TabularUnified tests/src/test-pitchdetection.c

    r8212692 rf650860  
    88  uint_t hop_s = win_s / 4;     /* hop size */
    99  uint_t samplerate = 44100;    /* samplerate */
    10   fvec_t *in = new_fvec (hop_s);      /* input buffer */
    11   fvec_t *out = new_fvec (1); /* input buffer */
     10  uint_t channels = 1;          /* number of channel */
     11  fvec_t *in = new_fvec (hop_s, channels);      /* input buffer */
     12  fvec_t *out = new_fvec (1, channels); /* input buffer */
    1213  aubio_pitch_t *o =
    13       new_aubio_pitch ("default", win_s, hop_s, samplerate);
     14      new_aubio_pitch ("default", win_s, hop_s, channels, samplerate);
    1415  uint_t i = 0;
    1516
  • TabularUnified tests/src/test-pitchfcomb.c

    r8212692 rf650860  
    77        uint_t win_s      = 1024;                       /* window size */
    88        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);
     9        uint_t channels   = 3;                          /* number of channel */
     10        fvec_t * in       = new_fvec (hop_s, channels); /* input buffer */
     11        fvec_t * out      = new_fvec (1, channels);
    1112        aubio_pitchfcomb_t * o  = new_aubio_pitchfcomb (
    12           win_s, hop_s);
     13          win_s, hop_s, channels);
    1314        uint_t i = 0;
    1415
  • TabularUnified tests/src/test-pitchmcomb.c

    r8212692 rf650860  
    77        uint_t win_s      = 1024;                       /* window size */
    88        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 */
     9        uint_t channels   = 1;                          /* number of channel */
     10        cvec_t * in       = new_cvec (win_s, channels); /* input buffer */
     11        fvec_t * out      = new_fvec (1, channels); /* input buffer */
    1112
    12         aubio_pitchmcomb_t * o  = new_aubio_pitchmcomb(win_s, hop_s);
     13        aubio_pitchmcomb_t * o  = new_aubio_pitchmcomb(win_s, hop_s, channels);
    1314        uint_t i = 0;
    1415
  • TabularUnified tests/src/test-pitchschmitt.c

    r8212692 rf650860  
    66        /* allocate some memory */
    77        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 */
     8        fvec_t * in       = new_fvec (win_s, 1); /* input buffer */
     9        fvec_t * out = new_fvec (1, 1); /* input buffer */
    1010        aubio_pitchschmitt_t * o  = new_aubio_pitchschmitt(win_s);
    1111        uint_t i = 0;
  • TabularUnified tests/src/test-pitchyin.c

    r8212692 rf650860  
    66        /* allocate some memory */
    77        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 */
     8        uint_t channels   = 1;                          /* number of channel */
     9        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
     10        fvec_t * out      = new_fvec (win_s/2, channels); /* input buffer */
    1011        aubio_pitchyin_t *p = new_aubio_pitchyin (win_s);
    1112        uint_t i = 0;
  • TabularUnified tests/src/test-pitchyinfft.c

    r8212692 rf650860  
    66        /* allocate some memory */
    77        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 */
     8        uint_t channels   = 1;                          /* number of channel */
     9        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
     10        fvec_t * out      = new_fvec (1, channels); /* output pitch periods */
    1011        aubio_pitchyinfft_t * o  = new_aubio_pitchyinfft(win_s);
    1112        aubio_pitchyinfft_set_tolerance (o, 0.2);
  • TabularUnified tests/src/test-resample.c

    r8212692 rf650860  
    77  /* allocate some memory */
    88  uint_t win_s = 1024;          /* window size */
     9  uint_t channels = 1;          /* number of channel */
    910  smpl_t ratio = 0.5;
    10   fvec_t *in = new_fvec (win_s);      /* input buffer */
    11   fvec_t *out = new_fvec ((uint_t) (win_s * ratio));  /* input buffer */
     11  fvec_t *in = new_fvec (win_s, channels);      /* input buffer */
     12  fvec_t *out = new_fvec ((uint_t) (win_s * ratio), channels);  /* input buffer */
    1213  aubio_resampler_t *o = new_aubio_resampler (0.5, 0);
    1314  uint_t i = 0;
  • TabularUnified tests/src/test-scale.c

    r8212692 rf650860  
    66        /* allocate some memory */
    77        uint_t win_s      = 1024;                       /* window size */
    8         fvec_t * in       = new_fvec (win_s); /* input buffer */
     8        uint_t channels   = 1;                          /* number of channel */
     9        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
    910        aubio_scale_t * o = new_aubio_scale(0,1,2,3);
    1011        aubio_scale_set_limits (o,0,1,2,3);
  • TabularUnified tests/src/test-tempo.c

    r8212692 rf650860  
    55        /* allocate some memory */
    66        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.);
     7        uint_t channels   = 1;                          /* number of channel */
     8        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
     9        fvec_t * out      = new_fvec (2, channels);     /* input buffer */
     10        aubio_tempo_t * o  = new_aubio_tempo("complex", win_s, win_s/4, channels, 44100.);
    1011        uint_t i = 0;
    1112
  • TabularUnified tests/src/test-tss.c

    r8212692 rf650860  
    1414        uint_t win_s    = 1024; /* window size                       */
    1515        uint_t hop_s    = 256;  /* hop size                          */
     16        uint_t channels = 4;  /* number of channels                */
    1617        /* allocate some memory */
    17         fvec_t * in       = new_fvec (hop_s); /* input buffer       */
    18         cvec_t * fftgrain = new_cvec (win_s); /* fft norm and phase */
    19         cvec_t * cstead   = new_cvec (win_s); /* fft norm and phase */
    20         cvec_t * ctrans   = new_cvec (win_s); /* fft norm and phase */
    21         fvec_t * stead    = new_fvec (hop_s); /* output buffer      */
    22         fvec_t * trans    = new_fvec (hop_s); /* output buffer      */
     18        fvec_t * in       = new_fvec (hop_s, channels); /* input buffer       */
     19        cvec_t * fftgrain = new_cvec (win_s, channels); /* fft norm and phase */
     20        cvec_t * cstead   = new_cvec (win_s, channels); /* fft norm and phase */
     21        cvec_t * ctrans   = new_cvec (win_s, channels); /* fft norm and phase */
     22        fvec_t * stead    = new_fvec (hop_s, channels); /* output buffer      */
     23        fvec_t * trans    = new_fvec (hop_s, channels); /* output buffer      */
    2324        /* allocate fft and other memory space */
    24         aubio_pvoc_t * pv = new_aubio_pvoc (win_s,hop_s);
    25         aubio_pvoc_t * pvt = new_aubio_pvoc(win_s,hop_s);
    26         aubio_pvoc_t * pvs = new_aubio_pvoc(win_s,hop_s);
     25        aubio_pvoc_t * pv = new_aubio_pvoc (win_s,hop_s,channels);
     26        aubio_pvoc_t * pvt = new_aubio_pvoc(win_s,hop_s,channels);
     27        aubio_pvoc_t * pvs = new_aubio_pvoc(win_s,hop_s,channels);
    2728
    28         aubio_tss_t *  tss = new_aubio_tss(win_s,hop_s);
     29        aubio_tss_t *  tss = new_aubio_tss(win_s,hop_s,channels);
    2930        /* fill input with some data */
    3031        printf("initialised\n");
Note: See TracChangeset for help on using the changeset viewer.