Changes in / [8212692:f650860]
- Files:
-
- 1 added
- 6 deleted
- 106 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified examples/aubiomfcc.c ¶
r8212692 rf650860 33 33 34 34 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 35 unsigned int i; /*channels*/ 35 36 unsigned int j; /*frames*/ 36 37 37 38 for (j=0;j<(unsigned)nframes;j++) { 38 39 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 } 43 46 } 44 47 /*time for fft*/ … … 47 50 48 51 //compute mag spectrum 49 aubio_pvoc_do (pv, 52 aubio_pvoc_do (pv,ibuf, fftgrain); 50 53 51 54 //compute mfccs … … 69 72 outmsg("%f\t",frames*overlap_size/(float)samplerate); 70 73 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) ); 72 75 } 73 76 outmsg("\n"); … … 83 86 84 87 /* phase vocoder */ 85 pv = new_aubio_pvoc (buffer_size, overlap_size );88 pv = new_aubio_pvoc (buffer_size, overlap_size, channels); 86 89 87 fftgrain = new_cvec (buffer_size );90 fftgrain = new_cvec (buffer_size, channels); 88 91 89 92 //populating the filter 90 93 mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate); 91 94 92 mfcc_out = new_fvec(n_coefs );95 mfcc_out = new_fvec(n_coefs,channels); 93 96 94 97 //process -
TabularUnified examples/aubionotes.c ¶
r8212692 rf650860 19 19 */ 20 20 21 #define AUBIO_UNSTABLE 1 // for fvec_median 21 #define AUBIO_UNSTABLE 1 // for fvec_median_channel 22 22 23 23 #include "utils.h" … … 50 50 51 51 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 52 unsigned int i; /*channels*/ 52 53 unsigned int j; /*frames*/ 53 54 for (j=0;j<(unsigned)nframes;j++) { 54 55 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 } 59 62 } 60 63 /*time for fft*/ … … 64 67 65 68 aubio_pitch_do (pitchdet, ibuf, pitch_obuf); 66 pitch = fvec_read_sample(pitch_obuf, 0 );69 pitch = fvec_read_sample(pitch_obuf, 0, 0); 67 70 if(median){ 68 71 note_append(note_buffer, pitch); … … 71 74 /* curlevel is negatif or 1 if silence */ 72 75 curlevel = aubio_level_detection(ibuf, silence); 73 if (fvec_read_sample(onset, 0 )) {76 if (fvec_read_sample(onset, 0, 0)) { 74 77 /* test for silence */ 75 78 if (curlevel == 1.) { … … 89 92 90 93 for (pos = 0; pos < overlap_size; pos++){ 91 obuf->data[ pos] = woodblock->data[pos];94 obuf->data[0][pos] = woodblock->data[0][pos]; 92 95 } 93 96 } … … 109 112 } // if median 110 113 for (pos = 0; pos < overlap_size; pos++) 111 obuf->data[ pos] = 0.;114 obuf->data[0][pos] = 0.; 112 115 } 113 116 /* end of block loop */ … … 128 131 uint_t i = 0; 129 132 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]; 131 134 } 132 note_buffer->data[ note_buffer->length - 1] = curnote;135 note_buffer->data[0][note_buffer->length - 1] = curnote; 133 136 return; 134 137 } … … 139 142 uint_t i; 140 143 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]; 142 145 } 143 return fvec_median (note_buffer2);146 return fvec_median_channel (note_buffer2, 0); 144 147 } 145 148 … … 147 150 examples_common_init(argc,argv); 148 151 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); 150 154 if (threshold != 0.) aubio_onset_set_threshold (o, threshold); 151 onset = new_fvec (1 );155 onset = new_fvec (1, channels); 152 156 153 157 pitchdet = new_aubio_pitch (pitch_mode, buffer_size * 4, 154 overlap_size, samplerate);158 overlap_size, channels, samplerate); 155 159 aubio_pitch_set_tolerance (pitchdet, 0.7); 156 pitch_obuf = new_fvec (1 );160 pitch_obuf = new_fvec (1, channels); 157 161 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); 160 164 } 161 165 -
TabularUnified examples/aubioonset.c ¶
r8212692 rf650860 31 31 for (j=0;j<(unsigned)nframes;j++) { 32 32 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 } 37 39 } 38 40 /*time for fft*/ 39 if (pos == overlap_size-1) { 41 if (pos == overlap_size-1) { 40 42 /* block loop */ 41 43 aubio_onset_do (o, ibuf, onset); 42 if ( fvec_read_sample(onset, 0)) {44 if (fvec_read_sample(onset, 0, 0)) { 43 45 fvec_copy (woodblock, obuf); 44 46 } else { … … 53 55 } 54 56 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 } 57 static void process_print (void) { 58 /* output times in seconds, taking back some 59 * delay to ensure the label is _before_ the 60 * actual onset */ 61 if (!verbose && usejack) return; 62 smpl_t onset_found = fvec_read_sample(onset, 0, 0); 63 if (onset_found) { 64 if(frames >= 4) { 65 outmsg("%f\n",(frames - frames_delay + onset_found) 66 *overlap_size/(float)samplerate); 67 } else if (frames < frames_delay) { 68 outmsg("%f\n",0.); 69 } 70 } 71 71 } 72 72 … … 75 75 examples_common_init(argc,argv); 76 76 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); 78 79 if (threshold != 0.) aubio_onset_set_threshold (o, threshold); 79 onset = new_fvec (1 );80 onset = new_fvec (1, channels); 80 81 81 82 examples_common_process(aubio_process,process_print); -
TabularUnified examples/aubiopitch.c ¶
r8212692 rf650860 27 27 28 28 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 29 unsigned int i; /*channels*/ 29 30 unsigned int j; /*frames*/ 30 31 for (j=0;j<(unsigned)nframes;j++) { 31 32 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 } 36 39 } 37 40 /*time for fft*/ … … 39 42 /* block loop */ 40 43 aubio_pitch_do (o, ibuf, pitch); 41 if (fvec_read_sample(pitch, 0 )) {44 if (fvec_read_sample(pitch, 0, 0)) { 42 45 for (pos = 0; pos < overlap_size; pos++){ 43 46 // TODO, play sine at this freq … … 56 59 static void process_print (void) { 57 60 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); 59 62 outmsg("%f %f\n",(frames) 60 63 *overlap_size/(float)samplerate, pitch_found); … … 64 67 examples_common_init(argc,argv); 65 68 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); 68 72 69 73 examples_common_process(aubio_process,process_print); -
TabularUnified examples/aubioquiet.c ¶
r8212692 rf650860 26 26 int aubio_process(smpl_t **input, smpl_t **output, int nframes); 27 27 int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 28 unsigned int i; /*channels*/ 28 29 unsigned int j; /*frames*/ 29 30 for (j=0;j<(unsigned)nframes;j++) { 30 31 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 } 35 38 } 36 39 /*time for fft*/ … … 38 41 /* test for silence */ 39 42 if (aubio_silence_detection(ibuf, silence)==1) { 40 41 43 if (wassilence==1) issilence = 1; 44 else issilence = 2; 42 45 wassilence=1; 43 46 } else { 44 45 47 if (wassilence<=0) issilence = 0; 48 else issilence = -1; 46 49 wassilence=0; 47 50 } -
TabularUnified examples/aubiotrack.c ¶
r8212692 rf650860 29 29 30 30 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 31 unsigned int i; /*channels*/ 31 32 unsigned int j; /*frames*/ 32 33 for (j=0;j<(unsigned)nframes;j++) { 33 34 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 } 38 41 } 39 42 /*time for fft*/ … … 41 44 /* block loop */ 42 45 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); 45 48 if (istactus > 0.) { 46 49 fvec_copy (woodblock, obuf); … … 73 76 examples_common_init(argc,argv); 74 77 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); 77 80 if (threshold != 0.) aubio_tempo_set_threshold (bt, threshold); 78 81 -
TabularUnified examples/sndfileio.c ¶
r8212692 rf650860 96 96 aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t); 97 97 f->samplerate = fmodel->samplerate; 98 f->channels = 1; //fmodel->channels;98 f->channels = fmodel->channels; 99 99 f->format = fmodel->format; 100 100 aubio_sndfile_open_wo(f, outputname); … … 125 125 /* read frames from file in data 126 126 * return the number of frames actually read */ 127 int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t * *read) {127 int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t * read) { 128 128 sf_count_t read_frames; 129 129 int i,j, channels = f->channels; … … 150 150 /* de-interleaving data */ 151 151 for (i=0; i<channels; i++) { 152 pread = (smpl_t *)fvec_get_ data(read[i]);152 pread = (smpl_t *)fvec_get_channel(read,i); 153 153 for (j=0; j<aread; j++) { 154 154 pread[j] = (smpl_t)f->tmpdata[channels*j+i]; … … 158 158 } 159 159 160 int161 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 199 160 /* write 'frames' samples to file from data 200 161 * return the number of frames actually written 201 162 */ 202 int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t * *write) {163 int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t * write) { 203 164 sf_count_t written_frames = 0; 204 165 int i, j, channels = f->channels; … … 219 180 /* interleaving data */ 220 181 for (i=0; i<channels; i++) { 221 pwrite = (smpl_t *)fvec_get_ data(write[i]);182 pwrite = (smpl_t *)fvec_get_channel(write,i); 222 183 for (j=0; j<frames; j++) { 223 184 f->tmpdata[channels*j+i] = (float)pwrite[j]; -
TabularUnified examples/sndfileio.h ¶
r8212692 rf650860 49 49 * Read frames data from file 50 50 */ 51 int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t * *read);51 int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t * read); 52 52 /** 53 53 * Write data of length frames to file 54 54 */ 55 int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t * *write);55 int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t * write); 56 56 /** 57 57 * Close file and delete file object -
TabularUnified examples/utils.c ¶
r8212692 rf650860 61 61 uint_t buffer_size = 512; //1024; 62 62 uint_t overlap_size = 256; //512; 63 uint_t channels = 1; 63 64 uint_t samplerate = 44100; 64 65 … … 216 217 if (verbose) 217 218 aubio_sndfile_info (file); 219 channels = aubio_sndfile_channels (file); 218 220 samplerate = aubio_sndfile_samplerate (file); 219 221 if (output_filename != NULL) … … 263 265 examples_common_del (void) 264 266 { 265 uint_t i;266 267 del_fvec (ibuf); 267 268 del_fvec (obuf); … … 282 283 #if HAVE_JACK 283 284 debug ("Jack init ...\n"); 284 jack_setup = new_aubio_jack ( 1, 1,285 jack_setup = new_aubio_jack (channels, channels, 285 286 0, 1, (aubio_process_func_t) process_func); 286 287 debug ("Jack activation ...\n"); … … 300 301 frames = 0; 301 302 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); 305 306 print (); 306 307 if (output_filename != NULL) { 307 aubio_sndfile_write (fileout, overlap_size, &obuf);308 aubio_sndfile_write (fileout, overlap_size, obuf); 308 309 } 309 310 frames++; … … 327 328 fvec_zeros(obuf); 328 329 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); 330 331 print (); 331 332 } -
TabularUnified examples/utils.h ¶
r8212692 rf650860 74 74 extern uint_t buffer_size; 75 75 extern uint_t overlap_size; 76 extern uint_t channels; 76 77 extern uint_t samplerate; 77 78 -
TabularUnified interfaces/python/aubio-types.h ¶
r8212692 rf650860 6 6 #include <aubio.h> 7 7 8 #define Py_default_vector_length 10249 #define Py_default_vector_ height18 #define Py_default_vector_length 1024 9 #define Py_default_vector_channels 1 10 10 11 11 #define Py_aubio_default_samplerate 44100 … … 18 18 #endif 19 19 20 // special python type for cvec 20 /** 21 22 Defining this constant to 1 will allow PyAubio_CastToFvec to convert from data 23 types different than NPY_FLOAT to and fvec, and therefore creating a copy of 24 it. 25 26 */ 27 #define AUBIO_DO_CASTING 0 28 29 typedef struct 30 { 31 PyObject_HEAD 32 fvec_t * o; 33 uint_t length; 34 uint_t channels; 35 } Py_fvec; 36 extern PyTypeObject Py_fvecType; 37 extern PyObject *PyAubio_FvecToArray (Py_fvec * self); 38 extern PyObject *PyAubio_CFvecToArray (fvec_t * self); 39 extern Py_fvec *PyAubio_ArrayToFvec (PyObject * self); 40 21 41 typedef struct 22 42 { … … 27 47 } Py_cvec; 28 48 extern PyTypeObject Py_cvecType; 49 extern PyObject *PyAubio_CvecToArray (Py_cvec * self); 50 extern Py_cvec *PyAubio_ArrayToCvec (PyObject * self); 29 51 30 // defined in aubio-proxy.c31 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 wrappers41 52 extern PyTypeObject Py_filterType; 42 53 … … 46 57 47 58 extern PyTypeObject Py_pvocType; 48 -
TabularUnified interfaces/python/aubiomodule.c ¶
r8212692 rf650860 12 12 { 13 13 PyObject *input; 14 fvec_t*vec;14 Py_fvec *vec; 15 15 smpl_t alpha; 16 16 PyObject *result; … … 24 24 } 25 25 26 vec = PyAubio_ArrayTo CFvec (input);26 vec = PyAubio_ArrayToFvec (input); 27 27 28 28 if (vec == NULL) { … … 31 31 32 32 // compute the function 33 result = Py_BuildValue ("f", fvec_alpha_norm (vec , alpha));33 result = Py_BuildValue ("f", fvec_alpha_norm (vec->o, alpha)); 34 34 if (result == NULL) { 35 35 return NULL; … … 45 45 { 46 46 PyObject *input; 47 fvec_t*vec;47 Py_fvec *vec; 48 48 PyObject *result; 49 49 … … 56 56 } 57 57 58 vec = PyAubio_ArrayTo CFvec (input);58 vec = PyAubio_ArrayToFvec (input); 59 59 60 60 if (vec == NULL) { … … 63 63 64 64 // compute the function 65 result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec ));65 result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec->o)); 66 66 if (result == NULL) { 67 67 return NULL; … … 73 73 static char Py_min_removal_doc[] = "compute zero crossing rate"; 74 74 75 static PyObject * 75 static PyObject * 76 76 Py_min_removal(PyObject * self, PyObject * args) 77 77 { 78 78 PyObject *input; 79 fvec_t*vec;79 Py_fvec *vec; 80 80 81 81 if (!PyArg_ParseTuple (args, "O:min_removal", &input)) { … … 87 87 } 88 88 89 vec = PyAubio_ArrayTo CFvec (input);89 vec = PyAubio_ArrayToFvec (input); 90 90 91 91 if (vec == NULL) { … … 94 94 95 95 // compute the function 96 fvec_min_removal (vec );96 fvec_min_removal (vec->o); 97 97 98 98 // since this function does not return, we could return None 99 99 //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); 102 102 // or even without converting it back to an array 103 103 //Py_INCREF(vec); … … 107 107 static PyMethodDef aubio_methods[] = { 108 108 {"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, 110 110 Py_zero_crossing_rate_doc}, 111 111 {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc}, … … 121 121 int err; 122 122 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) 128 129 // generated objects 129 130 || (generated_types_ready() < 0 ) … … 145 146 } 146 147 148 Py_INCREF (&Py_fvecType); 149 PyModule_AddObject (m, "fvec", (PyObject *) & Py_fvecType); 147 150 Py_INCREF (&Py_cvecType); 148 151 PyModule_AddObject (m, "cvec", (PyObject *) & Py_cvecType); -
TabularUnified interfaces/python/aubiowraphell.h ¶
r8212692 rf650860 94 94 95 95 // some more helpers 96 #define AUBIO_NEW_VEC(name, type, lengthval ) \96 #define AUBIO_NEW_VEC(name, type, lengthval, channelsval) \ 97 97 name = (type *) PyObject_New (type, & type ## Type); \ 98 name->channels = channelsval; \ 98 99 name->length = lengthval; -
TabularUnified interfaces/python/gen_pyobject.py ¶
r8212692 rf650860 69 69 # move into the C library at some point. 70 70 defaultsizes = { 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'), 85 85 } 86 86 … … 99 99 'hop_size': 'Py_default_vector_length / 2', 100 100 # these should be alright 101 'channels': 'Py_default_vector_channels', 101 102 'samplerate': 'Py_aubio_default_samplerate', 102 103 # now for the non obvious ones … … 123 124 } 124 125 125 # python to aubio 126 # aubio to pyaubio 127 aubio2pyaubio = { 128 'fvec_t*': 'Py_fvec', 129 'cvec_t*': 'Py_cvec', 130 } 131 132 # array to aubio 126 133 aubiovecfrompyobj = { 127 'fvec_t*': 'PyAubio_ArrayTo CFvec',128 'cvec_t*': 'PyAubio_ArrayToC Cvec',129 } 130 131 # aubio to python134 'fvec_t*': 'PyAubio_ArrayToFvec', 135 'cvec_t*': 'PyAubio_ArrayToCvec', 136 } 137 138 # aubio to array 132 139 aubiovectopyobj = { 140 'fvec_t*': 'PyAubio_FvecToArray', 141 'cvec_t*': 'PyAubio_CvecToArray', 142 } 143 144 aubiovectopyobj_new = { 133 145 'fvec_t*': 'PyAubio_CFvecToArray', 134 'cvec_t*': 'PyAubio_CCvecTo PyCvec',146 'cvec_t*': 'PyAubio_CCvecToArray', 135 147 'smpl_t': 'PyFloat_FromDouble', 136 148 } … … 139 151 newparams = get_params_types_names(newfunc) 140 152 # 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]) 145 154 # "param1", "param2", "param3" 146 155 paramnames = ", ".join(["\""+p[1]+"\"" for p in newparams]) … … 170 179 Py_%(name)s_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) 171 180 { 172 Py_%(name)s *self;173 181 """ % locals() 174 182 for ptype, pname in newparams: … … 178 186 """ % locals() 179 187 # now the actual PyArg_Parse 180 if len(paramnames):181 s += """\188 s += """\ 189 Py_%(name)s *self; 182 190 static char *kwlist[] = { %(paramnames)s, NULL }; 183 191 … … 186 194 return NULL; 187 195 } 188 """ % locals()189 s += """\190 196 191 197 self = (Py_%(name)s *) pytype->tp_alloc (pytype, 0); … … 232 238 } 233 239 234 AUBIO_INIT(%(name)s 240 AUBIO_INIT(%(name)s, self->%(selfparams)s) 235 241 236 242 AUBIO_DEL(%(name)s) … … 259 265 inputdefs = "\n ".join(["PyObject * " + p[-1] + "_obj;" for p in inputparams]) 260 266 inputvecs = "\n ".join(map(lambda p: \ 261 p[0]+ p[-1] + ";", inputparams))267 aubio2pyaubio[p[0]]+" * " + p[-1] + ";", inputparams)) 262 268 parseinput = "" 263 269 for p in inputparams: … … 279 285 #assert len(outputparams) == 1, \ 280 286 # "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]) 282 288 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]} \ 289 AUBIO_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]} \ 286 293 for p in outputparams]) 287 294 if len(outputparams) > 1: … … 301 308 302 309 # 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]) 304 311 305 312 # put it all together … … 409 416 "get method has more than one parameter %s" % params 410 417 getter_args = "self->o" 411 returnval = "(PyObject *)" + aubiovectopyobj [out_type] + " (tmp)"418 returnval = "(PyObject *)" + aubiovectopyobj_new[out_type] + " (tmp)" 412 419 shortname = method_name.split(name+'_')[-1] 413 420 method_defs += """\ -
TabularUnified interfaces/python/py-cvec.c ¶
r8212692 rf650860 4 4 5 5 class cvec(): 6 def __init__(self, length = 1024 ):6 def __init__(self, length = 1024, channels = 1): 7 7 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) 11 11 */ 12 12 13 13 14 static char Py_cvec_doc[] = "cvec object"; … … 16 17 Py_cvec_new (PyTypeObject * type, PyObject * args, PyObject * kwds) 17 18 { 18 int length= 0 ;19 int length= 0, channels = 0; 19 20 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)) { 24 25 return NULL; 25 26 } … … 29 30 30 31 self->length = Py_default_vector_length / 2 + 1; 32 self->channels = Py_default_vector_channels; 31 33 32 34 if (self == NULL) { … … 42 44 } 43 45 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 44 54 return (PyObject *) self; 45 55 } … … 48 58 Py_cvec_init (Py_cvec * self, PyObject * args, PyObject * kwds) 49 59 { 50 self->o = new_cvec ((self->length - 1) * 2 );60 self->o = new_cvec ((self->length - 1) * 2, self->channels); 51 61 if (self->o == NULL) { 52 62 return -1; … … 70 80 PyObject *result = NULL; 71 81 72 format = PyString_FromString ("aubio cvec of %d elements ");82 format = PyString_FromString ("aubio cvec of %d elements with %d channels"); 73 83 if (format == NULL) { 74 84 goto fail; 75 85 } 76 86 77 args = Py_BuildValue ("I ", self->length);87 args = Py_BuildValue ("II", self->length, self->channels); 78 88 if (args == NULL) { 79 89 goto fail; 80 90 } 81 cvec_print ( self->o );91 //cvec_print ( self->o ); 82 92 83 93 result = PyString_Format (format, args); … … 90 100 } 91 101 102 Py_cvec * 103 PyAubio_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 177 fail: 178 return NULL; 179 } 180 181 PyObject * 182 PyAubio_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 92 201 PyObject * 93 202 PyAubio_CvecNormToArray (Py_cvec * self) 94 203 { 204 PyObject *array = NULL; 205 uint_t i; 95 206 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; 97 216 } 98 217 … … 101 220 PyAubio_CvecPhasToArray (Py_cvec * self) 102 221 { 222 PyObject *array = NULL; 223 uint_t i; 103 224 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; 105 234 } 106 235 … … 126 255 Py_cvec_set_norm (Py_cvec * vec, PyObject *input, void * closure) 127 256 { 257 uint_t i; 128 258 PyObject * array; 129 259 if (input == NULL) { … … 153 283 154 284 // 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 } 161 291 if (vec->o->length != PyArray_SIZE (array)) { 162 292 PyErr_Format (PyExc_ValueError, … … 165 295 goto fail; 166 296 } 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 } 170 315 171 316 } else { … … 184 329 Py_cvec_set_phas (Py_cvec * vec, PyObject *input, void * closure) 185 330 { 331 uint_t i; 186 332 PyObject * array; 187 333 if (input == NULL) { … … 211 357 212 358 // 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 } 219 365 if (vec->o->length != PyArray_SIZE (array)) { 220 366 PyErr_Format (PyExc_ValueError, … … 223 369 goto fail; 224 370 } 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 } 228 389 229 390 } else { … … 237 398 fail: 238 399 return 1; 400 } 401 402 static Py_ssize_t 403 Py_cvec_getchannels (Py_cvec * self) 404 { 405 return self->channels; 406 } 407 408 static PyObject * 409 Py_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 423 static int 424 Py_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 454 fail: 455 return -1; 239 456 } 240 457 … … 243 460 {"length", T_INT, offsetof (Py_cvec, length), READONLY, 244 461 "length attribute"}, 462 {"channels", T_INT, offsetof (Py_cvec, channels), READONLY, 463 "channels attribute"}, 245 464 {NULL} /* Sentinel */ 246 465 }; 247 466 248 467 static PyMethodDef Py_cvec_methods[] = { 468 {"__array__", (PyCFunction) PyAubio_CvecToArray, METH_NOARGS, 469 "Returns the content of this cvec as a numpy array"}, 249 470 {NULL} 250 471 }; … … 252 473 static PyGetSetDef Py_cvec_getseters[] = { 253 474 {"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", 255 476 NULL}, 256 477 {"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", 258 479 NULL}, 259 480 {NULL} /* sentinel */ 260 481 }; 482 483 static 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 261 496 262 497 PyTypeObject Py_cvecType = { … … 273 508 (reprfunc) Py_cvec_repr, /* tp_repr */ 274 509 0, /* tp_as_number */ 275 0, //&Py_cvec_tp_as_sequence, /* tp_as_sequence */510 &Py_cvec_tp_as_sequence, /* tp_as_sequence */ 276 511 0, /* tp_as_mapping */ 277 512 0, /* tp_hash */ -
TabularUnified interfaces/python/py-fft.c ¶
r8212692 rf650860 3 3 static char Py_fft_doc[] = "fft object"; 4 4 5 AUBIO_DECLARE(fft, uint_t win_s )5 AUBIO_DECLARE(fft, uint_t win_s; uint_t channels) 6 6 7 7 //AUBIO_NEW(fft) … … 9 9 Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds) 10 10 { 11 int win_s = 0 ;11 int win_s = 0, channels = 0; 12 12 Py_fft *self; 13 static char *kwlist[] = { "win_s", NULL };13 static char *kwlist[] = { "win_s", "channels", NULL }; 14 14 15 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I ", kwlist,16 &win_s )) {15 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist, 16 &win_s, &channels)) { 17 17 return NULL; 18 18 } … … 25 25 26 26 self->win_s = Py_default_vector_length; 27 self->channels = Py_default_vector_channels; 27 28 28 29 if (self == NULL) { … … 38 39 } 39 40 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 40 49 return (PyObject *) self; 41 50 } 42 51 43 52 44 AUBIO_INIT(fft, self->win_s )53 AUBIO_INIT(fft, self->win_s, self->channels) 45 54 46 55 AUBIO_DEL(fft) … … 50 59 { 51 60 PyObject *input; 52 fvec_t*vec;53 cvec_t*output;61 Py_fvec *vec; 62 Py_cvec *output; 54 63 55 64 if (!PyArg_ParseTuple (args, "O", &input)) { … … 57 66 } 58 67 59 vec = PyAubio_ArrayTo CFvec (input);68 vec = PyAubio_ArrayToFvec (input); 60 69 61 70 if (vec == NULL) { … … 63 72 } 64 73 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); 66 78 67 79 // 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); 70 84 } 71 85 … … 73 87 {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY, 74 88 "size of the window"}, 89 {"channels", T_INT, offsetof (Py_fft, channels), READONLY, 90 "number of channels"}, 75 91 AUBIO_MEMBERS_STOP(fft) 76 92 77 93 static PyObject * 78 Py_fft_rdo(Py _fft * self, PyObject * args)94 Py_fft_rdo(PyObject * self, PyObject * args) 79 95 { 80 96 PyObject *input; 81 cvec_t*vec;82 fvec_t*output;97 Py_cvec *vec; 98 Py_fvec *output; 83 99 84 100 if (!PyArg_ParseTuple (args, "O", &input)) { … … 86 102 } 87 103 88 vec = PyAubio_ArrayToC Cvec (input);104 vec = PyAubio_ArrayToCvec (input); 89 105 90 106 if (vec == NULL) { … … 92 108 } 93 109 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); 95 114 96 115 // 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); 99 118 } 100 119 -
TabularUnified interfaces/python/py-filter.c ¶
r8212692 rf650860 6 6 aubio_filter_t * o; 7 7 uint_t order; 8 uint_t channels; 8 9 } Py_filter; 9 10 … … 13 14 Py_filter_new (PyTypeObject * type, PyObject * args, PyObject * kwds) 14 15 { 15 int order= 0 ;16 int order= 0, channels = 0; 16 17 Py_filter *self; 17 static char *kwlist[] = { "order", NULL };18 static char *kwlist[] = { "order", "channels", NULL }; 18 19 19 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I ", kwlist,20 &order )) {20 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist, 21 &order, &channels)) { 21 22 return NULL; 22 23 } … … 29 30 30 31 self->order = 7; 32 self->channels = Py_default_vector_channels; 31 33 32 34 if (order > 0) { … … 38 40 } 39 41 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 40 50 return (PyObject *) self; 41 51 } … … 44 54 Py_filter_init (Py_filter * self, PyObject * args, PyObject * kwds) 45 55 { 46 self->o = new_aubio_filter (self->order );56 self->o = new_aubio_filter (self->order, self->channels); 47 57 if (self->o == NULL) { 48 58 return -1; … … 60 70 61 71 static PyObject * 62 Py_filter_do(Py _filter* self, PyObject * args)72 Py_filter_do(PyObject * self, PyObject * args) 63 73 { 64 74 PyObject *input; 65 fvec_t*vec;75 Py_fvec *vec; 66 76 67 77 if (!PyArg_ParseTuple (args, "O:digital_filter.do", &input)) { … … 73 83 } 74 84 75 vec = PyAubio_ArrayTo CFvec (input);85 vec = PyAubio_ArrayToFvec (input); 76 86 77 87 if (vec == NULL) { … … 80 90 81 91 // 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 85 102 } 86 103 … … 125 142 {"order", T_INT, offsetof (Py_filter, order), READONLY, 126 143 "order of the filter"}, 144 {"channels", T_INT, offsetof (Py_filter, channels), READONLY, 145 "number of channels"}, 127 146 {NULL} /* Sentinel */ 128 147 }; -
TabularUnified interfaces/python/py-filterbank.c ¶
r8212692 rf650860 54 54 { 55 55 PyObject *input; 56 cvec_t*vec;57 fvec_t *out;56 Py_cvec *vec; 57 Py_fvec *output; 58 58 59 59 if (!PyArg_ParseTuple (args, "O", &input)) { … … 61 61 } 62 62 63 vec = PyAubio_ArrayToC Cvec (input);63 vec = PyAubio_ArrayToCvec (input); 64 64 65 65 if (vec == NULL) { … … 67 67 } 68 68 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); 70 73 71 74 // 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); 74 77 } 75 78 … … 88 91 PyObject *input; 89 92 uint_t samplerate; 90 fvec_t*freqs;93 Py_fvec *freqs; 91 94 if (!PyArg_ParseTuple (args, "OI", &input, &samplerate)) { 92 95 return NULL; … … 97 100 } 98 101 99 freqs = PyAubio_ArrayTo CFvec (input);102 freqs = PyAubio_ArrayToFvec (input); 100 103 101 104 if (freqs == NULL) { … … 104 107 105 108 err = aubio_filterbank_set_triangle_bands (self->o, 106 freqs , samplerate);109 freqs->o, samplerate); 107 110 if (err > 0) { 108 111 PyErr_SetString (PyExc_ValueError, … … 135 138 Py_filterbank_get_coeffs (Py_filterbank * self, PyObject *unused) 136 139 { 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); 139 145 } 140 146 -
TabularUnified interfaces/python/py-phasevoc.c ¶
r8212692 rf650860 3 3 static char Py_pvoc_doc[] = "pvoc object"; 4 4 5 AUBIO_DECLARE(pvoc, uint_t win_s; uint_t hop_s )5 AUBIO_DECLARE(pvoc, uint_t win_s; uint_t hop_s; uint_t channels) 6 6 7 7 //AUBIO_NEW(pvoc) … … 9 9 Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds) 10 10 { 11 int win_s = 0, hop_s = 0 ;11 int win_s = 0, hop_s = 0, channels = 0; 12 12 Py_pvoc *self; 13 static char *kwlist[] = { "win_s", "hop_s", NULL };13 static char *kwlist[] = { "win_s", "hop_s", "channels", NULL }; 14 14 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)) { 17 17 return NULL; 18 18 } … … 26 26 self->win_s = Py_default_vector_length; 27 27 self->hop_s = Py_default_vector_length/2; 28 self->channels = Py_default_vector_channels; 28 29 29 30 if (self == NULL) { … … 47 48 } 48 49 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 49 58 return (PyObject *) self; 50 59 } 51 60 52 61 53 AUBIO_INIT(pvoc, self->win_s, self->hop_s )62 AUBIO_INIT(pvoc, self->win_s, self->hop_s, self->channels) 54 63 55 64 AUBIO_DEL(pvoc) 56 65 57 66 static PyObject * 58 Py_pvoc_do(Py _pvoc* self, PyObject * args)67 Py_pvoc_do(PyObject * self, PyObject * args) 59 68 { 60 69 PyObject *input; 61 fvec_t*vec;62 cvec_t*output;70 Py_fvec *vec; 71 Py_cvec *output; 63 72 64 73 if (!PyArg_ParseTuple (args, "O", &input)) { … … 66 75 } 67 76 68 vec = PyAubio_ArrayTo CFvec (input);77 vec = PyAubio_ArrayToFvec (input); 69 78 70 79 if (vec == NULL) { … … 72 81 } 73 82 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); 75 87 76 88 // 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); 79 93 } 80 94 … … 84 98 {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY, 85 99 "size of the hop"}, 100 {"channels", T_INT, offsetof (Py_pvoc, channels), READONLY, 101 "number of channels"}, 86 102 AUBIO_MEMBERS_STOP(pvoc) 87 103 88 104 static PyObject * 89 Py_pvoc_rdo(Py _pvoc* self, PyObject * args)105 Py_pvoc_rdo(PyObject * self, PyObject * args) 90 106 { 91 107 PyObject *input; 92 cvec_t*vec;93 fvec_t*output;108 Py_cvec *vec; 109 Py_fvec *output; 94 110 95 111 if (!PyArg_ParseTuple (args, "O", &input)) { … … 97 113 } 98 114 99 vec = PyAubio_ArrayToC Cvec (input);115 vec = PyAubio_ArrayToCvec (input); 100 116 101 117 if (vec == NULL) { … … 103 119 } 104 120 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); 106 125 107 126 // 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); 110 129 } 111 130 -
TabularUnified interfaces/python/setup.py ¶
r8212692 rf650860 10 10 Extension("_aubio", 11 11 ["aubiomodule.c", 12 " aubioproxy.c",12 "py-fvec.c", 13 13 "py-cvec.c", 14 # example without macro15 14 "py-filter.c", 16 # macroised 15 # macroised 17 16 "py-filterbank.c", 18 17 "py-fft.c", -
TabularUnified interfaces/python/test_aubio.py ¶
r8212692 rf650860 1 1 from numpy.testing import TestCase, run_module_suite 2 from numpy.testing import assert_equal 3 from _aubio import * 4 from numpy import array 5 6 AUBIO_DO_CASTING = 0 2 7 3 8 class aubiomodule_test_case(TestCase): 4 9 5 def test_import(self):10 def setUp(self): 6 11 """ 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) 8 126 9 127 if __name__ == '__main__': -
TabularUnified interfaces/python/test_fft.py ¶
r8212692 rf650860 2 2 from numpy.testing import assert_equal, assert_almost_equal 3 3 # WARNING: numpy also has an fft object 4 from aubio import fvec, fft, cvec4 from _aubio import fft, fvec, cvec 5 5 from numpy import array, shape 6 6 from math import pi … … 10 10 def test_members(self): 11 11 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]) 13 15 14 16 def test_output_dimensions(self): 15 17 """ check the dimensions of output """ 16 win_s = 102417 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) 19 21 fftgrain = f (timegrain) 22 assert_equal (array(fftgrain), 0) 23 assert_equal (shape(fftgrain), (chan * 2, win_s/2+1)) 20 24 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)) 22 26 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)) 24 28 25 29 def test_zeros(self): 26 30 """ check the transform of zeros """ 27 win_s = 51228 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) 30 34 fftgrain = f(timegrain) 31 35 assert_equal ( fftgrain.norm == 0, True ) … … 36 40 from random import random 37 41 from math import floor 38 win_s = 25642 win_s, chan = 256, 1 39 43 i = floor(random()*win_s) 40 44 impulse = pi * random() 41 f = fft(win_s )42 timegrain = fvec(win_s )43 timegrain[ i] = impulse45 f = fft(win_s, chan) 46 timegrain = fvec(win_s, chan) 47 timegrain[0][i] = impulse 44 48 fftgrain = f ( timegrain ) 45 #self.plot_this ( fftgrain.phas )49 #self.plot_this ( fftgrain.phas[0] ) 46 50 assert_almost_equal ( fftgrain.norm, impulse, decimal = 6 ) 47 51 assert_equal ( fftgrain.phas <= pi, True) … … 52 56 from random import random 53 57 from math import floor 54 win_s = 25658 win_s, chan = 256, 1 55 59 i = 0 56 60 impulse = -10. 57 f = fft(win_s )58 timegrain = fvec(win_s )59 timegrain[ i] = impulse61 f = fft(win_s, chan) 62 timegrain = fvec(win_s, chan) 63 timegrain[0][i] = impulse 60 64 fftgrain = f ( timegrain ) 61 #self.plot_this ( fftgrain.phas )65 #self.plot_this ( fftgrain.phas[0] ) 62 66 assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 6 ) 63 67 if impulse < 0: 64 68 # 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) 68 72 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) 72 76 # now check the resynthesis 73 77 synthgrain = f.rdo ( fftgrain ) … … 79 83 80 84 def test_impulse_at_zero(self): 81 """ check the transform of one impulse at a index 0 """82 win_s = 102485 """ check the transform of one impulse at a index 0 in one channel """ 86 win_s, chan = 1024, 2 83 87 impulse = pi 84 f = fft(win_s )85 timegrain = fvec(win_s )86 timegrain[0] = impulse88 f = fft(win_s, chan) 89 timegrain = fvec(win_s, chan) 90 timegrain[0][0] = impulse 87 91 fftgrain = f ( timegrain ) 88 92 #self.plot_this ( fftgrain.phas ) 89 93 assert_equal ( fftgrain.phas[0], 0) 90 94 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) 92 97 93 98 def test_rdo_before_do(self): 94 99 """ check running fft.rdo before fft.do works """ 95 win_s = 1024100 win_s, chan = 1024, 2 96 101 impulse = pi 97 f = fft(win_s )98 fftgrain = cvec(win_s )102 f = fft(win_s, chan) 103 fftgrain = cvec(win_s, chan) 99 104 t = f.rdo( fftgrain ) 100 105 assert_equal ( t, 0 ) -
TabularUnified interfaces/python/test_filter.py ¶
r8212692 rf650860 1 1 from numpy.testing import TestCase, run_module_suite 2 2 from numpy.testing import assert_equal, assert_almost_equal 3 from aubio import fvec, digital_filter3 from _aubio import * 4 4 from numpy import array 5 5 … … 12 12 def test_members(self): 13 13 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]) 17 17 f(fvec()) 18 18 19 19 def test_cweighting_error(self): 20 f = digital_filter (2 )20 f = digital_filter (2, 1) 21 21 self.assertRaises ( ValueError, f.set_c_weighting, 44100 ) 22 f = digital_filter (8 )22 f = digital_filter (8, 1) 23 23 self.assertRaises ( ValueError, f.set_c_weighting, 44100 ) 24 f = digital_filter (5 )24 f = digital_filter (5, 1) 25 25 self.assertRaises ( ValueError, f.set_c_weighting, 4000 ) 26 f = digital_filter (5 )26 f = digital_filter (5, 1) 27 27 self.assertRaises ( ValueError, f.set_c_weighting, 193000 ) 28 f = digital_filter (7 )28 f = digital_filter (7, 1) 29 29 self.assertRaises ( ValueError, f.set_a_weighting, 193000 ) 30 f = digital_filter (5 )30 f = digital_filter (5, 1) 31 31 self.assertRaises ( ValueError, f.set_a_weighting, 192000 ) 32 32 33 33 def test_c_weighting(self): 34 34 expected = array_from_text_file('c_weighting_test_simple.expected') 35 f = digital_filter(5 )35 f = digital_filter(5, 1) 36 36 f.set_c_weighting(44100) 37 37 v = fvec(32) 38 v[ 12] = .538 v[0][12] = .5 39 39 u = f(v) 40 40 assert_almost_equal (expected[1], u) … … 42 42 def test_a_weighting(self): 43 43 expected = array_from_text_file('a_weighting_test_simple.expected') 44 f = digital_filter(7 )44 f = digital_filter(7, 1) 45 45 f.set_a_weighting(44100) 46 46 v = fvec(32) 47 v[ 12] = .547 v[0][12] = .5 48 48 u = f(v) 49 49 assert_almost_equal (expected[1], u) … … 51 51 def test_a_weighting_parted(self): 52 52 expected = array_from_text_file('a_weighting_test_simple.expected') 53 f = digital_filter(7 )53 f = digital_filter(7, 1) 54 54 f.set_a_weighting(44100) 55 55 v = fvec(16) 56 v[ 12] = .556 v[0][12] = .5 57 57 u = f(v) 58 58 assert_almost_equal (expected[1][:16], u) -
TabularUnified interfaces/python/test_filterbank.py ¶
r8212692 rf650860 2 2 from numpy.testing import assert_equal, assert_almost_equal 3 3 from numpy import array, shape 4 from aubio import cvec, filterbank4 from _aubio import * 5 5 6 6 class aubio_filter_test_case(TestCase): … … 11 11 a = f.get_coeffs() 12 12 a.T 13 assert_equal(shape (a), (40, 512/2 + 1) )14 13 15 14 def test_other_slaney(self): … … 24 23 #print "sum is", sum(sum(a)) 25 24 26 def test_triangle_freqs _zeros(self):25 def test_triangle_freqs(self): 27 26 f = filterbank(9, 1024) 28 27 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] … … 30 29 f.set_triangle_bands(freqs, 48000) 31 30 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) 40 32 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) 45 35 46 36 if __name__ == '__main__': -
TabularUnified interfaces/python/test_onsetdetection.py ¶
r8212692 rf650860 2 2 from numpy.testing import assert_equal, assert_almost_equal 3 3 # WARNING: numpy also has an fft object 4 from aubio import specdesc, cvec4 from _aubio import cvec, specdesc 5 5 from numpy import array, shape, arange, zeros, log 6 6 from math import pi … … 10 10 def test_members(self): 11 11 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"]) 14 17 15 18 def test_hfc(self): … … 19 22 a = arange(c.length, dtype='float32') 20 23 c.norm = a 21 assert_equal (a, c.norm )24 assert_equal (a, c.norm[0]) 22 25 assert_equal ( sum(a*(a+1)), o(c)) 23 26 … … 28 31 a = arange(c.length, dtype='float32') 29 32 c.norm = a 30 assert_equal (a, c.norm )33 assert_equal (a, c.norm[0]) 31 34 # the previous run was on zeros, so previous frames are still 0 32 35 # so we have sqrt ( abs ( r2 ^ 2) ) == r2 -
TabularUnified interfaces/python/test_phasevoc.py ¶
r8212692 rf650860 1 1 from numpy.testing import TestCase, run_module_suite 2 2 from numpy.testing import assert_equal, assert_almost_equal 3 from aubio import fvec, cvec, pvoc3 from _aubio import * 4 4 from numpy import array, shape 5 5 … … 26 26 def test_steps_two_channels(self): 27 27 """ 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) 31 31 # positive step in first channel 32 t1[ 100:200] = .132 t1[0][100:200] = .1 33 33 # positive step in second channel 34 t1[ 20:50] = -.134 t1[1][20:50] = -.1 35 35 s1 = f(t1) 36 36 r1 = f.rdo(s1) … … 42 42 def test_steps_three_random_channels(self): 43 43 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. 49 50 t2 = f.rdo(f(t1)) 50 51 t2 = f.rdo(f(t0)) -
TabularUnified src/aubio.h ¶
r8212692 rf650860 49 49 50 50 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 phase53 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 55 55 Additionally, the ::lvec_t structure can be used to store floating point 56 56 numbers in double precision. They are mostly used to store filter 57 57 coefficients, to avoid instability. 58 58 59 59 \subsection objects Available objects 60 60 … … 64 64 65 65 // fast Fourier transform (FFT) 66 aubio_fft_t *fft = new_aubio_fft (winsize );66 aubio_fft_t *fft = new_aubio_fft (winsize, channels); 67 67 // 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); 73 73 // 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); 75 75 76 76 \endcode … … 82 82 Here is a simple example that creates an A-Weighting filter and applies it to a 83 83 vector. 84 84 85 85 \code 86 86 87 // set window size, and sampling rate88 uint_t winsize = 1024, sr = 44100;87 // set channels, window size, and sampling rate 88 uint_t channels = 2, winsize = 1024, sr = 44100; 89 89 // create a vector 90 fvec_t *this_buffer = new_fvec (winsize );90 fvec_t *this_buffer = new_fvec (winsize, channels); 91 91 // 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 94 94 while (running) { 95 95 // here some code to put some data in this_buffer … … 99 99 aubio_filter_do (this_filter, this_buffer); 100 100 101 // here some code to get some data from this_buffer 101 // here some code to get some data from this_buffer 102 102 // ... 103 103 } 104 104 105 105 // and free the structures 106 106 del_aubio_filter (this_filter); … … 129 129 130 130 \section download Download 131 131 132 132 Latest versions, further documentation, examples, wiki, and mailing lists can 133 133 be found at http://aubio.org . 134 134 135 135 */ 136 136 … … 141 141 142 142 Programmers just need to include this file as: 143 143 144 144 @code 145 145 #include <aubio/aubio.h> 146 146 @endcode 147 147 148 148 */ 149 149 … … 158 158 #include "cvec.h" 159 159 #include "lvec.h" 160 #include "fmat.h"161 160 #include "musicutils.h" 162 161 #include "temporal/resampler.h" -
TabularUnified src/cvec.c ¶
r8212692 rf650860 22 22 #include "cvec.h" 23 23 24 cvec_t * new_cvec( uint_t length ) {24 cvec_t * new_cvec( uint_t length, uint_t channels) { 25 25 cvec_t * s = AUBIO_NEW(cvec_t); 26 uint_t j; 26 uint_t i,j; 27 s->channels = channels; 27 28 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 } 33 38 } 34 39 return s; … … 36 41 37 42 void 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 } 38 48 AUBIO_FREE(s->norm); 39 49 AUBIO_FREE(s->phas); … … 41 51 } 42 52 43 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position) {44 s->norm[ position] = data;53 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position) { 54 s->norm[channel][position] = data; 45 55 } 46 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position) {47 s->phas[ position] = data;56 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position) { 57 s->phas[channel][position] = data; 48 58 } 49 smpl_t cvec_read_norm(cvec_t *s, uint_t position) {50 return s->norm[ position];59 smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position) { 60 return s->norm[channel][position]; 51 61 } 52 smpl_t cvec_read_phas(cvec_t *s, uint_t position) {53 return s->phas[ position];62 smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position) { 63 return s->phas[channel][position]; 54 64 } 55 smpl_t * cvec_get_norm(cvec_t *s) { 65 void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel) { 66 s->norm[channel] = data; 67 } 68 void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel) { 69 s->phas[channel] = data; 70 } 71 smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel) { 72 return s->norm[channel]; 73 } 74 smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel) { 75 return s->phas[channel]; 76 } 77 smpl_t ** cvec_get_norm(cvec_t *s) { 56 78 return s->norm; 57 79 } 58 smpl_t * cvec_get_phas(cvec_t *s) {80 smpl_t ** cvec_get_phas(cvec_t *s) { 59 81 return s->phas; 60 82 } … … 63 85 64 86 void 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"); 69 99 } 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");76 100 } 77 101 78 102 void 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 } 82 108 } 83 109 } -
TabularUnified src/cvec.h ¶
r8212692 rf650860 39 39 typedef struct { 40 40 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] */ 43 44 } cvec_t; 44 45 … … 46 47 47 48 This function creates a cvec_t structure holding two arrays of size 48 [length/2+1] , corresponding to the norm and phase values of the49 [length/2+1] * channels, corresponding to the norm and phase values of the 49 50 spectral frame. The length stored in the structure is the actual size of both 50 51 arrays, not the length of the complex and symetrical vector, specified as … … 52 53 53 54 \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 */ 58 cvec_t * new_cvec(uint_t length, uint_t channels); 57 59 /** cvec_t buffer deletion function 58 60 … … 64 66 65 67 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 purpose68 result can be obtained by assigning vec->norm[channel][position]. Its purpose 67 69 is to access these values from wrappers, as created by swig. 68 70 69 71 \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 71 74 \param position sample position to write to 72 75 73 76 */ 74 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position);77 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position); 75 78 /** write phase value in a complex buffer 76 79 77 80 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 purpose81 result can be obtained by assigning vec->phas[channel][position]. Its purpose 79 82 is to access these values from wrappers, as created by swig. 80 83 81 84 \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 83 87 \param position sample position to write to 84 88 85 89 */ 86 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position);90 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position); 87 91 /** read norm value from a complex buffer 88 92 89 93 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 94 99 \param position sample position to read from 95 100 96 101 */ 97 smpl_t cvec_read_norm(cvec_t *s, uint_t position);102 smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position); 98 103 /** read phase value from a complex buffer 99 104 100 105 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 105 111 \param position sample position to read from 106 112 107 113 */ 108 smpl_t cvec_read_phas(cvec_t *s, uint_t position); 114 smpl_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 */ 126 void 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 */ 138 void 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 */ 149 smpl_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 */ 160 smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel); 109 161 /** read norm data from a complex buffer 110 162 … … 116 168 117 169 */ 118 smpl_t * cvec_get_norm(cvec_t *s);170 smpl_t ** cvec_get_norm(cvec_t *s); 119 171 /** read phase data from a complex buffer 120 172 … … 126 178 127 179 */ 128 smpl_t * cvec_get_phas(cvec_t *s);180 smpl_t ** cvec_get_phas(cvec_t *s); 129 181 130 182 /** print out cvec data -
TabularUnified src/fvec.c ¶
r8212692 rf650860 22 22 #include "fvec.h" 23 23 24 fvec_t * new_fvec( uint_t length ) {24 fvec_t * new_fvec( uint_t length, uint_t channels) { 25 25 fvec_t * s = AUBIO_NEW(fvec_t); 26 uint_t j; 26 uint_t i,j; 27 s->channels = channels; 27 28 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 } 31 35 } 32 36 return s; … … 34 38 35 39 void del_fvec(fvec_t *s) { 40 uint_t i; 41 for (i=0; i<s->channels; i++) { 42 AUBIO_FREE(s->data[i]); 43 } 36 44 AUBIO_FREE(s->data); 37 45 AUBIO_FREE(s); 38 46 } 39 47 40 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t position) { 41 s->data[position] = data; 48 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position) { 49 s->data[channel][position] = data; 50 } 51 smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position) { 52 return s->data[channel][position]; 53 } 54 void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel) { 55 s->data[channel] = data; 56 } 57 smpl_t * fvec_get_channel(fvec_t *s, uint_t channel) { 58 return s->data[channel]; 42 59 } 43 60 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) { 61 smpl_t ** fvec_get_data(fvec_t *s) { 49 62 return s->data; 50 63 } … … 53 66 54 67 void 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"); 58 74 } 59 AUBIO_MSG("\n");60 75 } 61 76 62 77 void 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 } 66 83 } 67 84 } … … 76 93 77 94 void 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 } 81 100 } 82 101 } 83 102 84 103 void fvec_weight(fvec_t *s, fvec_t *weight) { 85 uint_t j;104 uint_t i,j; 86 105 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 } 89 110 } 90 111 } 91 112 92 113 void 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); 94 116 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 } 95 121 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", 97 123 s->length, t->length); 98 124 } 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 } 101 129 } 102 130 } -
TabularUnified src/fvec.h ¶
r8212692 rf650860 38 38 typedef struct { 39 39 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] */ 41 42 } fvec_t; 42 43 … … 44 45 45 46 \param length the length of the buffer to create 47 \param channels the number of channels in the buffer 46 48 47 49 */ 48 fvec_t * new_fvec(uint_t length );50 fvec_t * new_fvec(uint_t length, uint_t channels); 49 51 /** fvec_t buffer deletion function 50 52 … … 56 58 57 59 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 to60 result can be obtained using vec->data[channel][position]. Its purpose is to 59 61 access these values from wrappers, as created by swig. 60 62 61 63 \param s vector to read from 64 \param channel channel to read from 62 65 \param position sample position to read from 63 66 64 67 */ 65 smpl_t fvec_read_sample(fvec_t *s, uint_t position);68 smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position); 66 69 /** write sample value in a buffer 67 70 68 71 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 purpose72 result can be obtained by assigning vec->data[channel][position]. Its purpose 70 73 is to access these values from wrappers, as created by swig. 71 74 72 75 \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 74 78 \param position sample position to write to 75 79 76 80 */ 77 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t position); 81 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position); 82 /** read channel vector from a buffer 78 83 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 */ 92 smpl_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 */ 104 void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel); 79 105 /** read data from a buffer 80 106 … … 86 112 87 113 */ 88 smpl_t * fvec_get_data(fvec_t *s);114 smpl_t ** fvec_get_data(fvec_t *s); 89 115 90 116 /** print out fvec data -
TabularUnified src/lvec.c ¶
r8212692 rf650860 22 22 #include "lvec.h" 23 23 24 lvec_t * new_lvec( uint_t length ) {24 lvec_t * new_lvec( uint_t length, uint_t channels) { 25 25 lvec_t * s = AUBIO_NEW(lvec_t); 26 uint_t j; 26 uint_t i,j; 27 s->channels = channels; 27 28 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 } 31 35 } 32 36 return s; … … 34 38 35 39 void del_lvec(lvec_t *s) { 40 uint_t i; 41 for (i=0; i<s->channels; i++) { 42 AUBIO_FREE(s->data[i]); 43 } 36 44 AUBIO_FREE(s->data); 37 45 AUBIO_FREE(s); 38 46 } 39 47 40 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position) {41 s->data[ position] = data;48 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_t position) { 49 s->data[channel][position] = data; 42 50 } 43 lsmp_t lvec_read_sample(lvec_t *s, uint_t position) { 44 return s->data[position]; 51 lsmp_t lvec_read_sample(lvec_t *s, uint_t channel, uint_t position) { 52 return s->data[channel][position]; 53 } 54 void lvec_put_channel(lvec_t *s, lsmp_t * data, uint_t channel) { 55 s->data[channel] = data; 56 } 57 lsmp_t * lvec_get_channel(lvec_t *s, uint_t channel) { 58 return s->data[channel]; 45 59 } 46 60 47 lsmp_t * lvec_get_data(lvec_t *s) {61 lsmp_t ** lvec_get_data(lvec_t *s) { 48 62 return s->data; 49 63 } … … 52 66 53 67 void 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"); 57 74 } 58 AUBIO_MSG("\n");59 75 } 60 76 61 77 void 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 } 65 83 } 66 84 } -
TabularUnified src/lvec.h ¶
r8212692 rf650860 39 39 typedef struct { 40 40 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] */ 42 43 } lvec_t; 43 44 … … 45 46 46 47 \param length the length of the buffer to create 48 \param channels the number of channels in the buffer 47 49 48 50 */ 49 lvec_t * new_lvec(uint_t length );51 lvec_t * new_lvec(uint_t length, uint_t channels); 50 52 /** lvec_t buffer deletion function 51 53 … … 57 59 58 60 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 to61 result can be obtained using vec->data[channel][position]. Its purpose is to 60 62 access these values from wrappers, as created by swig. 61 63 62 64 \param s vector to read from 65 \param channel channel to read from 63 66 \param position sample position to read from 64 67 65 68 */ 66 lsmp_t lvec_read_sample(lvec_t *s, uint_t position);69 lsmp_t lvec_read_sample(lvec_t *s, uint_t channel, uint_t position); 67 70 /** write sample value in a buffer 68 71 69 72 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 purpose73 result can be obtained by assigning vec->data[channel][position]. Its purpose 71 74 is to access these values from wrappers, as created by swig. 72 75 73 76 \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 75 79 \param position sample position to write to 76 80 77 81 */ 78 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position); 82 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_t position); 83 /** read channel vector from a buffer 79 84 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 */ 93 lsmp_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 */ 105 void lvec_put_channel(lvec_t *s, lsmp_t * data, uint_t channel); 80 106 /** read data from a buffer 81 107 … … 87 113 88 114 */ 89 lsmp_t * lvec_get_data(lvec_t *s);115 lsmp_t ** lvec_get_data(lvec_t *s); 90 116 91 117 /** print out lvec data -
TabularUnified src/mathutils.c ¶
r8212692 rf650860 46 46 new_aubio_window (char_t * window_type, uint_t size) 47 47 { 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]; 50 51 uint_t i; 51 52 aubio_window_type wintype; … … 133 134 fvec_mean (fvec_t * s) 134 135 { 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 144 smpl_t 145 fvec_mean_channel (fvec_t * s, uint_t i) 146 { 135 147 uint_t j; 136 148 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]; 140 151 return tmp / (smpl_t) (s->length); 141 152 } … … 144 155 fvec_sum (fvec_t * s) 145 156 { 146 uint_t j;157 uint_t i, j; 147 158 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 } 150 163 } 151 164 return tmp; … … 155 168 fvec_max (fvec_t * s) 156 169 { 157 uint_t j;170 uint_t i, j; 158 171 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 } 161 176 } 162 177 return tmp; … … 166 181 fvec_min (fvec_t * s) 167 182 { 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 } 172 189 } 173 190 return tmp; … … 177 194 fvec_min_elem (fvec_t * s) 178 195 { 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 } 184 203 } 185 204 return pos; … … 189 208 fvec_max_elem (fvec_t * s) 190 209 { 191 uint_t j, pos = 0;210 uint_t i, j, pos = 0; 192 211 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 } 196 217 } 197 218 return pos; … … 201 222 fvec_shift (fvec_t * s) 202 223 { 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 } 206 229 } 207 230 } … … 211 234 { 212 235 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 } 216 241 } 217 242 return energy; … … 222 247 { 223 248 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 } 227 254 } 228 255 return hfc; … … 239 266 fvec_alpha_norm (fvec_t * o, smpl_t alpha) 240 267 { 241 uint_t j;268 uint_t i, j; 242 269 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 } 245 274 } 246 275 return POW (tmp / o->length, 1. / alpha); … … 250 279 fvec_alpha_normalise (fvec_t * o, smpl_t alpha) 251 280 { 252 uint_t j;281 uint_t i, j; 253 282 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 } 256 287 } 257 288 } … … 260 291 fvec_add (fvec_t * o, smpl_t val) 261 292 { 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 } 265 298 } 266 299 } 267 300 268 301 void 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; 271 304 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); 273 306 } 274 307 } … … 276 309 smpl_t 277 310 fvec_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]; 282 315 uint_t win_length = post + pre + 1; 283 316 uint_t length = vec->length; … … 287 320 medar[k] = 0.; /* 0-padding at the beginning */ 288 321 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]; 290 323 /* the buffer is fully defined */ 291 324 } else if (pos + pre < length) { 292 325 for (k = 0; k < win_length; k++) 293 medar[k] = vec->data[ k + pos - post];326 medar[k] = vec->data[0][k + pos - post]; 294 327 /* pre part of the buffer does not exist */ 295 328 } else { 296 329 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]; 298 331 for (k = length - pos + post; k < win_length; k++) 299 332 medar[k] = 0.; /* 0-padding at the end */ 300 333 } 301 return fvec_median (tmpvec);302 } 303 304 smpl_t fvec_median (fvec_t * input) {334 return fvec_median_channel (tmpvec, i); 335 } 336 337 smpl_t fvec_median_channel (fvec_t * input, uint_t channel) { 305 338 uint_t n = input->length; 306 smpl_t * arr = (smpl_t *) input->data ;339 smpl_t * arr = (smpl_t *) input->data[channel]; 307 340 uint_t low, high ; 308 341 uint_t median; … … 353 386 } 354 387 355 smpl_t fvec_quadint (fvec_t * x, uint_t pos ) {388 smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t i) { 356 389 smpl_t s0, s1, s2; 357 390 uint_t x0 = (pos < 1) ? pos : pos - 1; 358 391 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]; 364 397 return pos + 0.5 * (s2 - s0 ) / (s2 - 2.* s1 + s0); 365 398 } 366 399 367 400 uint_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.); 372 406 return tmp; 373 407 } … … 478 512 aubio_zero_crossing_rate (fvec_t * input) 479 513 { 480 uint_t j;514 uint_t i = 0, j; 481 515 uint_t zcr = 0; 482 516 for (j = 1; j < input->length; j++) { 483 517 // previous was strictly negative 484 if (input->data[ j - 1] < 0.) {518 if (input->data[i][j - 1] < 0.) { 485 519 // current is positive or null 486 if (input->data[ j] >= 0.) {520 if (input->data[i][j] >= 0.) { 487 521 zcr += 1; 488 522 } … … 490 524 } else { 491 525 // current is strictly negative 492 if (input->data[ j] < 0.) {526 if (input->data[i][j] < 0.) { 493 527 zcr += 1; 494 528 } … … 501 535 aubio_autocorr (fvec_t * input, fvec_t * output) 502 536 { 503 uint_t i, j, length = input->length;537 uint_t i, j, k, length = input->length; 504 538 smpl_t *data, *acf; 505 539 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 } 514 550 } 515 551 } -
TabularUnified src/mathutils.h ¶
r8212692 rf650860 41 41 */ 42 42 smpl_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 */ 52 smpl_t fvec_mean_channel (fvec_t * s, uint_t i); 43 53 44 54 /** find the max of a vector … … 195 205 */ 196 206 smpl_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); 198 208 199 209 /** apply adaptive threshold to a vector … … 208 218 209 219 */ 210 void fvec_adapt_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre); 220 void fvec_adapt_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre, 221 uint_t channel); 211 222 212 223 /** returns the median of a vector … … 221 232 222 233 \param v vector to get median from 234 \param channel channel to get median from 223 235 224 236 \return the median of v 225 237 226 238 */ 227 smpl_t fvec_median (fvec_t * v);239 smpl_t fvec_median_channel (fvec_t * v, uint_t channel); 228 240 229 241 /** finds exact peak index by quadratic interpolation*/ 230 smpl_t fvec_quadint (fvec_t * x, uint_t pos );242 smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t channel); 231 243 232 244 /** Quadratic interpolation using Lagrange polynomial. -
TabularUnified src/onset/onset.c ¶
r8212692 rf650860 48 48 smpl_t isonset = 0; 49 49 smpl_t wasonset = 0; 50 uint_t i; 50 51 aubio_pvoc_do (o->pv,input, o->fftgrain); 51 52 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 }*/ 52 57 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]; 55 61 if (isonset > 0.) { 56 62 if (aubio_silence_detection(input, o->silence)==1) { … … 68 74 wasonset++; 69 75 } 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 } 72 79 return; 73 80 } … … 91 98 /* Allocate memory for an onset detection */ 92 99 aubio_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) 94 101 { 95 102 aubio_onset_t * o = AUBIO_NEW(aubio_onset_t); … … 98 105 o->minioi = 4; 99 106 o->silence = -70; 100 o->wasonset = new_fvec(1 );107 o->wasonset = new_fvec(1, channels); 101 108 o->samplerate = samplerate; 102 109 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); 105 112 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); 109 116 /*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); 112 119 }*/ 113 120 return o; -
TabularUnified src/onset/onset.h ¶
r8212692 rf650860 50 50 \param buf_size buffer size for phase vocoder 51 51 \param hop_size hop size for phase vocoder 52 \param channels number of channels 52 53 \param samplerate sampling rate of the input signal 53 54 54 55 */ 55 56 aubio_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); 57 58 58 59 /** execute onset detection -
TabularUnified src/onset/peakpicker.c ¶
r8212692 rf650860 28 28 29 29 /** function pointer to thresholding function */ 30 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input );30 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input, uint_t channel); 31 31 /** function pointer to peak-picking function */ 32 32 typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos); … … 69 69 fvec_t *scratch; 70 70 71 /** number of channels to analyse */ 72 uint_t channels; 73 71 74 /** \bug should be used to calculate filter coefficients */ 72 75 /* cutoff: low-pass filter cutoff [0.34, 1] */ … … 94 97 smpl_t mean = 0., median = 0.; 95 98 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]; 103 110 } 104 onset_keep->data[length - 1] = onset->data[0];105 onset_proc->data[length - 1] = onset->data[0];106 111 107 112 /* filter onset_proc */ … … 109 114 aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch); 110 115 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 } 128 135 } 129 136 } … … 166 173 167 174 aubio_peakpicker_t * 168 new_aubio_peakpicker ( )175 new_aubio_peakpicker (uint_t channels) 169 176 { 170 177 aubio_peakpicker_t *t = AUBIO_NEW (aubio_peakpicker_t); … … 172 179 t->win_post = 5; 173 180 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); */ 176 185 t->pickerfn = (aubio_pickerfn_t) (fvec_peakpick); 177 186 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); 183 192 184 193 /* cutoff: low-pass filter with cutoff reduced frequency at 0.34 … … 186 195 */ 187 196 t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789, 188 -0.59488894, 0.23484048 );197 -0.59488894, 0.23484048, channels); 189 198 190 199 return t; -
TabularUnified src/onset/peakpicker.h ¶
r8212692 rf650860 36 36 37 37 /** peak-picker creation function */ 38 aubio_peakpicker_t * new_aubio_peakpicker( void);38 aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels); 39 39 /** real time peak picking function */ 40 40 void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out); -
TabularUnified src/pitch/pitch.c ¶
r8212692 rf650860 114 114 aubio_pitch_t * 115 115 new_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) 117 117 { 118 118 aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t); … … 142 142 switch (p->type) { 143 143 case aubio_pitcht_yin: 144 p->buf = new_fvec (bufsize );144 p->buf = new_fvec (bufsize, channels); 145 145 p->yin = new_aubio_pitchyin (bufsize); 146 146 p->callback = aubio_pitch_do_yin; … … 148 148 break; 149 149 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); 154 154 p->callback = aubio_pitch_do_mcomb; 155 155 break; 156 156 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); 159 159 p->callback = aubio_pitch_do_fcomb; 160 160 break; 161 161 case aubio_pitcht_schmitt: 162 p->buf = new_fvec (bufsize );162 p->buf = new_fvec (bufsize, channels); 163 163 p->schmitt = new_aubio_pitchschmitt (bufsize); 164 164 p->callback = aubio_pitch_do_schmitt; 165 165 break; 166 166 case aubio_pitcht_yinfft: 167 p->buf = new_fvec (bufsize );167 p->buf = new_fvec (bufsize, channels); 168 168 p->yinfft = new_aubio_pitchyinfft (bufsize); 169 169 p->callback = aubio_pitch_do_yinfft; … … 211 211 aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf) 212 212 { 213 uint_t j = 0, overlap_size = 0;213 uint_t i, j = 0, overlap_size = 0; 214 214 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 } 220 224 } 221 225 } … … 279 283 aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf) 280 284 { 285 uint_t i; 281 286 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 } 283 290 } 284 291 … … 286 293 aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf) 287 294 { 295 uint_t i; 288 296 aubio_filter_do (p->filter, ibuf); 289 297 aubio_pvoc_do (p->pv, ibuf, p->fftgrain); 290 298 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 } 292 302 } 293 303 … … 296 306 { 297 307 smpl_t pitch = 0.; 308 uint_t i; 298 309 aubio_pitch_slideblock (p, ibuf); 299 310 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 } 307 320 } 308 321 … … 312 325 { 313 326 smpl_t pitch = 0.; 327 uint_t i; 314 328 aubio_pitch_slideblock (p, ibuf); 315 329 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 } 323 339 } 324 340 … … 326 342 aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out) 327 343 { 344 uint_t i; 328 345 aubio_pitch_slideblock (p, ibuf); 329 346 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 } 331 350 } 332 351 … … 335 354 { 336 355 smpl_t period, pitch = 0.; 356 uint_t i; 337 357 aubio_pitch_slideblock (p, ibuf); 338 358 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 41 41 42 42 \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] 45 45 46 46 */ … … 67 67 \param buf_size size of the input buffer to analyse 68 68 \param hop_size step size between two consecutive analysis instant 69 \param channels number of channels to analyse 69 70 \param samplerate sampling rate of the signal 70 71 71 72 */ 72 73 aubio_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); 74 75 75 76 /** set the output unit of the pitch detection object -
TabularUnified src/pitch/pitchfcomb.c ¶
r8212692 rf650860 49 49 50 50 aubio_pitchfcomb_t * 51 new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize )51 new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize, uint_t channels) 52 52 { 53 53 aubio_pitchfcomb_t *p = AUBIO_NEW (aubio_pitchfcomb_t); 54 54 p->fftSize = bufsize; 55 55 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); 60 60 p->win = new_aubio_window ("hanning", bufsize); 61 61 return p; … … 66 66 aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output) 67 67 { 68 uint_t k, l, maxharm = 0;68 uint_t i, k, l, maxharm = 0; 69 69 smpl_t phaseDifference = TWO_PI * (smpl_t) p->stepSize / (smpl_t) p->fftSize; 70 70 aubio_fpeak_t peaks[MAX_PEAKS]; 71 71 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++) { 76 73 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 } 81 78 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); 87 83 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; 91 89 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; 94 93 95 /* map delta phase into +/- Pi interval*/96 tmp = aubio_unwrap2pi (tmp);94 /* subtract expected phase difference */ 95 tmp -= (smpl_t) k *phaseDifference; 97 96 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); 100 99 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); 103 102 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 } 108 111 } 109 }110 112 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 } 120 123 } 121 124 } 122 125 } 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.; 123 130 } 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.;128 131 } 129 132 -
TabularUnified src/pitch/pitchfcomb.h ¶
r8212692 rf650860 57 57 \param buf_size size of the input buffer to analyse 58 58 \param hop_size step size between two consecutive analysis instant 59 \param channels number of channels to detect pitch on 59 60 60 61 */ 61 aubio_pitchfcomb_t *new_aubio_pitchfcomb (uint_t buf_size, uint_t hop_size); 62 aubio_pitchfcomb_t *new_aubio_pitchfcomb (uint_t buf_size, uint_t hop_size, 63 uint_t channels); 62 64 63 65 /** deletion of the pitch detection object -
TabularUnified src/pitch/pitchmcomb.c ¶
r8212692 rf650860 104 104 aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output) 105 105 { 106 uint_t j;106 uint_t i, j; 107 107 smpl_t instfreq; 108 108 fvec_t *newmag = (fvec_t *) p->newmag; 109 109 //smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta; 110 110 /* 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 } 134 136 } 135 137 … … 137 139 aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands) 138 140 { 139 uint_t j;141 uint_t i = 0, j; 140 142 uint_t k; 141 143 fvec_t *newmag = (fvec_t *) p->newmag; … … 145 147 /* copy incoming grain to newmag */ 146 148 for (j = 0; j < newmag->length; j++) 147 newmag->data[ j] = fftgrain->norm[j];149 newmag->data[i][j] = fftgrain->norm[i][j]; 148 150 /* detect only if local energy > 10. */ 149 151 if (fvec_local_energy (newmag) > 10.) { … … 170 172 fvec_t *mag = (fvec_t *) p->scratch; 171 173 fvec_t *tmp = (fvec_t *) p->scratch2; 172 uint_t j;174 uint_t i = 0, j; 173 175 uint_t length = mag->length; 174 176 /* copy newmag to mag (scracth) */ 175 177 for (j = 0; j < length; j++) { 176 mag->data[ j] = newmag->data[j];178 mag->data[i][j] = newmag->data[i][j]; 177 179 } 178 180 fvec_min_removal (mag); /* min removal */ … … 180 182 /* skipped *//* low pass filtering */ 181 183 /** \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 */ 183 185 fvec_add (mag, -p->threshold); /* fixed threshold */ 184 186 { … … 188 190 count = aubio_pitchmcomb_quadpick (peaks, mag); 189 191 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]; 191 193 /* reset non peaks */ 192 194 for (j = count; j < length; j++) … … 259 261 candidate[l]->ecomb[k] = peaks[position].ebin; 260 262 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)], 262 264 0.25); 263 265 candidate[l]->len += 1. / curlen; … … 288 290 aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, fvec_t * X) 289 291 { 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 } 299 302 return count; 300 303 } … … 361 364 362 365 aubio_pitchmcomb_t * 363 new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize )366 new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize, uint_t channels) 364 367 { 365 368 aubio_pitchmcomb_t *p = AUBIO_NEW (aubio_pitchmcomb_t); … … 383 386 //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348); 384 387 /* allocate temp memory */ 385 p->newmag = new_fvec (spec_size );388 p->newmag = new_fvec (spec_size, 1); 386 389 /* array for median */ 387 p->scratch = new_fvec (spec_size );390 p->scratch = new_fvec (spec_size, 1); 388 391 /* array for phase */ 389 p->theta = new_fvec (spec_size );392 p->theta = new_fvec (spec_size, channels); 390 393 /* 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); 392 395 /* array of spectral peaks */ 393 396 p->peaks = AUBIO_ARRAY (aubio_spectralpeak_t, spec_size); -
TabularUnified src/pitch/pitchmcomb.h ¶
r8212692 rf650860 57 57 \param buf_size size of the input buffer to analyse 58 58 \param hop_size step size between two consecutive analysis instant 59 \param channels number of channels to analyse 59 60 \param samplerate sampling rate of the signal 60 61 61 62 */ 62 aubio_pitchmcomb_t *new_aubio_pitchmcomb (uint_t buf_size, uint_t hop_size); 63 aubio_pitchmcomb_t *new_aubio_pitchmcomb (uint_t buf_size, uint_t hop_size, 64 uint_t channels); 63 65 64 66 /** deletion of the pitch detection object -
TabularUnified src/pitch/pitchschmitt.c ¶
r8212692 rf650860 51 51 fvec_t * output) 52 52 { 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); 56 59 } 57 output->data[0] = aubio_schmittS16LE (p, input->length, p->buf);58 60 } 59 61 -
TabularUnified src/pitch/pitchyin.c ¶
r8212692 rf650860 65 65 { 66 66 aubio_pitchyin_t *o = AUBIO_NEW (aubio_pitchyin_t); 67 o->yin = new_fvec (bufsize / 2 );67 o->yin = new_fvec (bufsize / 2, 1); 68 68 o->tol = 0.15; 69 69 return o; … … 81 81 aubio_pitchyin_diff (fvec_t * input, fvec_t * yin) 82 82 { 83 uint_t j, tau;83 uint_t c, j, tau; 84 84 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 } 92 94 } 93 95 } … … 98 100 aubio_pitchyin_getcum (fvec_t * yin) 99 101 { 100 uint_t tau;102 uint_t c, tau; 101 103 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"); 109 114 } 110 //AUBIO_DBG("\n");111 115 } 112 116 … … 114 118 aubio_pitchyin_getpitch (fvec_t * yin) 115 119 { 116 uint_t tau = 1;120 uint_t c = 0, tau = 1; 117 121 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]) { 120 124 tau++; 121 125 } … … 135 139 smpl_t tol = o->tol; 136 140 fvec_t *yin = o->yin; 137 uint_t j, tau = 0;141 uint_t c, j, tau = 0; 138 142 sint_t period; 139 143 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 } 146 160 } 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; 155 164 } 156 out->data[0] = fvec_quadint (yin, fvec_min_elem (yin)); 157 beach: 158 return; 165 //return 0; 159 166 } 160 167 -
TabularUnified src/pitch/pitchyinfft.c ¶
r8212692 rf650860 56 56 { 57 57 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); 64 64 p->tol = 0.85; 65 65 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])); 73 93 } 74 a0 = weight[j - 1];75 f0 = freqs[j - 1];76 a1 = weight[j];77 f1 = freqs[j];78 if (f0 == f1) { // just in case79 p->weight->data[i] = a0;80 } else if (f0 == 0) { // y = ax+b81 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]));92 94 } 93 95 return p; … … 97 99 aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output) 98 100 { 99 uint_t tau, l;101 uint_t i, tau, l; 100 102 uint_t halfperiod; 101 103 smpl_t tmp, sum; 102 104 cvec_t *res = (cvec_t *) p->res; 103 105 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 } 141 152 } 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.; 148 154 } 149 } else {150 output->data[0] = 0.;151 155 } 152 156 } -
TabularUnified src/spectral/fft.c ¶
r8212692 rf650860 75 75 struct _aubio_fft_t { 76 76 uint_t winsize; 77 uint_t channels; 77 78 uint_t fft_size; 78 79 real_t *in, *out; … … 82 83 }; 83 84 84 aubio_fft_t * new_aubio_fft(uint_t winsize ) {85 aubio_fft_t * new_aubio_fft(uint_t winsize, uint_t channels) { 85 86 aubio_fft_t * s = AUBIO_NEW(aubio_fft_t); 86 87 uint_t i; 87 88 s->winsize = winsize; 89 s->channels = channels; 88 90 /* allocate memory */ 89 91 s->in = AUBIO_ARRAY(real_t,winsize); 90 92 s->out = AUBIO_ARRAY(real_t,winsize); 91 s->compspec = new_fvec(winsize );93 s->compspec = new_fvec(winsize,channels); 92 94 /* create plans */ 93 95 #ifdef HAVE_COMPLEX_H … … 134 136 135 137 void 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 } 153 157 } 154 158 155 159 void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) { 156 uint_t j;160 uint_t i, j; 157 161 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 } 173 179 } 174 180 } … … 185 191 186 192 void 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 } 201 209 } 202 210 } 203 211 204 212 void 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 } 213 223 } 214 224 215 225 void 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 } 220 232 } 221 233 } 222 234 223 235 void 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 45 45 46 46 \param size length of the FFT 47 \param channels number of channels 47 48 48 49 */ 49 aubio_fft_t * new_aubio_fft (uint_t size);50 aubio_fft_t * new_aubio_fft(uint_t size, uint_t channels); 50 51 /** delete FFT object 51 52 -
TabularUnified src/spectral/filterbank.c ¶
r8212692 rf650860 22 22 #include "aubio_priv.h" 23 23 #include "fvec.h" 24 #include "fmat.h"25 24 #include "cvec.h" 26 25 #include "spectral/filterbank.h" … … 32 31 uint_t win_s; 33 32 uint_t n_filters; 34 f mat_t *filters;33 fvec_t *filters; 35 34 }; 36 35 … … 43 42 fb->n_filters = n_filters; 44 43 45 /* allocate filter tables, a matrix of length win_s and of height n_filters*/46 fb->filters = new_f mat(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); 47 46 48 47 return fb; … … 52 51 del_aubio_filterbank (aubio_filterbank_t * fb) 53 52 { 54 del_f mat(fb->filters);53 del_fvec (fb->filters); 55 54 AUBIO_FREE (fb); 56 55 } … … 59 58 aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out) 60 59 { 61 uint_t j, fn;60 uint_t i, j, fn; 62 61 63 62 /* apply filter to all input channel, provided out has enough channels */ 63 uint_t max_channels = MIN (in->channels, out->channels); 64 64 uint_t max_filters = MIN (f->n_filters, out->length); 65 65 uint_t max_length = MIN (in->length, f->filters->length); … … 68 68 fvec_zeros (out); 69 69 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++) { 72 72 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 } 76 80 } 77 81 } … … 80 84 } 81 85 82 f mat_t *86 fvec_t * 83 87 aubio_filterbank_get_coeffs (aubio_filterbank_t * f) 84 88 { … … 87 91 88 92 uint_t 89 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, f mat_t * filter_coeffs)93 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fvec_t * filters) 90 94 { 91 f mat_copy(filter_coeffs, f->filters);95 fvec_copy(filters, f->filters); 92 96 return 0; 93 97 } -
TabularUnified src/spectral/filterbank.h ¶
r8212692 rf650860 63 63 void aubio_filterbank_do (aubio_filterbank_t * fb, cvec_t * in, fvec_t * out); 64 64 65 /** return a pointer to the matrixobject containing all filter coefficients65 /** return a pointer to the fvec object containing all filter coefficients 66 66 67 67 \param f filterbank object to get coefficients from 68 68 69 69 */ 70 f mat_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f);70 fvec_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f); 71 71 72 72 /** copy filter coefficients to the filterbank … … 76 76 77 77 */ 78 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, f mat_t * filters);78 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fvec_t * filters); 79 79 80 80 #ifdef __cplusplus -
TabularUnified src/spectral/filterbank_mel.c ¶
r8212692 rf650860 21 21 22 22 #include "aubio_priv.h" 23 #include "fmat.h"24 23 #include "fvec.h" 25 24 #include "cvec.h" … … 32 31 { 33 32 34 f mat_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; 36 35 37 36 uint_t fn; /* filter counter */ … … 50 49 } 51 50 52 if (freqs->data[ freqs->length - 1] > samplerate / 2) {51 if (freqs->data[0][freqs->length - 1] > samplerate / 2) { 53 52 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]); 55 54 } 56 55 57 56 /* 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); 61 60 62 61 /* height of each triangle */ 63 fvec_t *triangle_heights = new_fvec (n_filters );62 fvec_t *triangle_heights = new_fvec (n_filters, 1); 64 63 65 64 /* 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); 67 66 68 67 /* fill up the lower/center/upper */ 69 68 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]; 73 72 } 74 73 75 74 /* compute triangle heights so that each triangle has unit area */ 76 75 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]); 79 78 } 80 79 81 80 /* fill fft_freqs lookup table, which assigns the frequency in hz to each bin */ 82 81 for (bin = 0; bin < win_s; bin++) { 83 fft_freqs->data[ bin] =82 fft_freqs->data[0][bin] = 84 83 aubio_bintofreq (bin, samplerate, (win_s - 1) * 2); 85 84 } 86 85 87 86 /* zeroing of all filters */ 88 f mat_zeros (filters);87 fvec_zeros (filters); 89 88 90 if (fft_freqs->data[ 1] >= lower_freqs->data[0]) {89 if (fft_freqs->data[0][1] >= lower_freqs->data[0][0]) { 91 90 /* - 1 to make sure we don't miss the smallest power of two */ 92 91 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; 94 93 AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \ 95 94 band (%.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, 98 97 aubio_next_power_of_two (min_win_s)); 99 98 } … … 104 103 /* skip first elements */ 105 104 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]) { 108 107 bin++; 109 108 break; … … 113 112 /* compute positive slope step size */ 114 113 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]); 117 116 118 117 /* compute coefficients in positive slope */ 119 118 for (; bin < win_s - 1; bin++) { 120 119 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; 122 121 123 if (fft_freqs->data[ bin + 1] >= center_freqs->data[fn]) {122 if (fft_freqs->data[0][bin + 1] >= center_freqs->data[0][fn]) { 124 123 bin++; 125 124 break; … … 129 128 /* compute negative slope step size */ 130 129 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]); 133 132 134 133 /* compute coefficents in negative slope */ 135 134 for (; bin < win_s - 1; bin++) { 136 135 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; 138 137 139 138 if (filters->data[fn][bin] < 0.) { … … 141 140 } 142 141 143 if (fft_freqs->data[ bin + 1] >= upper_freqs->data[fn])142 if (fft_freqs->data[0][bin + 1] >= upper_freqs->data[0][fn]) 144 143 break; 145 144 } … … 177 176 178 177 /* buffers to compute filter frequencies */ 179 fvec_t *freqs = new_fvec (n_filters + 2 );178 fvec_t *freqs = new_fvec (n_filters + 2, 1); 180 179 181 180 /* first step: fill all the linear filter frequencies */ 182 181 for (fn = 0; fn < linearFilters; fn++) { 183 freqs->data[ fn] = lowestFrequency + fn * linearSpacing;182 freqs->data[0][fn] = lowestFrequency + fn * linearSpacing; 184 183 } 185 smpl_t lastlinearCF = freqs->data[ fn - 1];184 smpl_t lastlinearCF = freqs->data[0][fn - 1]; 186 185 187 186 /* second step: fill all the log filter frequencies */ 188 187 for (fn = 0; fn < logFilters + 2; fn++) { 189 freqs->data[ fn + linearFilters] =188 freqs->data[0][fn + linearFilters] = 190 189 lastlinearCF * (POW (logSpacing, fn + 1)); 191 190 } -
TabularUnified src/spectral/mfcc.c ¶
r8212692 rf650860 22 22 #include "aubio_priv.h" 23 23 #include "fvec.h" 24 #include "fmat.h"25 24 #include "cvec.h" 26 25 #include "mathutils.h" … … 41 40 aubio_filterbank_t *fb; /** filter bank */ 42 41 fvec_t *in_dct; /** input buffer for dct * [fb->n_filters] */ 43 f mat_t *dct_coeffs; /** DCT transform n_filters * n_coeffs */42 fvec_t *dct_coeffs; /** DCT transform n_filters * n_coeffs */ 44 43 }; 45 44 … … 65 64 66 65 /* allocating buffers */ 67 mfcc->in_dct = new_fvec (n_filters );66 mfcc->in_dct = new_fvec (n_filters, 1); 68 67 69 mfcc->dct_coeffs = new_f mat(n_coefs, n_filters);68 mfcc->dct_coeffs = new_fvec (n_coefs, n_filters); 70 69 71 70 /* compute DCT transform dct_coeffs[i][j] as … … 101 100 aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out) 102 101 { 103 uint_t j, k;102 uint_t i, j, k; 104 103 105 104 /* compute filterbank */ … … 116 115 117 116 /* 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 } 122 123 } 123 124 } -
TabularUnified src/spectral/phasevoc.c ¶
r8212692 rf650860 30 30 uint_t win_s; /** grain length */ 31 31 uint_t hop_s; /** overlap step */ 32 uint_t channels; /** number of channels */ 32 33 aubio_fft_t * fft; /** fft object */ 33 34 fvec_t * synth; /** cur output grain [win_s] */ … … 48 49 49 50 void 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 } 53 57 /* windowing */ 54 58 fvec_weight(pv->data, pv->w); … … 60 64 61 65 void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) { 66 uint_t i; 62 67 /* calculate rfft */ 63 68 aubio_fft_rdo(pv->fft,fftgrain,pv->synth); 64 69 /* unshift */ 65 70 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 } 68 75 } 69 76 70 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s ) {77 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) { 71 78 aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t); 72 79 … … 81 88 } 82 89 83 pv->fft = new_aubio_fft (win_s);90 pv->fft = new_aubio_fft(win_s,channels); 84 91 85 92 /* 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); 88 95 89 96 /* 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); 92 99 pv->w = new_aubio_window ("hanningz", win_s); 93 100 101 pv->channels = channels; 94 102 pv->hop_s = hop_s; 95 103 pv->win_s = win_s; -
TabularUnified src/spectral/phasevoc.h ¶
r8212692 rf650860 26 26 using a HanningZ window and a swapped version of the signal to simplify the 27 27 phase relationships across frames. The window sizes and overlap are specified 28 at creation time. 28 at creation time. Multiple channels are fully supported. 29 29 30 30 */ … … 44 44 \param win_s size of analysis buffer (and length the FFT transform) 45 45 \param hop_s step size between two consecutive analysis 46 \param channels number of channels 46 47 47 48 */ 48 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s );49 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels); 49 50 /** delete phase vocoder object 50 51 … … 56 57 /** compute spectral frame 57 58 58 This function accepts an input vector of size [ hop_s]. The59 This function accepts an input vector of size [channels]x[hop_s]. The 59 60 analysis buffer is rotated and filled with the new data. After windowing of 60 61 this signal window, the Fourier transform is computed and returned in … … 70 71 71 72 This function takes an input spectral frame fftgrain of size 72 [ buf_s] and computes its inverse Fourier transform. Overlap-add73 [channels]x[buf_s] and computes its inverse Fourier transform. Overlap-add 73 74 synthesis is then computed using the previously synthetised frames, and the 74 75 output stored in out. … … 93 94 */ 94 95 uint_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 */ 101 uint_t aubio_pvoc_get_channels(aubio_pvoc_t* pv); 95 102 96 103 #ifdef __cplusplus -
TabularUnified src/spectral/specdesc.c ¶
r8212692 rf650860 89 89 void aubio_specdesc_energy (aubio_specdesc_t *o UNUSED, 90 90 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 } 95 97 } 96 98 } … … 99 101 void aubio_specdesc_hfc(aubio_specdesc_t *o UNUSED, 100 102 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 } 105 109 } 106 110 } … … 109 113 /* Complex Domain Method onset detection function */ 110 114 void aubio_specdesc_complex (aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset) { 111 uint_t j;115 uint_t i, j; 112 116 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 } 128 134 } 129 135 } … … 133 139 void aubio_specdesc_phase(aubio_specdesc_t *o, 134 140 cvec_t * fftgrain, fvec_t * onset){ 135 uint_t j;141 uint_t i, j; 136 142 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 } 160 168 } 161 169 … … 163 171 void aubio_specdesc_specdiff(aubio_specdesc_t *o, 164 172 cvec_t * fftgrain, fvec_t * onset){ 165 uint_t j;173 uint_t i, j; 166 174 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; 168 177 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]); 174 183 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]; 177 186 } 178 187 … … 183 192 aubio_hist_weight(o->histog); 184 193 /* 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 } 186 197 } 187 198 … … 190 201 * negative (1.+) and infinite values (+1.e-10) */ 191 202 void 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.; 194 206 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 } 200 213 } 201 214 … … 204 217 * negative (1.+) and infinite values (+1.e-10) */ 205 218 void 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.; 208 222 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 } 213 228 } 214 229 215 230 /* Spectral flux */ 216 231 void 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 } 223 240 } 224 241 } … … 235 252 */ 236 253 aubio_specdesc_t * 237 new_aubio_specdesc (char_t * onset_mode, uint_t size){ 254 new_aubio_specdesc (char_t * onset_mode, 255 uint_t size, uint_t channels){ 238 256 aubio_specdesc_t * o = AUBIO_NEW(aubio_specdesc_t); 239 257 uint_t rsize = size/2+1; … … 285 303 /* the other approaches will need some more memory spaces */ 286 304 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); 291 309 break; 292 310 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); 297 315 o->threshold = 0.1; 298 316 break; 299 317 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); 303 321 o->threshold = 0.1; 304 322 break; … … 306 324 case aubio_onset_mkl: 307 325 case aubio_onset_specflux: 308 o->oldmag = new_fvec(rsize );326 o->oldmag = new_fvec(rsize,channels); 309 327 break; 310 328 default: -
TabularUnified src/spectral/specdesc.h ¶
r8212692 rf650860 25 25 All of the following spectral description functions take as arguments the FFT 26 26 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]). 28 28 29 29 A list of the spectral description methods currently available follows. … … 168 168 \param method spectral description method 169 169 \param buf_size length of the input spectrum frame 170 \param channels number of input channels 170 171 171 172 */ 172 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size); 173 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size, 174 uint_t channels); 173 175 174 176 /** deletion of a spectral descriptor -
TabularUnified src/spectral/statistics.c ¶
r8212692 rf650860 24 24 25 25 smpl_t 26 cvec_sum (cvec_t * s)26 cvec_sum_channel (cvec_t * s, uint_t i) 27 27 { 28 28 uint_t j; 29 29 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]; 33 32 return tmp; 34 33 } 35 34 36 35 smpl_t 37 cvec_mean (cvec_t * s)36 cvec_mean_channel (cvec_t * s, uint_t i) 38 37 { 39 return cvec_sum (s) / (smpl_t) (s->length);38 return cvec_sum_channel(s, i) / (smpl_t) (s->length); 40 39 } 41 40 42 41 smpl_t 43 cvec_centroid (cvec_t * spec)42 cvec_centroid_channel (cvec_t * spec, uint_t i) 44 43 { 45 44 smpl_t sum = 0., sc = 0.; 46 45 uint_t j; 47 sum = cvec_sum (spec);46 sum = cvec_sum_channel (spec, i); 48 47 if (sum == 0.) { 49 48 return 0.; 50 49 } else { 51 50 for (j = 0; j < spec->length; j++) { 52 sc += (smpl_t) j *spec->norm[ j];51 sc += (smpl_t) j *spec->norm[i][j]; 53 52 } 54 53 return sc / sum; … … 57 56 58 57 smpl_t 59 cvec_moment (cvec_t * spec, uint_t order)58 cvec_moment_channel (cvec_t * spec, uint_t i, uint_t order) 60 59 { 61 60 smpl_t sum = 0., centroid = 0., sc = 0.; 62 61 uint_t j; 63 sum = cvec_sum (spec);62 sum = cvec_sum_channel (spec, i); 64 63 if (sum == 0.) { 65 64 return 0.; 66 65 } else { 67 centroid = cvec_centroid (spec);66 centroid = cvec_centroid_channel (spec, i); 68 67 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]; 70 69 } 71 70 return sc / sum; … … 77 76 fvec_t * desc) 78 77 { 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 } 80 82 } 81 83 … … 84 86 fvec_t * desc) 85 87 { 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 } 87 92 } 88 93 … … 91 96 fvec_t * desc) 92 97 { 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 } 100 107 } 101 108 } … … 105 112 fvec_t * desc) 106 113 { 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 } 114 123 } 115 124 } … … 119 128 fvec_t * desc) 120 129 { 121 uint_t j;130 uint_t i, j; 122 131 smpl_t norm = 0, sum = 0.; 123 132 // compute N * sum(j**2) - sum(j)**2 … … 128 137 // sum_0^N(j) = length * (length + 1) / 2 129 138 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; 137 152 } 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;142 153 } 143 154 } … … 147 158 fvec_t * desc) 148 159 { 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; 158 172 } 159 desc->data[0] /= sum;160 173 } 161 174 } … … 165 178 fvec_t *desc) 166 179 { 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]); 180 185 } 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 } 182 197 } 183 198 } -
TabularUnified src/spectral/tss.c ¶
r8212692 rf650860 44 44 cvec_t * trans, cvec_t * stead) 45 45 { 46 uint_t j;46 uint_t i,j; 47 47 uint_t test; 48 48 uint_t nbins = input->length; 49 uint_t channels = input->channels; 49 50 smpl_t alpha = o->alpha; 50 51 smpl_t beta = o->beta; 51 52 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; 57 58 /* 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 } 64 66 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 } 71 73 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; 77 79 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 } 91 94 } 92 95 } … … 98 101 } 99 102 100 aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size )103 aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size, uint_t channels) 101 104 { 102 105 aubio_tss_t * o = AUBIO_NEW(aubio_tss_t); … … 107 110 o->beta = 4.; 108 111 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); 114 117 return o; 115 118 } -
TabularUnified src/spectral/tss.h ¶
r8212692 rf650860 49 49 \param buf_size buffer size 50 50 \param hop_size step size 51 \param channels number of input channels 51 52 52 53 */ 53 aubio_tss_t *new_aubio_tss (uint_t buf_size, uint_t hop_size );54 aubio_tss_t *new_aubio_tss (uint_t buf_size, uint_t hop_size, uint_t channels); 54 55 55 56 /** delete tss object -
TabularUnified src/tempo/beattracking.c ¶
r8212692 rf650860 55 55 56 56 aubio_beattracking_t * 57 new_aubio_beattracking (uint_t winlen )57 new_aubio_beattracking (uint_t winlen, uint_t channels) 58 58 { 59 59 … … 79 79 p->rayparam = rayparam; 80 80 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); 89 89 90 90 p->timesig = 0; … … 92 92 /* exponential weighting, dfwv = 0.5 when i = 43 */ 93 93 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))) 95 95 / dfwvnorm; 96 96 } 97 97 98 98 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)) * 100 100 EXP ((-SQR ((smpl_t) (i + 1.)) / (2. * SQR ((smpl_t) rayparam)))); 101 101 } … … 161 161 for (a = 1; a <= numelem; a++) { 162 162 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] 164 164 * 1. / (2. * a - 1.); 165 165 } … … 171 171 /* find non-zero Rayleigh period */ 172 172 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; 174 174 //rp = (maxindex==127) ? 43 : maxindex; //rayparam 175 175 bt->rp = (maxindex == bt->acfout->length - 1) ? bt->rayparam : maxindex; //rayparam … … 191 191 for (i = 0; i < bp; i++) { 192 192 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)]; 194 194 } 195 195 } … … 204 204 phase = step - bt->lastbeat; 205 205 } else { 206 phase = fvec_quadint (bt->phout, maxindex );206 phase = fvec_quadint (bt->phout, maxindex, 0); 207 207 } 208 208 /* take back one frame delay */ … … 237 237 if (beat >= 0) { 238 238 //AUBIO_DBG ("beat: %d, %f, %f\n", i, bp, beat); 239 output->data[ i] = beat;239 output->data[0][i] = beat; 240 240 i++; 241 241 } … … 244 244 beat += bp; 245 245 //AUBIO_DBG ("beat: %d, %f, %f\n", i, bp, beat); 246 output->data[ i] = beat;246 output->data[0][i] = beat; 247 247 i++; 248 248 } … … 250 250 bt->lastbeat = beat; 251 251 /* store the number of beats in this frame as the first element */ 252 output->data[0] = i;252 output->data[0][0] = i; 253 253 } 254 254 … … 260 260 if (acflen > 6 * gp + 2) { 261 261 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]; 264 264 } 265 265 } else { 266 266 /*Expanded to be more accurate in time sig estimation */ 267 267 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]; 270 270 } 271 271 } … … 301 301 for (a = 1; a <= bt->timesig; a++) { 302 302 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]; 304 304 } 305 305 } 306 306 } 307 307 fvec_weight (acfout, bt->gwv); 308 gp = fvec_quadint (acfout, fvec_max_elem (acfout) );308 gp = fvec_quadint (acfout, fvec_max_elem (acfout), 0); 309 309 /* 310 310 while(gp<32) gp =gp*2; … … 351 351 bt->timesig = fvec_gettimesig (acf, acflen, gp); 352 352 for (j = 0; j < laglen; j++) 353 bt->gwv->data[ j] =353 bt->gwv->data[0][j] = 354 354 EXP (-.5 * SQR ((smpl_t) (j + 1. - gp)) / SQR (bt->g_var)); 355 355 flagconst = 0; … … 363 363 if (step > bt->lastbeat) { 364 364 for (j = 0; j < 2 * laglen; j++) { 365 bt->phwv->data[ j] =365 bt->phwv->data[0][j] = 366 366 EXP (-.5 * SQR ((smpl_t) (1. + j - step + 367 367 bt->lastbeat)) / (bp / 8.)); … … 410 410 { 411 411 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); 413 413 } else { 414 414 return 0.; -
TabularUnified src/tempo/beattracking.h ¶
r8212692 rf650860 48 48 49 49 \param hop_size number of onset detection samples [512] 50 \param channels number (not functionnal) [1] 50 51 51 52 */ 52 aubio_beattracking_t * new_aubio_beattracking(uint_t hop_size );53 aubio_beattracking_t * new_aubio_beattracking(uint_t hop_size, uint_t channels); 53 54 54 55 /** track the beat -
TabularUnified src/tempo/tempo.c ¶
r8212692 rf650860 59 59 /*if (usedoubled) { 60 60 aubio_specdesc_do(o2,fftgrain, onset2); 61 onset->data[0] *= onset2->data[0];61 onset->data[0][0] *= onset2->data[0][0]; 62 62 }*/ 63 63 /* execute every overlap_size*step */ … … 67 67 /* rotate dfframe */ 68 68 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]; 70 70 for (i = winlen - step ; i < winlen; i++ ) 71 o->dfframe->data[ i] = 0.;71 o->dfframe->data[0][i] = 0.; 72 72 o->blockpos = -1; 73 73 } 74 74 o->blockpos++; 75 75 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]; 77 77 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]; 79 79 /* end of second level loop */ 80 tempo->data[0] = 0; /* reset tactus */80 tempo->data[0][0] = 0; /* reset tactus */ 81 81 i=0; 82 for (i = 1; i < o->out->data[0] ; i++ ) {82 for (i = 1; i < o->out->data[0][0]; i++ ) { 83 83 /* 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 */ 86 86 /* test for silence */ 87 87 if (aubio_silence_detection(input, o->silence)==1) { 88 tempo->data[ 1] = 0; /* unset onset */88 tempo->data[0][1] = 0; /* unset onset */ 89 89 } 90 90 } … … 105 105 /* Allocate memory for an tempo detection */ 106 106 aubio_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) 108 108 { 109 109 aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t); … … 115 115 o->silence = -90.; 116 116 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); 122 122 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); 127 127 /*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); 130 130 }*/ 131 131 return o; -
TabularUnified src/tempo/tempo.h ¶
r8212692 rf650860 40 40 /** create tempo detection object */ 41 41 aubio_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); 43 43 44 44 /** execute tempo detection */ -
TabularUnified src/temporal/a_weighting.c ¶
r8212692 rf650860 32 32 lvec_t *bs = aubio_filter_get_feedforward (f); 33 33 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]; 35 35 uint_t order = aubio_filter_get_order (f); 36 36 … … 241 241 242 242 aubio_filter_t * 243 new_aubio_filter_a_weighting (uint_t samplerate)243 new_aubio_filter_a_weighting (uint_t channels, uint_t samplerate) 244 244 { 245 aubio_filter_t *f = new_aubio_filter (7 );245 aubio_filter_t *f = new_aubio_filter (7, channels); 246 246 aubio_filter_set_a_weighting (f, samplerate); 247 247 return f; -
TabularUnified src/temporal/a_weighting.h ¶
r8212692 rf650860 61 61 /** create new A-design filter 62 62 63 \param channels number of channels to allocate 63 64 \param samplerate sampling frequency of the signal to filter. Should be one of 64 65 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, and … … 68 69 69 70 */ 70 aubio_filter_t *new_aubio_filter_a_weighting (uint_t samplerate); 71 aubio_filter_t *new_aubio_filter_a_weighting (uint_t channels, 72 uint_t samplerate); 71 73 72 74 /** set feedback and feedforward coefficients of a A-weighting filter -
TabularUnified src/temporal/biquad.c ¶
r8212692 rf650860 36 36 return AUBIO_FAIL; 37 37 } 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; 44 44 return AUBIO_OK; 45 45 } 46 46 47 47 aubio_filter_t * 48 new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2, lsmp_t a1, lsmp_t a2) 48 new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2, lsmp_t a1, lsmp_t a2, 49 uint_t channels) 49 50 { 50 aubio_filter_t *f = new_aubio_filter (3 );51 aubio_filter_t *f = new_aubio_filter (3, channels); 51 52 aubio_filter_set_biquad (f, b0, b1, b2, a1, a2); 52 53 return f; -
TabularUnified src/temporal/biquad.h ¶
r8212692 rf650860 62 62 \param a1 feedback filter coefficient 63 63 \param a2 feedback filter coefficient 64 \param channels number of channels to allocate 64 65 65 66 */ 66 67 aubio_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); 68 69 69 70 #ifdef __cplusplus -
TabularUnified src/temporal/c_weighting.c ¶
r8212692 rf650860 32 32 lvec_t *bs = aubio_filter_get_feedforward (f); 33 33 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]; 35 35 uint_t order = aubio_filter_get_order (f); 36 36 … … 197 197 } 198 198 199 aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate) {200 aubio_filter_t * f = new_aubio_filter(5 );199 aubio_filter_t * new_aubio_filter_c_weighting (uint_t channels, uint_t samplerate) { 200 aubio_filter_t * f = new_aubio_filter(5, channels); 201 201 aubio_filter_set_c_weighting (f, samplerate); 202 202 return f; -
TabularUnified src/temporal/c_weighting.h ¶
r8212692 rf650860 61 61 /** create new C-design filter 62 62 63 \param channels number of channels to allocate 63 64 \param samplerate sampling frequency of the signal to filter. Should be one of 64 65 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, and … … 68 69 69 70 */ 70 aubio_filter_t *new_aubio_filter_c_weighting (uint_t samplerate); 71 aubio_filter_t *new_aubio_filter_c_weighting (uint_t channels, 72 uint_t samplerate); 71 73 72 74 /** set feedback and feedforward coefficients of a C-weighting filter -
TabularUnified src/temporal/filter.c ¶
r8212692 rf650860 49 49 aubio_filter_do (aubio_filter_t * f, fvec_t * in) 50 50 { 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]; 56 56 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 } 64 75 } 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; 72 79 } 73 80 } … … 77 84 aubio_filter_do_filtfilt (aubio_filter_t * f, fvec_t * in, fvec_t * tmp) 78 85 { 79 uint_t j ;86 uint_t j, i = 0; 80 87 uint_t length = in->length; 81 88 /* apply filtering */ … … 84 91 /* mirror */ 85 92 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]; 87 94 /* apply filtering on mirrored */ 88 95 aubio_filter_do (f, tmp); … … 90 97 /* invert back */ 91 98 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]; 93 100 } 94 101 … … 132 139 133 140 aubio_filter_t * 134 new_aubio_filter (uint_t order )141 new_aubio_filter (uint_t order, uint_t channels) 135 142 { 136 143 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); 141 148 /* by default, samplerate is not set */ 142 149 f->samplerate = 0; 143 150 f->order = order; 144 151 /* set default to identity */ 145 f->a->data[ 1] = 1.;152 f->a->data[0][1] = 1.; 146 153 return f; 147 154 } -
TabularUnified src/temporal/filter.h ¶
r8212692 rf650860 26 26 Digital filter 27 27 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. 29 29 It contains the following data: 30 30 - \f$ n*1 b_i \f$ feedforward coefficients … … 151 151 /** create new filter object 152 152 153 This function creates a new ::aubio_filter_t object, given the order of the154 filter.153 This function creates a new ::aubio_filter_t object, given an order 154 and a specific number of channels. 155 155 156 156 \param order order of the filter (number of coefficients) 157 \param channels number of channels to allocate 157 158 158 159 \return the newly created filter object 159 160 160 161 */ 161 aubio_filter_t *new_aubio_filter (uint_t order );162 aubio_filter_t *new_aubio_filter (uint_t order, uint_t channels); 162 163 163 164 /** delete a filter object -
TabularUnified src/temporal/resampler.c ¶
r8212692 rf650860 61 61 aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output) 62 62 { 63 uint_t i; 63 64 s->proc->input_frames = input->length; 64 65 s->proc->output_frames = output->length; 65 66 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 } 71 74 } 72 75 … … 84 87 85 88 void 86 del_aubio_resampler (aubio_resampler_t * s UNUSED)89 del_aubio_resampler (aubio_resampler_t * s) 87 90 { 88 91 } 89 92 90 93 void 91 aubio_resampler_do (aubio_resampler_t * s UNUSED, fvec_t * input UNUSED, fvec_t * output UNUSED)94 aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output) 92 95 { 93 96 } -
TabularUnified src/utils/hist.c ¶
r8212692 rf650860 32 32 fvec_t * hist; 33 33 uint_t nelems; 34 uint_t channels; 34 35 fvec_t * cent; 35 36 aubio_scale_t *scaler; … … 39 40 * Object creation/deletion calls 40 41 */ 41 aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems ){42 aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems, uint_t channels){ 42 43 aubio_hist_t * s = AUBIO_NEW(aubio_hist_t); 43 44 smpl_t step = (ihig-ilow)/(smpl_t)(nelems); 44 45 smpl_t accum = step; 45 46 uint_t i; 47 s->channels = channels; 46 48 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); 49 51 50 52 /* use scale to map ilow/ihig -> 0/nelems */ 51 53 s->scaler = new_aubio_scale(ilow,ihig,0,nelems); 52 54 /* calculate centers now once */ 53 s->cent->data[0] = ilow + 0.5 * step;55 s->cent->data[0][0] = ilow + 0.5 * step; 54 56 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; 56 58 57 59 return s; … … 69 71 */ 70 72 void aubio_hist_do (aubio_hist_t *s, fvec_t *input) { 71 uint_t j;73 uint_t i,j; 72 74 sint_t tmp = 0; 73 75 aubio_scale_do(s->scaler, input); 74 76 /* 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; 76 80 /* 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; 82 87 } 83 }84 88 } 85 89 86 90 void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input) { 87 uint_t j;91 uint_t i,j; 88 92 sint_t tmp = 0; 89 93 aubio_scale_do(s->scaler, input); 90 94 /* 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; 92 98 /* 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 } 98 106 } 99 }100 107 } 101 108 102 109 103 110 void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input) { 104 uint_t i ;111 uint_t i,j; 105 112 sint_t tmp = 0; 106 113 smpl_t ilow = fvec_min(input); … … 112 119 113 120 /* recalculate centers */ 114 s->cent->data[0] = ilow + 0.5f * step;121 s->cent->data[0][0] = ilow + 0.5f * step; 115 122 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; 117 124 118 125 /* scale */ … … 120 127 121 128 /* 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; 123 132 /* 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 } 129 140 } 130 }131 141 } 132 142 133 143 void 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 } 138 149 } 139 150 140 151 smpl_t aubio_hist_mean (aubio_hist_t *s) { 141 uint_t j;152 uint_t i,j; 142 153 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]; 145 157 return tmp/(smpl_t)(s->nelems); 146 158 } -
TabularUnified src/utils/hist.h ¶
r8212692 rf650860 40 40 * \param fhig maximum input 41 41 * \param nelems number of histogram columns 42 * \param channels number of channels 42 43 */ 43 aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems );44 aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems, uint_t channels); 44 45 /** histogram deletion */ 45 46 void del_aubio_hist(aubio_hist_t *s); -
TabularUnified src/utils/scale.c ¶
r8212692 rf650860 70 70 void aubio_scale_do (aubio_scale_t *s, fvec_t *input) 71 71 { 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 } 77 79 } 78 80 } -
TabularUnified src/vecutils.c ¶
r8212692 rf650860 9 9 void TYPE ## _ ## OPNAME (TYPE ## _t *o) \ 10 10 { \ 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 } \ 14 16 } \ 15 17 } … … 33 35 void fvec_pow (fvec_t *s, smpl_t power) 34 36 { 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 } 38 42 } 39 43 } … … 41 45 void cvec_pow (cvec_t *s, smpl_t power) 42 46 { 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 } 46 52 } 47 53 } -
TabularUnified swig/aubio.i ¶
r8212692 rf650860 12 12 13 13 /* fvec */ 14 fvec_t * new_fvec(uint_t length );14 fvec_t * new_fvec(uint_t length, uint_t channels); 15 15 void 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); 16 smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position); 17 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position); 18 smpl_t * fvec_get_channel(fvec_t *s, uint_t channel); 19 void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel); 20 smpl_t ** fvec_get_data(fvec_t *s); 19 21 20 22 /* cvec */ 21 cvec_t * new_cvec(uint_t length );23 cvec_t * new_cvec(uint_t length, uint_t channels); 22 24 void 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); 25 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position); 26 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position); 27 smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position); 28 smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position); 29 void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel); 30 void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel); 31 smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel); 32 smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel); 33 smpl_t ** cvec_get_norm(cvec_t *s); 34 smpl_t ** cvec_get_phas(cvec_t *s); 29 35 30 36 31 37 /* fft */ 32 aubio_fft_t * new_aubio_fft(uint_t size );38 aubio_fft_t * new_aubio_fft(uint_t size, uint_t channels); 33 39 void del_aubio_fft(aubio_fft_t * s); 34 40 void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum); … … 44 50 45 51 /* filter */ 46 aubio_filter_t * new_aubio_filter(uint_t order );52 aubio_filter_t * new_aubio_filter(uint_t order, uint_t channels); 47 53 void aubio_filter_do(aubio_filter_t * b, fvec_t * in); 48 54 void aubio_filter_do_outplace(aubio_filter_t * b, fvec_t * in, fvec_t * out); … … 51 57 52 58 /* a_weighting */ 53 aubio_filter_t * new_aubio_filter_a_weighting (uint_t samplerate);59 aubio_filter_t * new_aubio_filter_a_weighting (uint_t channels, uint_t samplerate); 54 60 uint_t aubio_filter_set_a_weighting (aubio_filter_t * b, uint_t samplerate); 55 61 56 62 /* c_weighting */ 57 aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate);63 aubio_filter_t * new_aubio_filter_c_weighting (uint_t channels, uint_t samplerate); 58 64 uint_t aubio_filter_set_c_weighting (aubio_filter_t * b, uint_t samplerate); 59 65 60 66 /* biquad */ 61 aubio_filter_t * new_aubio_filter_biquad(lsmp_t b1, lsmp_t b2, lsmp_t b3, lsmp_t a2, lsmp_t a3 );67 aubio_filter_t * new_aubio_filter_biquad(lsmp_t b1, lsmp_t b2, lsmp_t b3, lsmp_t a2, lsmp_t a3, uint_t channels); 62 68 uint_t aubio_filter_set_biquad (aubio_filter_t * b, lsmp_t b1, lsmp_t b2, lsmp_t b3, lsmp_t a2, lsmp_t a3); 63 69 … … 88 94 89 95 /* pvoc */ 90 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s );96 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels); 91 97 void del_aubio_pvoc(aubio_pvoc_t *pv); 92 98 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t *in, cvec_t * fftgrain); … … 95 101 /* pitch detection */ 96 102 aubio_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); 98 104 void aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); 99 105 uint_t aubio_pitch_set_tolerance(aubio_pitch_t *p, smpl_t thres); … … 103 109 /* tempo */ 104 110 aubio_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); 106 112 void aubio_tempo_do (aubio_tempo_t *o, fvec_t * input, fvec_t * tempo); 107 113 uint_t aubio_tempo_set_silence(aubio_tempo_t * o, smpl_t silence); … … 114 120 void aubio_specdesc_do (aubio_specdesc_t * o, cvec_t * fftgrain, 115 121 fvec_t * desc); 116 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size); 122 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size, 123 uint_t channels); 117 124 void del_aubio_specdesc (aubio_specdesc_t * o); 118 125 119 126 /* peak picker */ 120 aubio_peakpicker_t * new_aubio_peakpicker( );127 aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels); 121 128 void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out); 122 129 fvec_t * aubio_peakpicker_get_thresholded_input(aubio_peakpicker_t * p); … … 133 140 aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * existingfile, const char * outputname); 134 141 void 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);142 int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t * write); 143 int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t * read); 137 144 int del_aubio_sndfile(aubio_sndfile_t * file); 138 145 uint_t aubio_sndfile_channels(aubio_sndfile_t * file); -
TabularUnified tests/src/temporal/test-aweighting.c ¶
r8212692 rf650860 8 8 uint_t nrates = 6; 9 9 uint_t samplerate, i = 0; 10 uint_t channels = 2; 10 11 11 12 for ( samplerate = rates[i]; i < nrates ; i++ ) { 12 f = new_aubio_filter_a_weighting ( samplerate);13 f = new_aubio_filter_a_weighting (channels, samplerate); 13 14 del_aubio_filter (f); 14 15 15 f = new_aubio_filter (7 );16 f = new_aubio_filter (7, channels*2); 16 17 aubio_filter_set_a_weighting (f, samplerate); 17 18 del_aubio_filter (f); … … 19 20 20 21 // samplerate unknown 21 f = new_aubio_filter_a_weighting ( 4200);22 f = new_aubio_filter_a_weighting (channels, 4200); 22 23 del_aubio_filter (f); 23 24 24 25 // order to small 25 f = new_aubio_filter (2 );26 f = new_aubio_filter (2, channels*2); 26 27 aubio_filter_set_a_weighting (f, samplerate); 27 28 del_aubio_filter (f); 28 29 29 30 // order to big 30 f = new_aubio_filter (12 );31 f = new_aubio_filter (12, channels*2); 31 32 aubio_filter_set_a_weighting (f, samplerate); 32 33 del_aubio_filter (f); -
TabularUnified tests/src/temporal/test-cweighting.c ¶
r8212692 rf650860 8 8 uint_t nrates = 6; 9 9 uint_t samplerate, i = 0; 10 uint_t channels = 2; 10 11 11 12 for ( samplerate = rates[i]; i < nrates ; i++ ) { 12 f = new_aubio_filter_c_weighting ( samplerate);13 f = new_aubio_filter_c_weighting (channels, samplerate); 13 14 del_aubio_filter (f); 14 15 15 f = new_aubio_filter (5 );16 f = new_aubio_filter (5, channels*2); 16 17 aubio_filter_set_c_weighting (f, samplerate); 17 18 del_aubio_filter (f); … … 19 20 20 21 // samplerate unknown 21 f = new_aubio_filter_c_weighting ( 4200);22 f = new_aubio_filter_c_weighting (channels, 4200); 22 23 del_aubio_filter (f); 23 24 24 25 // order to small 25 f = new_aubio_filter (2 );26 f = new_aubio_filter (2, channels*2); 26 27 aubio_filter_set_c_weighting (f, samplerate); 27 28 del_aubio_filter (f); 28 29 29 30 // order to big 30 f = new_aubio_filter (12 );31 f = new_aubio_filter (12, channels*2); 31 32 aubio_filter_set_c_weighting (f, samplerate); 32 33 del_aubio_filter (f); -
TabularUnified tests/src/test-beattracking.c ¶
r8212692 rf650860 7 7 /* allocate some memory */ 8 8 uint_t win_s = 1024; /* window size */ 9 fvec_t * in = new_fvec (win_s); /* input buffer */ 10 fvec_t * out = new_fvec (win_s/4); /* input buffer */ 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 */ 11 12 12 13 /* 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); 14 15 15 16 uint_t i = 0; -
TabularUnified tests/src/test-biquad.c ¶
r8212692 rf650860 4 4 /* allocate some memory */ 5 5 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); 8 9 9 10 aubio_filter_do_filtfilt(o,in,in); -
TabularUnified tests/src/test-cvec.c ¶
r8212692 rf650860 4 4 /* allocate some memory */ 5 5 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 */ 7 8 del_cvec(sp); 8 9 -
TabularUnified tests/src/test-fft.c ¶
r8212692 rf650860 5 5 /* allocate some memory */ 6 6 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; 18 19 /* 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); 20 21 /* fill input with some data */ 21 22 fvec_print(in); -
TabularUnified tests/src/test-filter.c ¶
r8212692 rf650860 6 6 /* allocate some memory */ 7 7 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 */ 10 11 11 12 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; 14 15 fvec_print (in); 15 16 aubio_filter_do (o, in); … … 17 18 del_aubio_filter (o); 18 19 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; 21 22 fvec_print (in); 22 23 aubio_filter_do_outplace (o, in, out); … … 24 25 del_aubio_filter (o); 25 26 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; 28 29 fvec_print (in); 29 30 aubio_filter_do_filtfilt (o, in, out); -
TabularUnified tests/src/test-filterbank.c ¶
r8212692 rf650860 9 9 /* allocate some memory */ 10 10 uint_t win_s = 1024; /* window size */ 11 uint_t channels = 2; /* number of channel */ 11 12 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 f mat_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; 15 16 16 17 /* allocate fft and other memory space */ … … 22 23 } 23 24 24 /*25 25 if (fvec_max (coeffs) != 0.) { 26 26 return -1; … … 30 30 return -1; 31 31 } 32 */33 32 34 f mat_print (coeffs);33 fvec_print (coeffs); 35 34 36 35 aubio_filterbank_do (o, in, out); -
TabularUnified tests/src/test-filterbank_mel.c ¶
r8212692 rf650860 9 9 /* allocate some memory */ 10 10 uint_t win_s = 512; /* fft size */ 11 uint_t channels = 2; /* number of channel */ 11 12 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 f mat_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; 15 16 smpl_t samplerate = 16000.; 16 17 … … 26 27 } 27 28 28 //f mat_print (coeffs);29 //fvec_print (coeffs); 29 30 30 31 //fprintf(stderr, "%f\n", fvec_sum(coeffs)); -
TabularUnified tests/src/test-fvec.c ¶
r8212692 rf650860 4 4 /* allocate some memory */ 5 5 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 */ 7 8 del_fvec(in); 8 9 -
TabularUnified tests/src/test-hist.c ¶
r8212692 rf650860 8 8 uint_t length; 9 9 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); 11 11 fvec_t *t = new_aubio_window("hanning", length); 12 12 aubio_hist_do(o,t); -
TabularUnified tests/src/test-mfcc.c ¶
r8212692 rf650860 6 6 /* allocate some memory */ 7 7 uint_t win_s = 512; /* fft size */ 8 uint_t channels = 1; /* number of channel */ 8 9 uint_t n_filters = 40; /* number of filters */ 9 10 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 */ 12 13 smpl_t samplerate = 16000.; 13 14 -
TabularUnified tests/src/test-onset.c ¶
r8212692 rf650860 4 4 /* allocate some memory */ 5 5 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.); 9 10 uint_t i = 0; 10 11 -
TabularUnified tests/src/test-onsetdetection.c ¶
r8212692 rf650860 8 8 { 9 9 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 */ 12 13 13 14 aubio_specdesc_t *o; 14 15 15 o = new_aubio_specdesc ("energy", win_s );16 o = new_aubio_specdesc ("energy", win_s, channels); 16 17 aubio_specdesc_do (o, in, out); 17 18 del_aubio_specdesc (o); 18 19 19 o = new_aubio_specdesc ("energy", win_s );20 o = new_aubio_specdesc ("energy", win_s, channels); 20 21 aubio_specdesc_do (o, in, out); 21 22 del_aubio_specdesc (o); 22 23 23 o = new_aubio_specdesc ("hfc", win_s );24 o = new_aubio_specdesc ("hfc", win_s, channels); 24 25 aubio_specdesc_do (o, in, out); 25 26 del_aubio_specdesc (o); 26 27 27 o = new_aubio_specdesc ("complex", win_s );28 o = new_aubio_specdesc ("complex", win_s, channels); 28 29 aubio_specdesc_do (o, in, out); 29 30 del_aubio_specdesc (o); 30 31 31 o = new_aubio_specdesc ("phase", win_s );32 o = new_aubio_specdesc ("phase", win_s, channels); 32 33 aubio_specdesc_do (o, in, out); 33 34 del_aubio_specdesc (o); 34 35 35 o = new_aubio_specdesc ("kl", win_s );36 o = new_aubio_specdesc ("kl", win_s, channels); 36 37 aubio_specdesc_do (o, in, out); 37 38 del_aubio_specdesc (o); 38 39 39 o = new_aubio_specdesc ("mkl", win_s );40 o = new_aubio_specdesc ("mkl", win_s, channels); 40 41 aubio_specdesc_do (o, in, out); 41 42 del_aubio_specdesc (o); -
TabularUnified tests/src/test-peakpick.c ¶
r8212692 rf650860 6 6 /* allocate some memory */ 7 7 uint_t win_s = 1024; /* window size */ 8 fvec_t * in = new_fvec (win_s); /* input buffer */ 9 fvec_t * out = new_fvec (1); /* input buffer */ 10 aubio_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); 11 12 aubio_peakpicker_set_threshold (o, 0.3); 12 13 -
TabularUnified tests/src/test-phasevoc-jack.c ¶
r8212692 rf650860 22 22 uint_t pos = 0; /* frames%dspblocksize for jack loop */ 23 23 24 fvec_t * in [2];25 cvec_t * fftgrain [2];26 fvec_t * out [2];24 fvec_t * in; 25 cvec_t * fftgrain; 26 fvec_t * out; 27 27 28 aubio_pvoc_t * pv [2];28 aubio_pvoc_t * pv; 29 29 30 30 int aubio_process(float **input, float **output, int nframes); … … 32 32 int main(){ 33 33 /* 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 */ 39 37 /* 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); 42 39 43 40 #ifdef HAVE_JACK … … 56 53 #endif 57 54 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); 64 59 aubio_cleanup(); 65 60 return 0; … … 72 67 for (i=0;i<channels;i++) { 73 68 /* write input to datanew */ 74 fvec_write_sample(in [i], input[i][j], pos);69 fvec_write_sample(in, input[i][j], i, pos); 75 70 /* put synthnew in output */ 76 output[i][j] = fvec_read_sample(out [i], pos);71 output[i][j] = fvec_read_sample(out, i, pos); 77 72 } 78 73 /*time for fft*/ 79 74 if (pos == hop_s-1) { 80 75 /* 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); 83 77 // 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.; 85 79 // 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.); 89 83 } 90 84 // copy second channel to third one 91 aubio_pvoc_rdo(pv [i], fftgrain[i], out[i]);85 aubio_pvoc_rdo(pv,fftgrain,out); 92 86 pos = -1; 93 }94 87 } 95 88 pos++; -
TabularUnified tests/src/test-phasevoc.c ¶
r8212692 rf650860 7 7 uint_t win_s = 1024; /* window size */ 8 8 uint_t hop_s = 256; /* hop size */ 9 uint_t channels = 4; /* number of channels */ 9 10 /* 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 */ 13 14 /* 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); 15 16 /* fill input with some data */ 16 17 printf("initialised\n"); -
TabularUnified tests/src/test-pitchdetection.c ¶
r8212692 rf650860 8 8 uint_t hop_s = win_s / 4; /* hop size */ 9 9 uint_t samplerate = 44100; /* samplerate */ 10 fvec_t *in = new_fvec (hop_s); /* input buffer */ 11 fvec_t *out = new_fvec (1); /* input buffer */ 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 */ 12 13 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); 14 15 uint_t i = 0; 15 16 -
TabularUnified tests/src/test-pitchfcomb.c ¶
r8212692 rf650860 7 7 uint_t win_s = 1024; /* window size */ 8 8 uint_t hop_s = win_s/4; /* hop size */ 9 fvec_t * in = new_fvec (hop_s); /* input buffer */ 10 fvec_t * out = new_fvec (1); 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); 11 12 aubio_pitchfcomb_t * o = new_aubio_pitchfcomb ( 12 win_s, hop_s );13 win_s, hop_s, channels); 13 14 uint_t i = 0; 14 15 -
TabularUnified tests/src/test-pitchmcomb.c ¶
r8212692 rf650860 7 7 uint_t win_s = 1024; /* window size */ 8 8 uint_t hop_s = win_s/4; /* hop size */ 9 cvec_t * in = new_cvec (win_s); /* input buffer */ 10 fvec_t * out = new_fvec (1); /* input buffer */ 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 */ 11 12 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); 13 14 uint_t i = 0; 14 15 -
TabularUnified tests/src/test-pitchschmitt.c ¶
r8212692 rf650860 6 6 /* allocate some memory */ 7 7 uint_t win_s = 1024; /* window size */ 8 fvec_t * in = new_fvec (win_s ); /* input buffer */9 fvec_t * out = new_fvec (1 ); /* input buffer */8 fvec_t * in = new_fvec (win_s, 1); /* input buffer */ 9 fvec_t * out = new_fvec (1, 1); /* input buffer */ 10 10 aubio_pitchschmitt_t * o = new_aubio_pitchschmitt(win_s); 11 11 uint_t i = 0; -
TabularUnified tests/src/test-pitchyin.c ¶
r8212692 rf650860 6 6 /* allocate some memory */ 7 7 uint_t win_s = 1024; /* window size */ 8 fvec_t * in = new_fvec (win_s); /* input buffer */ 9 fvec_t * out = new_fvec (win_s/2); /* input buffer */ 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 */ 10 11 aubio_pitchyin_t *p = new_aubio_pitchyin (win_s); 11 12 uint_t i = 0; -
TabularUnified tests/src/test-pitchyinfft.c ¶
r8212692 rf650860 6 6 /* allocate some memory */ 7 7 uint_t win_s = 1024; /* window size */ 8 fvec_t * in = new_fvec (win_s); /* input buffer */ 9 fvec_t * out = new_fvec (1); /* output pitch periods */ 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 */ 10 11 aubio_pitchyinfft_t * o = new_aubio_pitchyinfft(win_s); 11 12 aubio_pitchyinfft_set_tolerance (o, 0.2); -
TabularUnified tests/src/test-resample.c ¶
r8212692 rf650860 7 7 /* allocate some memory */ 8 8 uint_t win_s = 1024; /* window size */ 9 uint_t channels = 1; /* number of channel */ 9 10 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 */ 12 13 aubio_resampler_t *o = new_aubio_resampler (0.5, 0); 13 14 uint_t i = 0; -
TabularUnified tests/src/test-scale.c ¶
r8212692 rf650860 6 6 /* allocate some memory */ 7 7 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 */ 9 10 aubio_scale_t * o = new_aubio_scale(0,1,2,3); 10 11 aubio_scale_set_limits (o,0,1,2,3); -
TabularUnified tests/src/test-tempo.c ¶
r8212692 rf650860 5 5 /* allocate some memory */ 6 6 uint_t win_s = 1024; /* window size */ 7 fvec_t * in = new_fvec (win_s); /* input buffer */ 8 fvec_t * out = new_fvec (2); /* input buffer */ 9 aubio_tempo_t * o = new_aubio_tempo("complex", win_s, win_s/4, 44100.); 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.); 10 11 uint_t i = 0; 11 12 -
TabularUnified tests/src/test-tss.c ¶
r8212692 rf650860 14 14 uint_t win_s = 1024; /* window size */ 15 15 uint_t hop_s = 256; /* hop size */ 16 uint_t channels = 4; /* number of channels */ 16 17 /* 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 */ 23 24 /* 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); 27 28 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); 29 30 /* fill input with some data */ 30 31 printf("initialised\n");
Note: See TracChangeset
for help on using the changeset viewer.