Changes in / [0536612:f658288]
- Files:
-
- 4 added
- 102 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/aubiomfcc.c
r0536612 rf658288 33 33 34 34 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 35 unsigned int i; /*channels*/36 35 unsigned int j; /*frames*/ 37 36 38 37 for (j=0;j<(unsigned)nframes;j++) { 39 38 if(usejack) { 40 for (i=0;i<channels;i++) { 41 /* write input to datanew */ 42 fvec_write_sample(ibuf, input[i][j], i, pos); 43 /* put synthnew in output */ 44 output[i][j] = fvec_read_sample(obuf, i, pos); 45 } 39 /* write input to datanew */ 40 fvec_write_sample(ibuf, input[0][j], pos); 41 /* put synthnew in output */ 42 output[0][j] = fvec_read_sample(obuf, pos); 46 43 } 47 44 /*time for fft*/ … … 50 47 51 48 //compute mag spectrum 52 aubio_pvoc_do (pv, ibuf, fftgrain);49 aubio_pvoc_do (pv, ibuf, fftgrain); 53 50 54 51 //compute mfccs … … 72 69 outmsg("%f\t",frames*overlap_size/(float)samplerate); 73 70 for (coef_cnt = 0; coef_cnt < n_coefs; coef_cnt++) { 74 outmsg("%f ", fvec_read_sample (mfcc_out, 0,coef_cnt) );71 outmsg("%f ", fvec_read_sample (mfcc_out, coef_cnt) ); 75 72 } 76 73 outmsg("\n"); … … 86 83 87 84 /* phase vocoder */ 88 pv = new_aubio_pvoc (buffer_size, overlap_size , channels);85 pv = new_aubio_pvoc (buffer_size, overlap_size); 89 86 90 fftgrain = new_cvec (buffer_size , channels);87 fftgrain = new_cvec (buffer_size); 91 88 92 89 //populating the filter 93 90 mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate); 94 91 95 mfcc_out = new_fvec(n_coefs ,channels);92 mfcc_out = new_fvec(n_coefs); 96 93 97 94 //process -
examples/aubionotes.c
r0536612 rf658288 19 19 */ 20 20 21 #define AUBIO_UNSTABLE 1 // for fvec_median _channel21 #define AUBIO_UNSTABLE 1 // for fvec_median 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*/53 52 unsigned int j; /*frames*/ 54 53 for (j=0;j<(unsigned)nframes;j++) { 55 54 if(usejack) { 56 for (i=0;i<channels;i++) { 57 /* write input to datanew */ 58 fvec_write_sample(ibuf, input[i][j], i, pos); 59 /* put synthnew in output */ 60 output[i][j] = fvec_read_sample(obuf, i, pos); 61 } 55 /* write input to datanew */ 56 fvec_write_sample(ibuf, input[0][j], pos); 57 /* put synthnew in output */ 58 output[0][j] = fvec_read_sample(obuf, pos); 62 59 } 63 60 /*time for fft*/ … … 67 64 68 65 aubio_pitch_do (pitchdet, ibuf, pitch_obuf); 69 pitch = fvec_read_sample(pitch_obuf, 0 , 0);66 pitch = fvec_read_sample(pitch_obuf, 0); 70 67 if(median){ 71 68 note_append(note_buffer, pitch); … … 74 71 /* curlevel is negatif or 1 if silence */ 75 72 curlevel = aubio_level_detection(ibuf, silence); 76 if (fvec_read_sample(onset, 0 , 0)) {73 if (fvec_read_sample(onset, 0)) { 77 74 /* test for silence */ 78 75 if (curlevel == 1.) { … … 92 89 93 90 for (pos = 0; pos < overlap_size; pos++){ 94 obuf->data[ 0][pos] = woodblock->data[0][pos];91 obuf->data[pos] = woodblock->data[pos]; 95 92 } 96 93 } … … 112 109 } // if median 113 110 for (pos = 0; pos < overlap_size; pos++) 114 obuf->data[ 0][pos] = 0.;111 obuf->data[pos] = 0.; 115 112 } 116 113 /* end of block loop */ … … 131 128 uint_t i = 0; 132 129 for (i = 0; i < note_buffer->length - 1; i++) { 133 note_buffer->data[ 0][i] = note_buffer->data[0][i + 1];130 note_buffer->data[i] = note_buffer->data[i + 1]; 134 131 } 135 note_buffer->data[ 0][note_buffer->length - 1] = curnote;132 note_buffer->data[note_buffer->length - 1] = curnote; 136 133 return; 137 134 } … … 142 139 uint_t i; 143 140 for (i = 0; i < note_buffer->length; i++) { 144 note_buffer2->data[ 0][i] = note_buffer->data[0][i];141 note_buffer2->data[i] = note_buffer->data[i]; 145 142 } 146 return fvec_median _channel (note_buffer2, 0);143 return fvec_median (note_buffer2); 147 144 } 148 145 … … 150 147 examples_common_init(argc,argv); 151 148 152 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels, 153 samplerate); 149 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate); 154 150 if (threshold != 0.) aubio_onset_set_threshold (o, threshold); 155 onset = new_fvec (1 , channels);151 onset = new_fvec (1); 156 152 157 153 pitchdet = new_aubio_pitch (pitch_mode, buffer_size * 4, 158 overlap_size, channels,samplerate);154 overlap_size, samplerate); 159 155 aubio_pitch_set_tolerance (pitchdet, 0.7); 160 pitch_obuf = new_fvec (1 , channels);156 pitch_obuf = new_fvec (1); 161 157 if (median) { 162 note_buffer = new_fvec (median , 1);163 note_buffer2 = new_fvec (median , 1);158 note_buffer = new_fvec (median); 159 note_buffer2 = new_fvec (median); 164 160 } 165 161 -
examples/aubioonset.c
r0536612 rf658288 31 31 for (j=0;j<(unsigned)nframes;j++) { 32 32 if(usejack) { 33 for (i=0;i<channels;i++) { 34 /* write input to datanew */ 35 fvec_write_sample(ibuf, input[i][j], i, pos); 36 /* put synthnew in output */ 37 output[i][j] = fvec_read_sample(obuf, i, pos); 38 } 33 /* write input to datanew */ 34 fvec_write_sample(ibuf, input[0][j], pos); 35 /* put synthnew in output */ 36 output[0][j] = fvec_read_sample(obuf, pos); 39 37 } 40 38 /*time for fft*/ 41 if (pos == overlap_size-1) { 39 if (pos == overlap_size-1) { 42 40 /* block loop */ 43 41 aubio_onset_do (o, ibuf, onset); 44 if ( fvec_read_sample(onset, 0, 0)) {42 if ( fvec_read_sample(onset, 0) ) { 45 43 fvec_copy (woodblock, obuf); 46 44 } else { … … 55 53 } 56 54 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 } 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 } 71 71 } 72 72 … … 75 75 examples_common_init(argc,argv); 76 76 77 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels, 78 samplerate); 77 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate); 79 78 if (threshold != 0.) aubio_onset_set_threshold (o, threshold); 80 onset = new_fvec (1 , channels);79 onset = new_fvec (1); 81 80 82 81 examples_common_process(aubio_process,process_print); -
examples/aubiopitch.c
r0536612 rf658288 27 27 28 28 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 29 unsigned int i; /*channels*/30 29 unsigned int j; /*frames*/ 31 30 for (j=0;j<(unsigned)nframes;j++) { 32 31 if(usejack) { 33 for (i=0;i<channels;i++) { 34 /* write input to datanew */ 35 fvec_write_sample(ibuf, input[i][j], i, pos); 36 /* put synthnew in output */ 37 output[i][j] = fvec_read_sample(obuf, i, pos); 38 } 32 /* write input to datanew */ 33 fvec_write_sample(ibuf, input[0][j], pos); 34 /* put synthnew in output */ 35 output[0][j] = fvec_read_sample(obuf, pos); 39 36 } 40 37 /*time for fft*/ … … 42 39 /* block loop */ 43 40 aubio_pitch_do (o, ibuf, pitch); 44 if (fvec_read_sample(pitch, 0 , 0)) {41 if (fvec_read_sample(pitch, 0)) { 45 42 for (pos = 0; pos < overlap_size; pos++){ 46 43 // TODO, play sine at this freq … … 59 56 static void process_print (void) { 60 57 if (!verbose && usejack) return; 61 smpl_t pitch_found = fvec_read_sample(pitch, 0 , 0);58 smpl_t pitch_found = fvec_read_sample(pitch, 0); 62 59 outmsg("%f %f\n",(frames) 63 60 *overlap_size/(float)samplerate, pitch_found); … … 67 64 examples_common_init(argc,argv); 68 65 69 o = new_aubio_pitch (onset_mode, buffer_size, overlap_size, channels, 70 samplerate); 71 pitch = new_fvec (1, channels); 66 o = new_aubio_pitch (onset_mode, buffer_size, overlap_size, samplerate); 67 pitch = new_fvec (1); 72 68 73 69 examples_common_process(aubio_process,process_print); -
examples/aubioquiet.c
r0536612 rf658288 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*/29 28 unsigned int j; /*frames*/ 30 29 for (j=0;j<(unsigned)nframes;j++) { 31 30 if(usejack) { 32 for (i=0;i<channels;i++) { 33 /* write input to datanew */ 34 fvec_write_sample(ibuf, input[i][j], i, pos); 35 /* put synthnew in output */ 36 output[i][j] = fvec_read_sample(obuf, i, pos); 37 } 31 /* write input to datanew */ 32 fvec_write_sample(ibuf, input[0][j], pos); 33 /* put synthnew in output */ 34 output[0][j] = fvec_read_sample(obuf, pos); 38 35 } 39 36 /*time for fft*/ … … 41 38 /* test for silence */ 42 39 if (aubio_silence_detection(ibuf, silence)==1) { 43 44 40 if (wassilence==1) issilence = 1; 41 else issilence = 2; 45 42 wassilence=1; 46 43 } else { 47 48 44 if (wassilence<=0) issilence = 0; 45 else issilence = -1; 49 46 wassilence=0; 50 47 } -
examples/aubiotrack.c
r0536612 rf658288 29 29 30 30 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 31 unsigned int i; /*channels*/32 31 unsigned int j; /*frames*/ 33 32 for (j=0;j<(unsigned)nframes;j++) { 34 33 if(usejack) { 35 for (i=0;i<channels;i++) { 36 /* write input to datanew */ 37 fvec_write_sample(ibuf, input[i][j], i, pos); 38 /* put synthnew in output */ 39 output[i][j] = fvec_read_sample(obuf, i, pos); 40 } 34 /* write input to datanew */ 35 fvec_write_sample(ibuf, input[0][j], pos); 36 /* put synthnew in output */ 37 output[0][j] = fvec_read_sample(obuf, pos); 41 38 } 42 39 /*time for fft*/ … … 44 41 /* block loop */ 45 42 aubio_tempo_do (bt,ibuf,tempo_out); 46 istactus = fvec_read_sample (tempo_out, 0 , 0);47 isonset = fvec_read_sample (tempo_out, 0,1);43 istactus = fvec_read_sample (tempo_out, 0); 44 isonset = fvec_read_sample (tempo_out, 1); 48 45 if (istactus > 0.) { 49 46 fvec_copy (woodblock, obuf); … … 76 73 examples_common_init(argc,argv); 77 74 78 tempo_out = new_fvec(2 ,channels);79 bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, channels,samplerate);75 tempo_out = new_fvec(2); 76 bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size, samplerate); 80 77 if (threshold != 0.) aubio_tempo_set_threshold (bt, threshold); 81 78 -
examples/sndfileio.c
r0536612 rf658288 96 96 aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t); 97 97 f->samplerate = fmodel->samplerate; 98 f->channels = fmodel->channels;98 f->channels = 1; //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_ channel(read,i);152 pread = (smpl_t *)fvec_get_data(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 int 161 aubio_sndfile_read_mono (aubio_sndfile_t * f, int frames, fvec_t * read) 162 { 163 sf_count_t read_frames; 164 int i, j, channels = f->channels; 165 int nsamples = frames * channels; 166 int aread; 167 smpl_t *pread; 168 169 /* allocate data for de/interleaving reallocated when needed. */ 170 if (nsamples >= f->size) { 171 AUBIO_ERR ("Maximum aubio_sndfile_read buffer size exceeded."); 172 return -1; 173 /* 174 AUBIO_FREE(f->tmpdata); 175 f->tmpdata = AUBIO_ARRAY(float,nsamples); 176 */ 177 } 178 //f->size = nsamples; 179 180 /* do actual reading */ 181 read_frames = sf_read_float (f->handle, f->tmpdata, nsamples); 182 183 aread = (int) FLOOR (read_frames / (float) channels); 184 185 /* de-interleaving data */ 186 pread = (smpl_t *) fvec_get_data (read); 187 for (i = 0; i < channels; i++) { 188 for (j = 0; j < aread; j++) { 189 pread[j] += (smpl_t) f->tmpdata[channels * j + i]; 190 } 191 } 192 for (j = 0; j < aread; j++) { 193 pread[j] /= (smpl_t)channels; 194 } 195 196 return aread; 197 } 198 160 199 /* write 'frames' samples to file from data 161 200 * return the number of frames actually written 162 201 */ 163 int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t * write) {202 int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t ** write) { 164 203 sf_count_t written_frames = 0; 165 204 int i, j, channels = f->channels; … … 180 219 /* interleaving data */ 181 220 for (i=0; i<channels; i++) { 182 pwrite = (smpl_t *)fvec_get_ channel(write,i);221 pwrite = (smpl_t *)fvec_get_data(write[i]); 183 222 for (j=0; j<frames; j++) { 184 223 f->tmpdata[channels*j+i] = (float)pwrite[j]; -
examples/sndfileio.h
r0536612 rf658288 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 -
examples/utils.c
r0536612 rf658288 61 61 uint_t buffer_size = 512; //1024; 62 62 uint_t overlap_size = 256; //512; 63 uint_t channels = 1;64 63 uint_t samplerate = 44100; 65 64 … … 208 207 parse_args (argc, argv); 209 208 210 woodblock = new_fvec ( buffer_size, 1);209 woodblock = new_fvec (overlap_size); 211 210 if (output_filename || usejack) { 212 211 /* dummy assignement to keep egcs happy */ … … 221 220 if (onsetfile) { 222 221 /* read the output sound once */ 223 aubio_sndfile_read (onsetfile, overlap_size, woodblock);222 aubio_sndfile_read_mono (onsetfile, overlap_size, woodblock); 224 223 } 225 224 … … 233 232 if (verbose) 234 233 aubio_sndfile_info (file); 235 channels = aubio_sndfile_channels (file);236 234 samplerate = aubio_sndfile_samplerate (file); 237 235 if (output_filename != NULL) … … 256 254 #endif /* HAVE_LASH */ 257 255 258 ibuf = new_fvec (overlap_size, channels); 259 obuf = new_fvec (overlap_size, channels); 256 uint_t i; 257 ibuf = new_fvec (overlap_size); 258 obuf = new_fvec (overlap_size); 260 259 261 260 } … … 265 264 examples_common_del (void) 266 265 { 266 uint_t i; 267 267 del_fvec (ibuf); 268 268 del_fvec (obuf); … … 283 283 #if HAVE_JACK 284 284 debug ("Jack init ...\n"); 285 jack_setup = new_aubio_jack ( channels, channels,285 jack_setup = new_aubio_jack (1, 1, 286 286 0, 1, (aubio_process_func_t) process_func); 287 287 debug ("Jack activation ...\n"); … … 301 301 frames = 0; 302 302 303 while ((signed) overlap_size == aubio_sndfile_read (file, overlap_size,304 305 process_func ( ibuf->data,obuf->data, overlap_size);303 while ((signed) overlap_size == 304 aubio_sndfile_read_mono (file, overlap_size, ibuf)) { 305 process_func (&ibuf->data, &obuf->data, overlap_size); 306 306 print (); 307 307 if (output_filename != NULL) { 308 aubio_sndfile_write (fileout, overlap_size, obuf);308 aubio_sndfile_write (fileout, overlap_size, &obuf); 309 309 } 310 310 frames++; … … 328 328 fvec_zeros(obuf); 329 329 for (i = 0; (signed) i < frames_delay; i++) { 330 process_func ( ibuf->data,obuf->data, overlap_size);330 process_func (&ibuf->data, &obuf->data, overlap_size); 331 331 print (); 332 332 } -
examples/utils.h
r0536612 rf658288 74 74 extern uint_t buffer_size; 75 75 extern uint_t overlap_size; 76 extern uint_t channels;77 76 extern uint_t samplerate; 78 77 -
interfaces/python/aubio-types.h
r0536612 rf658288 6 6 #include <aubio.h> 7 7 8 #define Py_default_vector_length 9 #define Py_default_vector_ channels18 #define Py_default_vector_length 1024 9 #define Py_default_vector_height 1 10 10 11 11 #define Py_aubio_default_samplerate 44100 … … 25 25 26 26 */ 27 #define AUBIO_DO_CASTING 028 27 29 28 typedef struct … … 32 31 fvec_t * o; 33 32 uint_t length; 34 uint_t channels;35 33 } Py_fvec; 36 34 extern PyTypeObject Py_fvecType; … … 38 36 extern PyObject *PyAubio_CFvecToArray (fvec_t * self); 39 37 extern Py_fvec *PyAubio_ArrayToFvec (PyObject * self); 38 39 typedef struct 40 { 41 PyObject_HEAD 42 fmat_t * o; 43 uint_t length; 44 uint_t height; 45 } Py_fmat; 46 extern PyTypeObject Py_fmatType; 47 extern PyObject *PyAubio_FmatToArray (Py_fmat * self); 48 extern PyObject *PyAubio_CFmatToArray (fmat_t * self); 49 extern Py_fmat *PyAubio_ArrayToFmat (PyObject * self); 40 50 41 51 typedef struct -
interfaces/python/aubiomodule.c
r0536612 rf658288 122 122 123 123 if ((PyType_Ready (&Py_fvecType) < 0) 124 || (PyType_Ready (&Py_fmatType) < 0) 124 125 || (PyType_Ready (&Py_cvecType) < 0) 125 126 || (PyType_Ready (&Py_filterType) < 0) … … 148 149 Py_INCREF (&Py_fvecType); 149 150 PyModule_AddObject (m, "fvec", (PyObject *) & Py_fvecType); 151 Py_INCREF (&Py_fmatType); 152 PyModule_AddObject (m, "fmat", (PyObject *) & Py_fmatType); 150 153 Py_INCREF (&Py_cvecType); 151 154 PyModule_AddObject (m, "cvec", (PyObject *) & Py_cvecType); -
interfaces/python/aubiowraphell.h
r0536612 rf658288 94 94 95 95 // some more helpers 96 #define AUBIO_NEW_VEC(name, type, lengthval , channelsval) \96 #define AUBIO_NEW_VEC(name, type, lengthval) \ 97 97 name = (type *) PyObject_New (type, & type ## Type); \ 98 name->channels = channelsval; \99 98 name->length = lengthval; -
interfaces/python/gen_pyobject.py
r0536612 rf658288 69 69 # move into the C library at some point. 70 70 defaultsizes = { 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'),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', 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',102 101 'samplerate': 'Py_aubio_default_samplerate', 103 102 # now for the non obvious ones … … 151 150 newparams = get_params_types_names(newfunc) 152 151 # self->param1, self->param2, self->param3 153 selfparams = ', self->'.join([p[1] for p in newparams]) 152 if len(newparams): 153 selfparams = ', self->'+', self->'.join([p[1] for p in newparams]) 154 else: 155 selfparams = '' 154 156 # "param1", "param2", "param3" 155 157 paramnames = ", ".join(["\""+p[1]+"\"" for p in newparams]) … … 179 181 Py_%(name)s_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) 180 182 { 183 Py_%(name)s *self; 181 184 """ % locals() 182 185 for ptype, pname in newparams: … … 186 189 """ % locals() 187 190 # now the actual PyArg_Parse 188 s += """\189 Py_%(name)s *self;191 if len(paramnames): 192 s += """\ 190 193 static char *kwlist[] = { %(paramnames)s, NULL }; 191 194 … … 194 197 return NULL; 195 198 } 199 """ % locals() 200 s += """\ 196 201 197 202 self = (Py_%(name)s *) pytype->tp_alloc (pytype, 0); … … 238 243 } 239 244 240 AUBIO_INIT(%(name)s , self->%(selfparams)s)245 AUBIO_INIT(%(name)s %(selfparams)s) 241 246 242 247 AUBIO_DEL(%(name)s) … … 287 292 outputvecs = "\n ".join([aubio2pyaubio[p[0]]+" * " + p[-1] + ";" for p in outputparams]) 288 293 outputcreate = "\n ".join(["""\ 289 AUBIO_NEW_VEC(%(name)s, %(pytype)s, %(length)s , %(channels)s)290 %(name)s->o = new_%(autype)s (%(length)s , %(channels)s);""" % \294 AUBIO_NEW_VEC(%(name)s, %(pytype)s, %(length)s) 295 %(name)s->o = new_%(autype)s (%(length)s);""" % \ 291 296 {'name': p[-1], 'pytype': aubio2pyaubio[p[0]], 'autype': p[0][:-3], 292 'length': defaultsizes[name] [0], 'channels': defaultsizes[name][1]} \297 'length': defaultsizes[name]} \ 293 298 for p in outputparams]) 294 299 if len(outputparams) > 1: -
interfaces/python/py-cvec.c
r0536612 rf658288 4 4 5 5 class cvec(): 6 def __init__(self, length = 1024 , channels = 1):6 def __init__(self, length = 1024): 7 7 self.length = length 8 self. channels = channels9 self. norm = array(length, channels)10 self.phas = array(length, channels) 8 self.norm = array(length) 9 self.phas = array(length) 10 11 11 */ 12 13 12 14 13 static char Py_cvec_doc[] = "cvec object"; … … 17 16 Py_cvec_new (PyTypeObject * type, PyObject * args, PyObject * kwds) 18 17 { 19 int length= 0 , channels = 0;18 int length= 0; 20 19 Py_cvec *self; 21 static char *kwlist[] = { "length", "channels",NULL };22 23 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I I", kwlist,24 &length , &channels)) {20 static char *kwlist[] = { "length", NULL }; 21 22 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist, 23 &length)) { 25 24 return NULL; 26 25 } … … 30 29 31 30 self->length = Py_default_vector_length / 2 + 1; 32 self->channels = Py_default_vector_channels;33 31 34 32 if (self == NULL) { … … 44 42 } 45 43 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 54 44 return (PyObject *) self; 55 45 } … … 58 48 Py_cvec_init (Py_cvec * self, PyObject * args, PyObject * kwds) 59 49 { 60 self->o = new_cvec ((self->length - 1) * 2 , self->channels);50 self->o = new_cvec ((self->length - 1) * 2); 61 51 if (self->o == NULL) { 62 52 return -1; … … 80 70 PyObject *result = NULL; 81 71 82 format = PyString_FromString ("aubio cvec of %d elements with %d channels");72 format = PyString_FromString ("aubio cvec of %d elements"); 83 73 if (format == NULL) { 84 74 goto fail; 85 75 } 86 76 87 args = Py_BuildValue ("I I", self->length, self->channels);77 args = Py_BuildValue ("I", self->length); 88 78 if (args == NULL) { 89 79 goto fail; 90 80 } 91 //cvec_print ( self->o );81 cvec_print ( self->o ); 92 82 93 83 result = PyString_Format (format, args); … … 104 94 PyObject *array; 105 95 Py_cvec *vec; 106 uint_t i; 96 if (input == NULL) { 97 PyErr_SetString (PyExc_ValueError, "input array is not a python object"); 98 goto fail; 99 } 107 100 // parsing input object into a Py_cvec 108 101 if (PyObject_TypeCheck (input, &Py_cvecType)) { … … 115 108 PyErr_SetString (PyExc_ValueError, "input array is a scalar"); 116 109 goto fail; 110 } else if (PyArray_NDIM (input) > 1) { 111 PyErr_SetString (PyExc_ValueError, 112 "input array has more than one dimensions"); 113 goto fail; 114 } 115 116 if (!PyArray_ISFLOAT (input)) { 117 PyErr_SetString (PyExc_ValueError, "input array should be float"); 118 goto fail; 119 } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) { 120 PyErr_SetString (PyExc_ValueError, "input array should be float32"); 121 goto fail; 122 } else { 123 // input data type is float32, nothing else to do 124 array = input; 125 } 126 127 // create a new cvec object 128 vec = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); 129 if (PyArray_NDIM (array) != 2) { 130 PyErr_SetString (PyExc_ValueError, 131 "input array should be have exactly two rows for norm and phas"); 132 goto fail; 133 } else { 134 vec->length = PyArray_SIZE (array); 135 } 136 137 // no need to really allocate cvec, just its struct member 138 // vec->o = new_cvec (vec->length); 139 vec->o = (cvec_t *)malloc(sizeof(cvec_t)); 140 vec->o->length = vec->length; 141 // have norm and phas point to array rows 142 vec->o->norm = (smpl_t *) PyArray_GETPTR1 (array, 0); 143 vec->o->phas = (smpl_t *) PyArray_GETPTR1 (array, 1); 144 145 } else { 146 PyErr_SetString (PyExc_ValueError, "can only accept array or cvec as input"); 147 return NULL; 148 } 149 150 return vec; 151 152 fail: 153 return NULL; 154 } 155 156 PyObject * 157 PyAubio_CvecToArray (Py_cvec * self) 158 { 159 PyObject *array = NULL; 160 npy_intp dims[] = { self->o->length, 1 }; 161 PyObject *concat = PyList_New (0), *tmp = NULL; 162 tmp = PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->norm); 163 PyList_Append (concat, tmp); 164 Py_DECREF (tmp); 165 tmp = PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->phas); 166 PyList_Append (concat, tmp); 167 Py_DECREF (tmp); 168 array = PyArray_FromObject (concat, NPY_FLOAT, 2, 2); 169 Py_DECREF (concat); 170 return array; 171 } 172 173 PyObject * 174 PyAubio_CvecNormToArray (Py_cvec * self) 175 { 176 npy_intp dims[] = { self->o->length, 1 }; 177 return PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->norm); 178 } 179 180 181 PyObject * 182 PyAubio_CvecPhasToArray (Py_cvec * self) 183 { 184 npy_intp dims[] = { self->o->length, 1 }; 185 return PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->phas); 186 } 187 188 PyObject * 189 PyAubio_ArrayToCvecPhas (PyObject * self) 190 { 191 return NULL; 192 } 193 194 PyObject * 195 Py_cvec_get_norm (Py_cvec * self, void *closure) 196 { 197 return PyAubio_CvecNormToArray(self); 198 } 199 200 PyObject * 201 Py_cvec_get_phas (Py_cvec * self, void *closure) 202 { 203 return PyAubio_CvecPhasToArray(self); 204 } 205 206 static int 207 Py_cvec_set_norm (Py_cvec * vec, PyObject *input, void * closure) 208 { 209 PyObject * array; 210 if (input == NULL) { 211 PyErr_SetString (PyExc_ValueError, "input array is not a python object"); 212 goto fail; 213 } 214 if (PyArray_Check(input)) { 215 216 // we got an array, convert it to a cvec.norm 217 if (PyArray_NDIM (input) == 0) { 218 PyErr_SetString (PyExc_ValueError, "input array is a scalar"); 219 goto fail; 117 220 } else if (PyArray_NDIM (input) > 2) { 118 221 PyErr_SetString (PyExc_ValueError, … … 124 227 PyErr_SetString (PyExc_ValueError, "input array should be float"); 125 228 goto fail; 126 #if AUBIO_DO_CASTING127 } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) {128 // input data type is not float32, casting129 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 #else135 229 } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) { 136 230 PyErr_SetString (PyExc_ValueError, "input array should be float32"); 137 231 goto fail; 138 #endif 232 } 233 array = input; 234 235 // check input array dimensions 236 if (PyArray_NDIM (array) != 1) { 237 PyErr_Format (PyExc_ValueError, 238 "input array has %d dimensions, not 1", 239 PyArray_NDIM (array)); 240 goto fail; 139 241 } else { 140 // input data type is float32, nothing else to do141 array = input;142 }143 144 // create a new cvec object145 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 member159 // 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 line165 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 201 PyObject *202 PyAubio_CvecNormToArray (Py_cvec * self)203 {204 PyObject *array = NULL;205 uint_t i;206 npy_intp dims[] = { self->o->length, 1 };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;216 }217 218 219 PyObject *220 PyAubio_CvecPhasToArray (Py_cvec * self)221 {222 PyObject *array = NULL;223 uint_t i;224 npy_intp dims[] = { self->o->length, 1 };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;234 }235 236 PyObject *237 PyAubio_ArrayToCvecPhas (PyObject * self)238 {239 return NULL;240 }241 242 PyObject *243 Py_cvec_get_norm (Py_cvec * self, void *closure)244 {245 return PyAubio_CvecNormToArray(self);246 }247 248 PyObject *249 Py_cvec_get_phas (Py_cvec * self, void *closure)250 {251 return PyAubio_CvecPhasToArray(self);252 }253 254 static int255 Py_cvec_set_norm (Py_cvec * vec, PyObject *input, void * closure)256 {257 uint_t i;258 PyObject * array;259 if (input == NULL) {260 PyErr_SetString (PyExc_ValueError, "input array is not a python object");261 goto fail;262 }263 if (PyArray_Check(input)) {264 265 // we got an array, convert it to a cvec.norm266 if (PyArray_NDIM (input) == 0) {267 PyErr_SetString (PyExc_ValueError, "input array is a scalar");268 goto fail;269 } else if (PyArray_NDIM (input) > 2) {270 PyErr_SetString (PyExc_ValueError,271 "input array has more than two dimensions");272 goto fail;273 }274 275 if (!PyArray_ISFLOAT (input)) {276 PyErr_SetString (PyExc_ValueError, "input array should be float");277 goto fail;278 } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) {279 PyErr_SetString (PyExc_ValueError, "input array should be float32");280 goto fail;281 }282 array = input;283 284 // check input array dimensions285 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 }291 242 if (vec->o->length != PyArray_SIZE (array)) { 292 243 PyErr_Format (PyExc_ValueError, … … 295 246 goto fail; 296 247 } 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 } 248 } 249 250 vec->o->norm = (smpl_t *) PyArray_GETPTR1 (array, 0); 315 251 316 252 } else { … … 329 265 Py_cvec_set_phas (Py_cvec * vec, PyObject *input, void * closure) 330 266 { 331 uint_t i;332 267 PyObject * array; 333 268 if (input == NULL) { … … 357 292 358 293 // check input array dimensions 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 364 }294 if (PyArray_NDIM (array) != 1) { 295 PyErr_Format (PyExc_ValueError, 296 "input array has %d dimensions, not 1", 297 PyArray_NDIM (array)); 298 goto fail; 299 } else { 365 300 if (vec->o->length != PyArray_SIZE (array)) { 366 301 PyErr_Format (PyExc_ValueError, … … 369 304 goto fail; 370 305 } 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 } 306 } 307 308 vec->o->phas = (smpl_t *) PyArray_GETPTR1 (array, 0); 389 309 390 310 } else { … … 398 318 fail: 399 319 return 1; 400 }401 402 static Py_ssize_t403 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 int424 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;456 320 } 457 321 … … 460 324 {"length", T_INT, offsetof (Py_cvec, length), READONLY, 461 325 "length attribute"}, 462 {"channels", T_INT, offsetof (Py_cvec, channels), READONLY,463 "channels attribute"},464 326 {NULL} /* Sentinel */ 465 327 }; … … 480 342 {NULL} /* sentinel */ 481 343 }; 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 496 344 497 345 PyTypeObject Py_cvecType = { … … 508 356 (reprfunc) Py_cvec_repr, /* tp_repr */ 509 357 0, /* tp_as_number */ 510 &Py_cvec_tp_as_sequence, /* tp_as_sequence */358 0, //&Py_cvec_tp_as_sequence, /* tp_as_sequence */ 511 359 0, /* tp_as_mapping */ 512 360 0, /* tp_hash */ -
interfaces/python/py-fft.c
r0536612 rf658288 3 3 static char Py_fft_doc[] = "fft object"; 4 4 5 AUBIO_DECLARE(fft, uint_t win_s ; uint_t channels)5 AUBIO_DECLARE(fft, uint_t win_s) 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 , channels = 0;11 int win_s = 0; 12 12 Py_fft *self; 13 static char *kwlist[] = { "win_s", "channels",NULL };13 static char *kwlist[] = { "win_s", NULL }; 14 14 15 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I I", kwlist,16 &win_s , &channels)) {15 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist, 16 &win_s)) { 17 17 return NULL; 18 18 } … … 25 25 26 26 self->win_s = Py_default_vector_length; 27 self->channels = Py_default_vector_channels;28 27 29 28 if (self == NULL) { … … 39 38 } 40 39 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 49 40 return (PyObject *) self; 50 41 } 51 42 52 43 53 AUBIO_INIT(fft, self->win_s , self->channels)44 AUBIO_INIT(fft, self->win_s) 54 45 55 46 AUBIO_DEL(fft) … … 73 64 74 65 output = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); 75 output->channels = vec->channels;76 66 output->length = ((Py_fft *) self)->win_s; 77 output->o = new_cvec(((Py_fft *) self)->win_s , vec->channels);67 output->o = new_cvec(((Py_fft *) self)->win_s); 78 68 79 69 // compute the function … … 87 77 {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY, 88 78 "size of the window"}, 89 {"channels", T_INT, offsetof (Py_fft, channels), READONLY,90 "number of channels"},91 79 AUBIO_MEMBERS_STOP(fft) 92 80 … … 109 97 110 98 output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); 111 output->channels = vec->channels;112 99 output->length = ((Py_fft *) self)->win_s; 113 output->o = new_fvec(output->length , output->channels);100 output->o = new_fvec(output->length); 114 101 115 102 // compute the function -
interfaces/python/py-filter.c
r0536612 rf658288 6 6 aubio_filter_t * o; 7 7 uint_t order; 8 uint_t channels;9 8 } Py_filter; 10 9 … … 14 13 Py_filter_new (PyTypeObject * type, PyObject * args, PyObject * kwds) 15 14 { 16 int order= 0 , channels = 0;15 int order= 0; 17 16 Py_filter *self; 18 static char *kwlist[] = { "order", "channels",NULL };17 static char *kwlist[] = { "order", NULL }; 19 18 20 19 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist, 21 &order , &channels)) {20 &order)) { 22 21 return NULL; 23 22 } … … 30 29 31 30 self->order = 7; 32 self->channels = Py_default_vector_channels;33 31 34 32 if (order > 0) { … … 40 38 } 41 39 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 50 40 return (PyObject *) self; 51 41 } … … 54 44 Py_filter_init (Py_filter * self, PyObject * args, PyObject * kwds) 55 45 { 56 self->o = new_aubio_filter (self->order , self->channels);46 self->o = new_aubio_filter (self->order); 57 47 if (self->o == NULL) { 58 48 return -1; … … 92 82 #if 1 93 83 aubio_filter_do (((Py_filter *)self)->o, vec->o); 94 Py _INCREF(vec);84 PyArray_INCREF((PyArrayObject*)vec); 95 85 return (PyObject *)vec; 96 86 #else 97 87 Py_fvec *copy = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); 98 copy->o = new_fvec(vec->o->length , vec->o->channels);88 copy->o = new_fvec(vec->o->length); 99 89 aubio_filter_do_outplace (((Py_filter *)self)->o, vec->o, copy->o); 100 90 return (PyObject *)copy; … … 142 132 {"order", T_INT, offsetof (Py_filter, order), READONLY, 143 133 "order of the filter"}, 144 {"channels", T_INT, offsetof (Py_filter, channels), READONLY,145 "number of channels"},146 134 {NULL} /* Sentinel */ 147 135 }; -
interfaces/python/py-filterbank.c
r0536612 rf658288 68 68 69 69 output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); 70 output->channels = vec->channels;71 70 output->length = self->n_filters; 72 output->o = new_fvec(self->n_filters , vec->channels);71 output->o = new_fvec(self->n_filters); 73 72 74 73 // compute the function … … 138 137 Py_filterbank_get_coeffs (Py_filterbank * self, PyObject *unused) 139 138 { 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; 139 Py_fmat *output = (Py_fmat *) PyObject_New (Py_fmat, &Py_fvecType); 143 140 output->o = aubio_filterbank_get_coeffs (self->o); 144 return (PyObject *)PyAubio_F vecToArray(output);141 return (PyObject *)PyAubio_FmatToArray(output); 145 142 } 146 143 -
interfaces/python/py-fvec.c
r0536612 rf658288 4 4 5 5 class fvec(): 6 def __init__(self, length = 1024 , channels = 1):6 def __init__(self, length = 1024): 7 7 self.length = length 8 self.channels = channels 9 self.data = array(length, channels) 8 self.data = array(length) 10 9 11 10 */ … … 16 15 Py_fvec_new (PyTypeObject * type, PyObject * args, PyObject * kwds) 17 16 { 18 int length= 0 , channels = 0;17 int length= 0; 19 18 Py_fvec *self; 20 static char *kwlist[] = { "length", "channels", NULL }; 21 22 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist, 23 &length, &channels)) { 24 return NULL; 25 } 26 19 static char *kwlist[] = { "length", NULL }; 20 21 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist, 22 &length)) { 23 return NULL; 24 } 27 25 28 26 self = (Py_fvec *) type->tp_alloc (type, 0); 29 27 30 28 self->length = Py_default_vector_length; 31 self->channels = Py_default_vector_channels;32 29 33 30 if (self == NULL) { … … 43 40 } 44 41 45 if (channels > 0) {46 self->channels = channels;47 } else if (channels < 0) {48 PyErr_SetString (PyExc_ValueError,49 "can not use negative number of channels");50 return NULL;51 }52 53 42 return (PyObject *) self; 54 43 } … … 57 46 Py_fvec_init (Py_fvec * self, PyObject * args, PyObject * kwds) 58 47 { 59 self->o = new_fvec (self->length , self->channels);48 self->o = new_fvec (self->length); 60 49 if (self->o == NULL) { 61 50 return -1; … … 75 64 Py_fvec_repr (Py_fvec * self, PyObject * unused) 76 65 { 66 #if 0 77 67 PyObject *format = NULL; 78 68 PyObject *args = NULL; 79 69 PyObject *result = NULL; 80 70 81 format = PyString_FromString ("aubio fvec of %d elements with %d channels");71 format = PyString_FromString ("aubio fvec of %d elements"); 82 72 if (format == NULL) { 83 73 goto fail; 84 74 } 85 75 86 args = Py_BuildValue ("I I", self->length, self->channels);76 args = Py_BuildValue ("I", self->length); 87 77 if (args == NULL) { 88 78 goto fail; … … 92 82 result = PyString_Format (format, args); 93 83 84 fail: 85 Py_XDECREF (format); 86 Py_XDECREF (args); 87 88 return result; 89 #endif 90 PyObject *format = NULL; 91 PyObject *args = NULL; 92 PyObject *result = NULL; 93 94 format = PyString_FromString ("%s"); 95 if (format == NULL) { 96 goto fail; 97 } 98 99 args = Py_BuildValue ("O", PyAubio_FvecToArray (self)); 100 if (args == NULL) { 101 goto fail; 102 } 103 104 result = PyString_Format (format, args); 94 105 fail: 95 106 Py_XDECREF (format); … … 103 114 PyObject *array; 104 115 Py_fvec *vec; 105 uint_t i;106 116 if (input == NULL) { 107 117 PyErr_SetString (PyExc_ValueError, "input array is not a python object"); … … 118 128 PyErr_SetString (PyExc_ValueError, "input array is a scalar"); 119 129 goto fail; 120 } else if (PyArray_NDIM (input) > 2) {130 } else if (PyArray_NDIM (input) > 1) { 121 131 PyErr_SetString (PyExc_ValueError, 122 "input array has more than twodimensions");132 "input array has more than one dimensions"); 123 133 goto fail; 124 134 } … … 127 137 PyErr_SetString (PyExc_ValueError, "input array should be float"); 128 138 goto fail; 129 #if AUBIO_DO_CASTING130 } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) {131 // input data type is not float32, casting132 array = PyArray_Cast ( (PyArrayObject*) input, AUBIO_NPY_SMPL);133 if (array == NULL) {134 PyErr_SetString (PyExc_IndexError, "failed converting to AUBIO_NPY_SMPL");135 goto fail;136 }137 #else138 139 } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) { 139 140 PyErr_SetString (PyExc_ValueError, "input array should be float32"); 140 141 goto fail; 141 #endif142 142 } else { 143 143 // input data type is float32, nothing else to do … … 147 147 // create a new fvec object 148 148 vec = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); 149 if (PyArray_NDIM (array) == 1) { 150 vec->channels = 1; 151 vec->length = PyArray_SIZE (array); 152 } else { 153 vec->channels = PyArray_DIM (array, 0); 154 vec->length = PyArray_DIM (array, 1); 155 } 149 vec->length = PyArray_SIZE (array); 156 150 157 151 // no need to really allocate fvec, just its struct member 158 // vec->o = new_fvec (vec->length , vec->channels);152 // vec->o = new_fvec (vec->length); 159 153 vec->o = (fvec_t *)malloc(sizeof(fvec_t)); 160 vec->o->length = vec->length; vec->o->channels = vec->channels; 161 vec->o->data = (smpl_t**)malloc(vec->o->channels * sizeof(smpl_t*)); 162 // hat data[i] point to array line 163 for (i = 0; i < vec->channels; i++) { 164 vec->o->data[i] = (smpl_t *) PyArray_GETPTR1 (array, i); 165 } 166 154 vec->o->length = vec->length; 155 vec->o->data = (smpl_t *) PyArray_GETPTR1 (array, 0); 156 157 } else if (PyObject_TypeCheck (input, &PyList_Type)) { 158 PyErr_SetString (PyExc_ValueError, "does not convert from list yet"); 159 return NULL; 167 160 } else { 168 PyErr_SetString (PyExc_ValueError, "can only accept arrayor fvec as input");161 PyErr_SetString (PyExc_ValueError, "can only accept vector or fvec as input"); 169 162 return NULL; 170 163 } … … 179 172 PyAubio_CFvecToArray (fvec_t * self) 180 173 { 181 PyObject *array = NULL;182 uint_t i;183 174 npy_intp dims[] = { self->length, 1 }; 184 PyObject *concat = PyList_New (0), *tmp = NULL; 185 for (i = 0; i < self->channels; i++) { 186 tmp = PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->data[i]); 187 PyList_Append (concat, tmp); 188 Py_DECREF (tmp); 189 } 190 array = PyArray_FromObject (concat, AUBIO_NPY_SMPL, 2, 2); 191 Py_DECREF (concat); 192 return array; 175 return PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->data); 193 176 } 194 177 … … 197 180 { 198 181 PyObject *array = NULL; 199 if (self->channels == 1) { 200 npy_intp dims[] = { self->length, 1 }; 201 array = PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->o->data[0]); 202 } else { 203 uint_t i; 204 npy_intp dims[] = { self->length, 1 }; 205 PyObject *concat = PyList_New (0), *tmp = NULL; 206 for (i = 0; i < self->channels; i++) { 207 tmp = PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->o->data[i]); 208 PyList_Append (concat, tmp); 209 Py_DECREF (tmp); 210 } 211 array = PyArray_FromObject (concat, AUBIO_NPY_SMPL, 2, 2); 212 Py_DECREF (concat); 213 } 182 npy_intp dims[] = { self->length, 1 }; 183 array = PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->o->data); 214 184 return array; 215 }216 217 static Py_ssize_t218 Py_fvec_getchannels (Py_fvec * self)219 {220 return self->channels;221 185 } 222 186 … … 224 188 Py_fvec_getitem (Py_fvec * self, Py_ssize_t index) 225 189 { 226 PyObject *array; 227 228 if (index < 0 || index >= self->channels) { 229 PyErr_SetString (PyExc_IndexError, "no such channel"); 230 return NULL; 231 } 232 233 npy_intp dims[] = { self->length, 1 }; 234 array = PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->o->data[index]); 235 return array; 190 if (index < 0 || index >= self->length) { 191 PyErr_SetString (PyExc_IndexError, "no such element"); 192 return NULL; 193 } 194 195 return PyFloat_FromDouble (self->o->data[index]); 236 196 } 237 197 … … 239 199 Py_fvec_setitem (Py_fvec * self, Py_ssize_t index, PyObject * o) 240 200 { 241 PyObject *array; 242 243 if (index < 0 || index >= self->channels) { 244 PyErr_SetString (PyExc_IndexError, "no such channel"); 245 return -1; 246 } 247 248 array = PyArray_FROM_OT (o, AUBIO_NPY_SMPL); 249 if (array == NULL) { 250 PyErr_SetString (PyExc_ValueError, "should be an array of float"); 251 goto fail; 252 } 253 254 if (PyArray_NDIM (array) != 1) { 255 PyErr_SetString (PyExc_ValueError, "should be a one-dimensional array"); 256 goto fail; 257 } 258 259 if (PyArray_SIZE (array) != self->length) { 260 PyErr_SetString (PyExc_ValueError, 261 "should be an array of same length as target fvec"); 262 goto fail; 263 } 264 265 self->o->data[index] = (smpl_t *) PyArray_GETPTR1 (array, 0); 201 202 if (index < 0 || index >= self->length) { 203 PyErr_SetString (PyExc_IndexError, "no such element"); 204 goto fail; 205 } 206 207 if (PyFloat_Check (o)) { 208 PyErr_SetString (PyExc_ValueError, "should be a float"); 209 goto fail; 210 } 211 212 self->o->data[index] = (smpl_t) PyFloat_AsDouble(o); 266 213 267 214 return 0; … … 269 216 fail: 270 217 return -1; 218 } 219 220 int 221 Py_fvec_get_length (Py_fvec * self) 222 { 223 return self->length; 271 224 } 272 225 … … 275 228 {"length", T_INT, offsetof (Py_fvec, length), READONLY, 276 229 "length attribute"}, 277 {"channels", T_INT, offsetof (Py_fvec, channels), READONLY,278 "channels attribute"},279 230 {NULL} /* Sentinel */ 280 231 }; … … 287 238 288 239 static PySequenceMethods Py_fvec_tp_as_sequence = { 289 (lenfunc) Py_fvec_get channels, /* sq_length */240 (lenfunc) Py_fvec_get_length, /* sq_length */ 290 241 0, /* sq_concat */ 291 242 0, /* sq_repeat */ -
interfaces/python/py-phasevoc.c
r0536612 rf658288 3 3 static char Py_pvoc_doc[] = "pvoc object"; 4 4 5 AUBIO_DECLARE(pvoc, uint_t win_s; uint_t hop_s ; uint_t channels)5 AUBIO_DECLARE(pvoc, uint_t win_s; uint_t hop_s) 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 , channels = 0;11 int win_s = 0, hop_s = 0; 12 12 Py_pvoc *self; 13 static char *kwlist[] = { "win_s", "hop_s", "channels",NULL };13 static char *kwlist[] = { "win_s", "hop_s", NULL }; 14 14 15 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II I", kwlist,16 &win_s, &hop_s , &channels)) {15 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist, 16 &win_s, &hop_s)) { 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;29 28 30 29 if (self == NULL) { … … 48 47 } 49 48 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 58 49 return (PyObject *) self; 59 50 } 60 51 61 52 62 AUBIO_INIT(pvoc, self->win_s, self->hop_s , self->channels)53 AUBIO_INIT(pvoc, self->win_s, self->hop_s) 63 54 64 55 AUBIO_DEL(pvoc) … … 82 73 83 74 output = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); 84 output->channels = vec->channels;85 75 output->length = ((Py_pvoc *) self)->win_s; 86 output->o = new_cvec(((Py_pvoc *) self)->win_s , vec->channels);76 output->o = new_cvec(((Py_pvoc *) self)->win_s); 87 77 88 78 // compute the function … … 98 88 {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY, 99 89 "size of the hop"}, 100 {"channels", T_INT, offsetof (Py_pvoc, channels), READONLY,101 "number of channels"},102 90 AUBIO_MEMBERS_STOP(pvoc) 103 91 … … 120 108 121 109 output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); 122 output->channels = vec->channels;123 110 output->length = ((Py_pvoc *) self)->hop_s; 124 output->o = new_fvec(output->length , output->channels);111 output->o = new_fvec(output->length); 125 112 126 113 // compute the function -
interfaces/python/setup.py
r0536612 rf658288 11 11 ["aubiomodule.c", 12 12 "py-fvec.c", 13 "py-fmat.c", 13 14 "py-cvec.c", 14 15 "py-filter.c", -
interfaces/python/test_aubio.py
r0536612 rf658288 3 3 from _aubio import * 4 4 from numpy import array 5 6 AUBIO_DO_CASTING = 07 5 8 6 class aubiomodule_test_case(TestCase): … … 11 9 """ try importing aubio """ 12 10 13 def test_vector(self):14 a = fvec()15 a.length, a.channels16 a[0]17 array(a)18 a = fvec(10)19 a = fvec(1, 2)20 array(a).T21 a[0] = range(a.length)22 a[1][0] = 223 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 fails44 a = array(1, dtype = 'float32')45 self.assertRaises (ValueError, alpha_norm, a, 1)46 # check 3d array fails47 a = array([[[1,2],[3,4]]], dtype = 'float32')48 self.assertRaises (ValueError, alpha_norm, a, 1)49 # check 1d array50 a = array(range(10), dtype = 'float32')51 self.assertEquals (alpha_norm(a, 1), 4.5)52 # check 2d array53 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 fail80 a = array(1, dtype = 'float64')81 self.assertRaises (ValueError, alpha_norm, a, 1)82 # check 3d array fail83 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 fail87 a = array(range(10), dtype = 'float64')88 self.assertEquals (alpha_norm(a, 1), 4.5)89 # check float64 2d array fail90 a = array([range(10), range(10)], dtype = 'float64')91 self.assertEquals (alpha_norm(a, 1), 9)92 else:93 # check float64 1d array fail94 a = array(range(10), dtype = 'float64')95 self.assertRaises (ValueError, alpha_norm, a, 1)96 # check float64 2d array fail97 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] = 0107 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)126 11 127 12 if __name__ == '__main__': -
src/aubio.h
r0536612 rf658288 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 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 51 ::fvec_t structures are used to store vectors of floating pointer number. 52 ::cvec_t are used to store complex number, as two vectors of norm and phase 53 elements. 54 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 , channels);66 aubio_fft_t *fft = new_aubio_fft (winsize); 67 67 // phase vocoder 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);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); 73 73 // beat tracking 74 aubio_tempo_t *tempo = new_aubio_tempo (method, winsize, stepsize, channels,samplerate);74 aubio_tempo_t *tempo = new_aubio_tempo (method, winsize, stepsize, 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 channels, window size, and sampling rate88 uint_t channels = 2,winsize = 1024, sr = 44100;87 // set window size, and sampling rate 88 uint_t winsize = 1024, sr = 44100; 89 89 // create a vector 90 fvec_t *this_buffer = new_fvec (winsize , channels);90 fvec_t *this_buffer = new_fvec (winsize); 91 91 // create the a-weighting filter 92 aubio_filter_t *this_filter = new_aubio_filter_a_weighting ( channels,sr);93 92 aubio_filter_t *this_filter = new_aubio_filter_a_weighting (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" 160 161 #include "musicutils.h" 161 162 #include "temporal/resampler.h" -
src/cvec.c
r0536612 rf658288 22 22 #include "cvec.h" 23 23 24 cvec_t * new_cvec( uint_t length , uint_t channels) {24 cvec_t * new_cvec( uint_t length) { 25 25 cvec_t * s = AUBIO_NEW(cvec_t); 26 uint_t i,j; 27 s->channels = channels; 26 uint_t j; 28 27 s->length = length/2 + 1; 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 } 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.; 38 33 } 39 34 return s; … … 41 36 42 37 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 }48 38 AUBIO_FREE(s->norm); 49 39 AUBIO_FREE(s->phas); … … 51 41 } 52 42 53 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_tposition) {54 s->norm[ channel][position] = data;43 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position) { 44 s->norm[position] = data; 55 45 } 56 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_tposition) {57 s->phas[ channel][position] = data;46 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position) { 47 s->phas[position] = data; 58 48 } 59 smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_tposition) {60 return s->norm[ channel][position];49 smpl_t cvec_read_norm(cvec_t *s, uint_t position) { 50 return s->norm[position]; 61 51 } 62 smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_tposition) {63 return s->phas[ channel][position];52 smpl_t cvec_read_phas(cvec_t *s, uint_t position) { 53 return s->phas[position]; 64 54 } 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) { 55 smpl_t * cvec_get_norm(cvec_t *s) { 78 56 return s->norm; 79 57 } 80 smpl_t * *cvec_get_phas(cvec_t *s) {58 smpl_t * cvec_get_phas(cvec_t *s) { 81 59 return s->phas; 82 60 } … … 85 63 86 64 void cvec_print(cvec_t *s) { 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"); 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]); 99 69 } 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"); 100 76 } 101 77 102 78 void cvec_set(cvec_t *s, smpl_t 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 } 79 uint_t j; 80 for (j=0; j< s->length; j++) { 81 s->norm[j] = val; 108 82 } 109 83 } -
src/cvec.h
r0536612 rf658288 39 39 typedef struct { 40 40 uint_t length; /**< length of buffer = (requested length)/2 + 1 */ 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] */ 41 smpl_t *norm; /**< norm array of size [length] */ 42 smpl_t *phas; /**< phase array of size [length] */ 44 43 } cvec_t; 45 44 … … 47 46 48 47 This function creates a cvec_t structure holding two arrays of size 49 [length/2+1] * channels, corresponding to the norm and phase values of the48 [length/2+1], corresponding to the norm and phase values of the 50 49 spectral frame. The length stored in the structure is the actual size of both 51 50 arrays, not the length of the complex and symetrical vector, specified as … … 53 52 54 53 \param length the length of the buffer to create 55 \param channels the number of channels in the buffer56 54 57 55 */ 58 cvec_t * new_cvec(uint_t length , uint_t channels);56 cvec_t * new_cvec(uint_t length); 59 57 /** cvec_t buffer deletion function 60 58 … … 66 64 67 65 Note that this function is not used in the aubio library, since the same 68 result can be obtained by assigning vec->norm[ channel][position]. Its purpose66 result can be obtained by assigning vec->norm[position]. Its purpose 69 67 is to access these values from wrappers, as created by swig. 70 68 71 69 \param s vector to write to 72 \param data norm value to write in s->norm[channel][position] 73 \param channel channel to write to 70 \param data norm value to write in s->norm[position] 74 71 \param position sample position to write to 75 72 76 73 */ 77 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_tposition);74 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t position); 78 75 /** write phase value in a complex buffer 79 76 80 77 Note that this function is not used in the aubio library, since the same 81 result can be obtained by assigning vec->phas[ channel][position]. Its purpose78 result can be obtained by assigning vec->phas[position]. Its purpose 82 79 is to access these values from wrappers, as created by swig. 83 80 84 81 \param s vector to write to 85 \param data phase value to write in s->phas[channel][position] 86 \param channel channel to write to 82 \param data phase value to write in s->phas[position] 87 83 \param position sample position to write to 88 84 89 85 */ 90 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_tposition);86 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t position); 91 87 /** read norm value from a complex buffer 92 88 93 89 Note that this function is not used in the aubio library, since the same 94 result can be obtained with vec->norm[ channel][position]. Its purpose is to90 result can be obtained with vec->norm[position]. Its purpose is to 95 91 access these values from wrappers, as created by swig. 96 92 97 93 \param s vector to read from 98 \param channel channel to read from99 94 \param position sample position to read from 100 95 101 96 */ 102 smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_tposition);97 smpl_t cvec_read_norm(cvec_t *s, uint_t position); 103 98 /** read phase value from a complex buffer 104 99 105 100 Note that this function is not used in the aubio library, since the same 106 result can be obtained with vec->phas[ channel][position]. Its purpose is to101 result can be obtained with vec->phas[position]. Its purpose is to 107 102 access these values from wrappers, as created by swig. 108 103 109 104 \param s vector to read from 110 \param channel channel to read from111 105 \param position sample position to read from 112 106 113 107 */ 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); 108 smpl_t cvec_read_phas(cvec_t *s, uint_t position); 161 109 /** read norm data from a complex buffer 162 110 … … 168 116 169 117 */ 170 smpl_t * *cvec_get_norm(cvec_t *s);118 smpl_t * cvec_get_norm(cvec_t *s); 171 119 /** read phase data from a complex buffer 172 120 … … 178 126 179 127 */ 180 smpl_t * *cvec_get_phas(cvec_t *s);128 smpl_t * cvec_get_phas(cvec_t *s); 181 129 182 130 /** print out cvec data -
src/fvec.c
r0536612 rf658288 22 22 #include "fvec.h" 23 23 24 fvec_t * new_fvec( uint_t length , uint_t channels) {24 fvec_t * new_fvec( uint_t length) { 25 25 fvec_t * s = AUBIO_NEW(fvec_t); 26 uint_t i,j; 27 s->channels = channels; 26 uint_t j; 28 27 s->length = length; 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 } 28 s->data = AUBIO_ARRAY(smpl_t, s->length); 29 for (j=0; j< s->length; j++) { 30 s->data[j]=0.; 35 31 } 36 32 return s; … … 38 34 39 35 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 }44 36 AUBIO_FREE(s->data); 45 37 AUBIO_FREE(s); 46 38 } 47 39 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]; 40 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t position) { 41 s->data[position] = data; 59 42 } 60 43 61 smpl_t ** fvec_get_data(fvec_t *s) { 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) { 62 49 return s->data; 63 50 } … … 66 53 67 54 void fvec_print(fvec_t *s) { 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"); 55 uint_t j; 56 for (j=0; j< s->length; j++) { 57 AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]); 74 58 } 59 AUBIO_MSG("\n"); 75 60 } 76 61 77 62 void fvec_set(fvec_t *s, smpl_t 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 } 63 uint_t j; 64 for (j=0; j< s->length; j++) { 65 s->data[j] = val; 83 66 } 84 67 } … … 93 76 94 77 void fvec_rev(fvec_t *s) { 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 } 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]); 100 81 } 101 82 } 102 83 103 84 void fvec_weight(fvec_t *s, fvec_t *weight) { 104 uint_t i,j;85 uint_t j; 105 86 uint_t length = MIN(s->length, weight->length); 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 } 87 for (j=0; j< length; j++) { 88 s->data[j] *= weight->data[j]; 110 89 } 111 90 } 112 91 113 92 void fvec_copy(fvec_t *s, fvec_t *t) { 114 uint_t i,j; 115 uint_t channels = MIN(s->channels, t->channels); 93 uint_t j; 116 94 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 }121 95 if (s->length != t->length) { 122 AUBIO_ ERR("warning,trying to copy %d elements to %d elements \n",96 AUBIO_WRN("trying to copy %d elements to %d elements \n", 123 97 s->length, t->length); 124 98 } 125 for (i=0; i< channels; i++) { 126 for (j=0; j< length; j++) { 127 t->data[i][j] = s->data[i][j]; 128 } 99 for (j=0; j< length; j++) { 100 t->data[j] = s->data[j]; 129 101 } 130 102 } -
src/fvec.h
r0536612 rf658288 38 38 typedef struct { 39 39 uint_t length; /**< length of buffer */ 40 uint_t channels; /**< number of channels */ 41 smpl_t **data; /**< data array of size [length] * [channels] */ 40 smpl_t *data; /**< data array of size [length] */ 42 41 } fvec_t; 43 42 … … 45 44 46 45 \param length the length of the buffer to create 47 \param channels the number of channels in the buffer48 46 49 47 */ 50 fvec_t * new_fvec(uint_t length , uint_t channels);48 fvec_t * new_fvec(uint_t length); 51 49 /** fvec_t buffer deletion function 52 50 … … 58 56 59 57 Note that this function is not used in the aubio library, since the same 60 result can be obtained using vec->data[ channel][position]. Its purpose is to58 result can be obtained using vec->data[position]. Its purpose is to 61 59 access these values from wrappers, as created by swig. 62 60 63 61 \param s vector to read from 64 \param channel channel to read from65 62 \param position sample position to read from 66 63 67 64 */ 68 smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_tposition);65 smpl_t fvec_read_sample(fvec_t *s, uint_t position); 69 66 /** write sample value in a buffer 70 67 71 68 Note that this function is not used in the aubio library, since the same 72 result can be obtained by assigning vec->data[ channel][position]. Its purpose69 result can be obtained by assigning vec->data[position]. Its purpose 73 70 is to access these values from wrappers, as created by swig. 74 71 75 72 \param s vector to write to 76 \param data value to write in s->data[channel][position] 77 \param channel channel to write to 73 \param data value to write in s->data[position] 78 74 \param position sample position to write to 79 75 80 76 */ 81 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position); 82 /** read channel vector from a buffer 77 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t position); 83 78 84 Note that this function is not used in the aubio library, since the same85 result can be obtained with vec->data[channel]. Its purpose is to access86 these values from wrappers, as created by swig.87 88 \param s vector to read from89 \param channel channel to read from90 91 */92 smpl_t * fvec_get_channel(fvec_t *s, uint_t channel);93 /** write channel vector into a buffer94 95 Note that this function is not used in the aubio library, since the same96 result can be obtained by assigning vec->data[channel]. Its purpose is to97 access these values from wrappers, as created by swig.98 99 \param s vector to write to100 \param data vector of [length] values to write101 \param channel channel to write to102 103 */104 void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel);105 79 /** read data from a buffer 106 80 … … 112 86 113 87 */ 114 smpl_t * *fvec_get_data(fvec_t *s);88 smpl_t * fvec_get_data(fvec_t *s); 115 89 116 90 /** print out fvec data -
src/lvec.c
r0536612 rf658288 22 22 #include "lvec.h" 23 23 24 lvec_t * new_lvec( uint_t length , uint_t channels) {24 lvec_t * new_lvec( uint_t length) { 25 25 lvec_t * s = AUBIO_NEW(lvec_t); 26 uint_t i,j; 27 s->channels = channels; 26 uint_t j; 28 27 s->length = length; 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 } 28 s->data = AUBIO_ARRAY(lsmp_t, s->length); 29 for (j=0; j< s->length; j++) { 30 s->data[j]=0.; 35 31 } 36 32 return s; … … 38 34 39 35 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 }44 36 AUBIO_FREE(s->data); 45 37 AUBIO_FREE(s); 46 38 } 47 39 48 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_tposition) {49 s->data[ channel][position] = data;40 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position) { 41 s->data[position] = data; 50 42 } 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]; 43 lsmp_t lvec_read_sample(lvec_t *s, uint_t position) { 44 return s->data[position]; 59 45 } 60 46 61 lsmp_t * *lvec_get_data(lvec_t *s) {47 lsmp_t * lvec_get_data(lvec_t *s) { 62 48 return s->data; 63 49 } … … 66 52 67 53 void lvec_print(lvec_t *s) { 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"); 54 uint_t j; 55 for (j=0; j< s->length; j++) { 56 AUBIO_MSG(AUBIO_LSMP_FMT " ", s->data[j]); 74 57 } 58 AUBIO_MSG("\n"); 75 59 } 76 60 77 61 void lvec_set(lvec_t *s, smpl_t 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 } 62 uint_t j; 63 for (j=0; j< s->length; j++) { 64 s->data[j] = val; 83 65 } 84 66 } -
src/lvec.h
r0536612 rf658288 39 39 typedef struct { 40 40 uint_t length; /**< length of buffer */ 41 uint_t channels; /**< number of channels */ 42 lsmp_t **data; /**< data array of size [length] * [channels] */ 41 lsmp_t *data; /**< data array of size [length] */ 43 42 } lvec_t; 44 43 … … 46 45 47 46 \param length the length of the buffer to create 48 \param channels the number of channels in the buffer49 47 50 48 */ 51 lvec_t * new_lvec(uint_t length , uint_t channels);49 lvec_t * new_lvec(uint_t length); 52 50 /** lvec_t buffer deletion function 53 51 … … 59 57 60 58 Note that this function is not used in the aubio library, since the same 61 result can be obtained using vec->data[ channel][position]. Its purpose is to59 result can be obtained using vec->data[position]. Its purpose is to 62 60 access these values from wrappers, as created by swig. 63 61 64 62 \param s vector to read from 65 \param channel channel to read from66 63 \param position sample position to read from 67 64 68 65 */ 69 lsmp_t lvec_read_sample(lvec_t *s, uint_t channel, uint_tposition);66 lsmp_t lvec_read_sample(lvec_t *s, uint_t position); 70 67 /** write sample value in a buffer 71 68 72 69 Note that this function is not used in the aubio library, since the same 73 result can be obtained by assigning vec->data[ channel][position]. Its purpose70 result can be obtained by assigning vec->data[position]. Its purpose 74 71 is to access these values from wrappers, as created by swig. 75 72 76 73 \param s vector to write to 77 \param data value to write in s->data[channel][position] 78 \param channel channel to write to 74 \param data value to write in s->data[position] 79 75 \param position sample position to write to 80 76 81 77 */ 82 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_t position); 83 /** read channel vector from a buffer 78 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position); 84 79 85 Note that this function is not used in the aubio library, since the same86 result can be obtained with vec->data[channel]. Its purpose is to access87 these values from wrappers, as created by swig.88 89 \param s vector to read from90 \param channel channel to read from91 92 */93 lsmp_t * lvec_get_channel(lvec_t *s, uint_t channel);94 /** write channel vector into a buffer95 96 Note that this function is not used in the aubio library, since the same97 result can be obtained by assigning vec->data[channel]. Its purpose is to98 access these values from wrappers, as created by swig.99 100 \param s vector to write to101 \param data vector of [length] values to write102 \param channel channel to write to103 104 */105 void lvec_put_channel(lvec_t *s, lsmp_t * data, uint_t channel);106 80 /** read data from a buffer 107 81 … … 113 87 114 88 */ 115 lsmp_t * *lvec_get_data(lvec_t *s);89 lsmp_t * lvec_get_data(lvec_t *s); 116 90 117 91 /** print out lvec data -
src/mathutils.c
r0536612 rf658288 46 46 new_aubio_window (char_t * window_type, uint_t size) 47 47 { 48 // create fvec of size x 1 channel 49 fvec_t * win = new_fvec( size, 1); 50 smpl_t * w = win->data[0]; 48 fvec_t * win = new_fvec (size); 49 smpl_t * w = win->data; 51 50 uint_t i; 52 51 aubio_window_type wintype; … … 134 133 fvec_mean (fvec_t * s) 135 134 { 136 uint_t i,j;135 uint_t j; 137 136 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];137 for (j = 0; j < s->length; j++) { 138 tmp += s->data[j]; 139 } 141 140 return tmp / (smpl_t) (s->length); 142 141 } 143 142 144 143 smpl_t 145 fvec_ mean_channel (fvec_t * s, uint_t i)144 fvec_sum (fvec_t * s) 146 145 { 147 146 uint_t j; 148 147 smpl_t tmp = 0.0; 149 for (j = 0; j < s->length; j++) 150 tmp += s->data[i][j]; 151 return tmp / (smpl_t) (s->length); 152 } 153 154 smpl_t 155 fvec_sum (fvec_t * s) 156 { 157 uint_t i, j; 148 for (j = 0; j < s->length; j++) { 149 tmp += s->data[j]; 150 } 151 return tmp; 152 } 153 154 smpl_t 155 fvec_max (fvec_t * s) 156 { 157 uint_t j; 158 158 smpl_t tmp = 0.0; 159 for (i = 0; i < s->channels; i++) { 160 for (j = 0; j < s->length; j++) { 161 tmp += s->data[i][j]; 162 } 159 for (j = 0; j < s->length; j++) { 160 tmp = (tmp > s->data[j]) ? tmp : s->data[j]; 163 161 } 164 162 return tmp; … … 166 164 167 165 smpl_t 168 fvec_max (fvec_t * s)169 {170 uint_t i, j;171 smpl_t tmp = 0.0;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 }176 }177 return tmp;178 }179 180 smpl_t181 166 fvec_min (fvec_t * s) 182 167 { 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 } 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]; 189 172 } 190 173 return tmp; … … 194 177 fvec_min_elem (fvec_t * s) 195 178 { 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 } 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]; 203 184 } 204 185 return pos; … … 208 189 fvec_max_elem (fvec_t * s) 209 190 { 210 uint_t i,j, pos = 0;191 uint_t j, pos = 0; 211 192 smpl_t tmp = 0.0; 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 } 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]; 217 196 } 218 197 return pos; … … 222 201 fvec_shift (fvec_t * s) 223 202 { 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 } 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]); 229 206 } 230 207 } … … 234 211 { 235 212 smpl_t energy = 0.; 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 } 213 uint_t j; 214 for (j = 0; j < f->length; j++) { 215 energy += SQR (f->data[j]); 241 216 } 242 217 return energy; … … 247 222 { 248 223 smpl_t hfc = 0.; 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 } 224 uint_t j; 225 for (j = 0; j < v->length; j++) { 226 hfc += (j + 1) * v->data[j]; 254 227 } 255 228 return hfc; … … 266 239 fvec_alpha_norm (fvec_t * o, smpl_t alpha) 267 240 { 268 uint_t i,j;241 uint_t j; 269 242 smpl_t tmp = 0.; 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 } 243 for (j = 0; j < o->length; j++) { 244 tmp += POW (ABS (o->data[j]), alpha); 274 245 } 275 246 return POW (tmp / o->length, 1. / alpha); … … 279 250 fvec_alpha_normalise (fvec_t * o, smpl_t alpha) 280 251 { 281 uint_t i,j;252 uint_t j; 282 253 smpl_t norm = fvec_alpha_norm (o, alpha); 283 for (i = 0; i < o->channels; i++) { 284 for (j = 0; j < o->length; j++) { 285 o->data[i][j] /= norm; 286 } 254 for (j = 0; j < o->length; j++) { 255 o->data[j] /= norm; 287 256 } 288 257 } … … 291 260 fvec_add (fvec_t * o, smpl_t val) 292 261 { 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 } 262 uint_t j; 263 for (j = 0; j < o->length; j++) { 264 o->data[j] += val; 298 265 } 299 266 } 300 267 301 268 void fvec_adapt_thres(fvec_t * vec, fvec_t * tmp, 302 uint_t post, uint_t pre , uint_t channel) {303 uint_t length = vec->length, i=channel,j;269 uint_t post, uint_t pre) { 270 uint_t length = vec->length, j; 304 271 for (j=0;j<length;j++) { 305 vec->data[ i][j] -= fvec_moving_thres(vec, tmp, post, pre, j, i);272 vec->data[j] -= fvec_moving_thres(vec, tmp, post, pre, j); 306 273 } 307 274 } … … 309 276 smpl_t 310 277 fvec_moving_thres (fvec_t * vec, fvec_t * tmpvec, 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];278 uint_t post, uint_t pre, uint_t pos) 279 { 280 uint_t k; 281 smpl_t *medar = (smpl_t *) tmpvec->data; 315 282 uint_t win_length = post + pre + 1; 316 283 uint_t length = vec->length; … … 320 287 medar[k] = 0.; /* 0-padding at the beginning */ 321 288 for (k = post + 1 - pos; k < win_length; k++) 322 medar[k] = vec->data[ 0][k + pos - post];289 medar[k] = vec->data[k + pos - post]; 323 290 /* the buffer is fully defined */ 324 291 } else if (pos + pre < length) { 325 292 for (k = 0; k < win_length; k++) 326 medar[k] = vec->data[ 0][k + pos - post];293 medar[k] = vec->data[k + pos - post]; 327 294 /* pre part of the buffer does not exist */ 328 295 } else { 329 296 for (k = 0; k < length - pos + post; k++) 330 medar[k] = vec->data[ 0][k + pos - post];297 medar[k] = vec->data[k + pos - post]; 331 298 for (k = length - pos + post; k < win_length; k++) 332 299 medar[k] = 0.; /* 0-padding at the end */ 333 300 } 334 return fvec_median _channel (tmpvec, i);335 } 336 337 smpl_t fvec_median _channel (fvec_t * input, uint_t channel) {301 return fvec_median (tmpvec); 302 } 303 304 smpl_t fvec_median (fvec_t * input) { 338 305 uint_t n = input->length; 339 smpl_t * arr = (smpl_t *) input->data [channel];306 smpl_t * arr = (smpl_t *) input->data; 340 307 uint_t low, high ; 341 308 uint_t median; … … 386 353 } 387 354 388 smpl_t fvec_quadint (fvec_t * x, uint_t pos , uint_t i) {355 smpl_t fvec_quadint (fvec_t * x, uint_t pos) { 389 356 smpl_t s0, s1, s2; 390 357 uint_t x0 = (pos < 1) ? pos : pos - 1; 391 358 uint_t x2 = (pos + 1 < x->length) ? pos + 1 : pos; 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];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]; 397 364 return pos + 0.5 * (s2 - s0 ) / (s2 - 2.* s1 + s0); 398 365 } 399 366 400 367 uint_t fvec_peakpick(fvec_t * onset, uint_t pos) { 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.); 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.); 406 372 return tmp; 407 373 } … … 512 478 aubio_zero_crossing_rate (fvec_t * input) 513 479 { 514 uint_t i = 0,j;480 uint_t j; 515 481 uint_t zcr = 0; 516 482 for (j = 1; j < input->length; j++) { 517 483 // previous was strictly negative 518 if (input->data[ i][j - 1] < 0.) {484 if (input->data[j - 1] < 0.) { 519 485 // current is positive or null 520 if (input->data[ i][j] >= 0.) {486 if (input->data[j] >= 0.) { 521 487 zcr += 1; 522 488 } … … 524 490 } else { 525 491 // current is strictly negative 526 if (input->data[ i][j] < 0.) {492 if (input->data[j] < 0.) { 527 493 zcr += 1; 528 494 } … … 535 501 aubio_autocorr (fvec_t * input, fvec_t * output) 536 502 { 537 uint_t i, j, k,length = input->length;503 uint_t i, j, length = input->length; 538 504 smpl_t *data, *acf; 539 505 smpl_t tmp = 0; 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); 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]; 549 512 } 513 acf[i] = tmp / (smpl_t) (length - i); 550 514 } 551 515 } -
src/mathutils.h
r0536612 rf658288 41 41 */ 42 42 smpl_t fvec_mean (fvec_t * s); 43 44 /** compute the mean of a vector channel45 46 \param s vector to compute mean from47 \param i channel to compute mean from48 49 \return the mean of v50 51 */52 smpl_t fvec_mean_channel (fvec_t * s, uint_t i);53 43 54 44 /** find the max of a vector … … 205 195 */ 206 196 smpl_t fvec_moving_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre, 207 uint_t pos , uint_t channel);197 uint_t pos); 208 198 209 199 /** apply adaptive threshold to a vector … … 218 208 219 209 */ 220 void fvec_adapt_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre, 221 uint_t channel); 210 void fvec_adapt_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre); 222 211 223 212 /** returns the median of a vector … … 232 221 233 222 \param v vector to get median from 234 \param channel channel to get median from235 223 236 224 \return the median of v 237 225 238 226 */ 239 smpl_t fvec_median _channel (fvec_t * v, uint_t channel);227 smpl_t fvec_median (fvec_t * v); 240 228 241 229 /** finds exact peak index by quadratic interpolation*/ 242 smpl_t fvec_quadint (fvec_t * x, uint_t pos , uint_t channel);230 smpl_t fvec_quadint (fvec_t * x, uint_t pos); 243 231 244 232 /** Quadratic interpolation using Lagrange polynomial. -
src/onset/onset.c
r0536612 rf658288 48 48 smpl_t isonset = 0; 49 49 smpl_t wasonset = 0; 50 uint_t i;51 50 aubio_pvoc_do (o->pv,input, o->fftgrain); 52 51 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 }*/57 52 aubio_peakpicker_do(o->pp, o->of, onset); 58 for (i = 0; i < input->channels; i++) { 59 isonset = onset->data[i][0]; 60 wasonset = o->wasonset->data[i][0]; 53 isonset = onset->data[0]; 54 wasonset = o->wasonset->data[0]; 61 55 if (isonset > 0.) { 62 56 if (aubio_silence_detection(input, o->silence)==1) { … … 74 68 wasonset++; 75 69 } 76 o->wasonset->data[i][0] = wasonset; 77 onset->data[i][0] = isonset; 78 } 70 o->wasonset->data[0] = wasonset; 71 onset->data[0] = isonset; 79 72 return; 80 73 } … … 98 91 /* Allocate memory for an onset detection */ 99 92 aubio_onset_t * new_aubio_onset (char_t * onset_mode, 100 uint_t buf_size, uint_t hop_size, uint_t channels, uint_tsamplerate)93 uint_t buf_size, uint_t hop_size, uint_t samplerate) 101 94 { 102 95 aubio_onset_t * o = AUBIO_NEW(aubio_onset_t); … … 105 98 o->minioi = 4; 106 99 o->silence = -70; 107 o->wasonset = new_fvec(1 , channels);100 o->wasonset = new_fvec(1); 108 101 o->samplerate = samplerate; 109 102 o->hop_size = hop_size; 110 o->pv = new_aubio_pvoc(buf_size, hop_size , channels);111 o->pp = new_aubio_peakpicker( channels);103 o->pv = new_aubio_pvoc(buf_size, hop_size); 104 o->pp = new_aubio_peakpicker(); 112 105 aubio_peakpicker_set_threshold (o->pp, o->threshold); 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);106 o->od = new_aubio_specdesc(onset_mode,buf_size); 107 o->fftgrain = new_cvec(buf_size); 108 o->of = new_fvec(1); 116 109 /*if (usedoubled) { 117 o2 = new_aubio_specdesc(onset_type2,buffer_size ,channels);118 onset2 = new_fvec(1 , channels);110 o2 = new_aubio_specdesc(onset_type2,buffer_size); 111 onset2 = new_fvec(1); 119 112 }*/ 120 113 return o; -
src/onset/onset.h
r0536612 rf658288 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 channels53 52 \param samplerate sampling rate of the input signal 54 53 55 54 */ 56 55 aubio_onset_t * new_aubio_onset (char_t * method, 57 uint_t buf_size, uint_t hop_size, uint_t channels, uint_tsamplerate);56 uint_t buf_size, uint_t hop_size, uint_t samplerate); 58 57 59 58 /** execute onset detection -
src/onset/peakpicker.c
r0536612 rf658288 28 28 29 29 /** function pointer to thresholding function */ 30 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input , uint_t channel);30 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input); 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 74 71 /** \bug should be used to calculate filter coefficients */ 75 72 /* cutoff: low-pass filter cutoff [0.34, 1] */ … … 97 94 smpl_t mean = 0., median = 0.; 98 95 uint_t length = p->win_post + p->win_pre + 1; 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]; 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]; 110 103 } 104 onset_keep->data[length - 1] = onset->data[0]; 105 onset_proc->data[length - 1] = onset->data[0]; 111 106 112 107 /* filter onset_proc */ … … 114 109 aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch); 115 110 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 } 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); 135 128 } 136 129 } … … 173 166 174 167 aubio_peakpicker_t * 175 new_aubio_peakpicker ( uint_t channels)168 new_aubio_peakpicker () 176 169 { 177 170 aubio_peakpicker_t *t = AUBIO_NEW (aubio_peakpicker_t); … … 179 172 t->win_post = 5; 180 173 t->win_pre = 1; 181 //channels = 1; 182 t->channels = channels; 183 184 t->thresholdfn = (aubio_thresholdfn_t) (fvec_median_channel); /* (fvec_mean); */ 174 175 t->thresholdfn = (aubio_thresholdfn_t) (fvec_median); /* (fvec_mean); */ 185 176 t->pickerfn = (aubio_pickerfn_t) (fvec_peakpick); 186 177 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);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); 192 183 193 184 /* cutoff: low-pass filter with cutoff reduced frequency at 0.34 … … 195 186 */ 196 187 t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789, 197 -0.59488894, 0.23484048 , channels);188 -0.59488894, 0.23484048); 198 189 199 190 return t; -
src/onset/peakpicker.h
r0536612 rf658288 36 36 37 37 /** peak-picker creation function */ 38 aubio_peakpicker_t * new_aubio_peakpicker( uint_t channels);38 aubio_peakpicker_t * new_aubio_peakpicker(void); 39 39 /** real time peak picking function */ 40 40 void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out); -
src/pitch/pitch.c
r0536612 rf658288 114 114 aubio_pitch_t * 115 115 new_aubio_pitch (char_t * pitch_mode, 116 uint_t bufsize, uint_t hopsize, uint_t channels, uint_tsamplerate)116 uint_t bufsize, uint_t hopsize, 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 , channels);144 p->buf = new_fvec (bufsize); 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 , 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);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); 154 154 p->callback = aubio_pitch_do_mcomb; 155 155 break; 156 156 case aubio_pitcht_fcomb: 157 p->buf = new_fvec (bufsize , channels);158 p->fcomb = new_aubio_pitchfcomb (bufsize, hopsize , channels);157 p->buf = new_fvec (bufsize); 158 p->fcomb = new_aubio_pitchfcomb (bufsize, hopsize); 159 159 p->callback = aubio_pitch_do_fcomb; 160 160 break; 161 161 case aubio_pitcht_schmitt: 162 p->buf = new_fvec (bufsize , channels);162 p->buf = new_fvec (bufsize); 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 , channels);167 p->buf = new_fvec (bufsize); 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 i,j = 0, overlap_size = 0;213 uint_t j = 0, overlap_size = 0; 214 214 overlap_size = p->buf->length - ibuf->length; 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 } 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]; 224 220 } 225 221 } … … 283 279 aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf) 284 280 { 285 uint_t i;286 281 p->callback (p, ibuf, obuf); 287 for (i = 0; i < obuf->channels; i++) { 288 p->freqconv (obuf->data[i][0], p->srate, p->bufsize); 289 } 282 obuf->data[0] = p->freqconv (obuf->data[0], p->srate, p->bufsize); 290 283 } 291 284 … … 293 286 aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf) 294 287 { 295 uint_t i;296 288 aubio_filter_do (p->filter, ibuf); 297 289 aubio_pvoc_do (p->pv, ibuf, p->fftgrain); 298 290 aubio_pitchmcomb_do (p->mcomb, p->fftgrain, obuf); 299 for (i = 0; i < obuf->channels; i++) { 300 obuf->data[i][0] = aubio_bintofreq (obuf->data[i][0], p->srate, p->bufsize); 301 } 291 obuf->data[0] = aubio_bintofreq (obuf->data[0], p->srate, p->bufsize); 302 292 } 303 293 … … 306 296 { 307 297 smpl_t pitch = 0.; 308 uint_t i;309 298 aubio_pitch_slideblock (p, ibuf); 310 299 aubio_pitchyin_do (p->yin, p->buf, obuf); 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 } 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; 320 307 } 321 308 … … 325 312 { 326 313 smpl_t pitch = 0.; 327 uint_t i;328 314 aubio_pitch_slideblock (p, ibuf); 329 315 aubio_pitchyinfft_do (p->yinfft, p->buf, obuf); 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 } 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; 339 323 } 340 324 … … 342 326 aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out) 343 327 { 344 uint_t i;345 328 aubio_pitch_slideblock (p, ibuf); 346 329 aubio_pitchfcomb_do (p->fcomb, p->buf, out); 347 for (i = 0; i < out->channels; i++) { 348 out->data[i][0] = aubio_bintofreq (out->data[i][0], p->srate, p->bufsize); 349 } 330 out->data[0] = aubio_bintofreq (out->data[0], p->srate, p->bufsize); 350 331 } 351 332 … … 354 335 { 355 336 smpl_t period, pitch = 0.; 356 uint_t i;357 337 aubio_pitch_slideblock (p, ibuf); 358 338 aubio_pitchschmitt_do (p->schmitt, p->buf, out); 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 } 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 } -
src/pitch/pitch.h
r0536612 rf658288 41 41 42 42 \param o pitch detection object as returned by new_aubio_pitch() 43 \param in input signal of size [hop_size x channels]44 \param out output pitch candidates of size [1 x channels]43 \param in input signal of size [hop_size] 44 \param out output pitch candidates of size [1] 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 analyse70 69 \param samplerate sampling rate of the signal 71 70 72 71 */ 73 72 aubio_pitch_t *new_aubio_pitch (char_t * method, 74 uint_t buf_size, uint_t hop_size, uint_t channels, uint_tsamplerate);73 uint_t buf_size, uint_t hop_size, uint_t samplerate); 75 74 76 75 /** set the output unit of the pitch detection object -
src/pitch/pitchfcomb.c
r0536612 rf658288 49 49 50 50 aubio_pitchfcomb_t * 51 new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize , uint_t channels)51 new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize) 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 , 1);57 p->fftOut = new_cvec (bufsize , 1);58 p->fftLastPhase = new_fvec (bufsize , channels);59 p->fft = new_aubio_fft (bufsize , 1);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); 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 i,k, l, maxharm = 0;68 uint_t 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 (i = 0; i < input->channels; i++) { 72 for (k = 0; k < MAX_PEAKS; k++) { 73 peaks[k].db = -200.; 74 peaks[k].bin = 0.; 75 } 73 76 74 for (k = 0; k < MAX_PEAKS; k++) { 75 peaks[k].db = -200.; 76 peaks[k].bin = 0.; 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); 81 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; 87 88 /* compute phase difference */ 89 tmp = phase - p->fftLastPhase->data[k]; 90 p->fftLastPhase->data[k] = phase; 91 92 /* subtract expected phase difference */ 93 tmp -= (smpl_t) k *phaseDifference; 94 95 /* map delta phase into +/- Pi interval */ 96 tmp = aubio_unwrap2pi (tmp); 97 98 /* get deviation from bin frequency from the +/- Pi interval */ 99 tmp = p->fftSize / (smpl_t) p->stepSize * tmp / (TWO_PI); 100 101 /* compute the k-th partials' true bin */ 102 bin = (smpl_t) k + tmp; 103 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; 77 108 } 109 } 78 110 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); 83 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; 89 90 /* compute phase difference */ 91 tmp = phase - p->fftLastPhase->data[i][k]; 92 p->fftLastPhase->data[i][k] = phase; 93 94 /* subtract expected phase difference */ 95 tmp -= (smpl_t) k *phaseDifference; 96 97 /* map delta phase into +/- Pi interval */ 98 tmp = aubio_unwrap2pi (tmp); 99 100 /* get deviation from bin frequency from the +/- Pi interval */ 101 tmp = p->fftSize / (smpl_t) p->stepSize * tmp / (TWO_PI); 102 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 } 111 } 112 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 } 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; 123 120 } 124 121 } 125 122 } 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.;130 123 } 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.; 131 128 } 132 129 -
src/pitch/pitchfcomb.h
r0536612 rf658288 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 on60 59 61 60 */ 62 aubio_pitchfcomb_t *new_aubio_pitchfcomb (uint_t buf_size, uint_t hop_size, 63 uint_t channels); 61 aubio_pitchfcomb_t *new_aubio_pitchfcomb (uint_t buf_size, uint_t hop_size); 64 62 65 63 /** deletion of the pitch detection object -
src/pitch/pitchmcomb.c
r0536612 rf658288 104 104 aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output) 105 105 { 106 uint_t i,j;106 uint_t 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 (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 } 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 } */ 136 134 } 137 135 … … 139 137 aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands) 140 138 { 141 uint_t i = 0,j;139 uint_t j; 142 140 uint_t k; 143 141 fvec_t *newmag = (fvec_t *) p->newmag; … … 147 145 /* copy incoming grain to newmag */ 148 146 for (j = 0; j < newmag->length; j++) 149 newmag->data[ i][j] = fftgrain->norm[i][j];147 newmag->data[j] = fftgrain->norm[j]; 150 148 /* detect only if local energy > 10. */ 151 149 if (fvec_local_energy (newmag) > 10.) { … … 172 170 fvec_t *mag = (fvec_t *) p->scratch; 173 171 fvec_t *tmp = (fvec_t *) p->scratch2; 174 uint_t i = 0,j;172 uint_t j; 175 173 uint_t length = mag->length; 176 174 /* copy newmag to mag (scracth) */ 177 175 for (j = 0; j < length; j++) { 178 mag->data[ i][j] = newmag->data[i][j];176 mag->data[j] = newmag->data[j]; 179 177 } 180 178 fvec_min_removal (mag); /* min removal */ … … 182 180 /* skipped *//* low pass filtering */ 183 181 /** \bug fvec_moving_thres may write out of bounds */ 184 fvec_adapt_thres (mag, tmp, p->win_post, p->win_pre , i); /* adaptative threshold */182 fvec_adapt_thres (mag, tmp, p->win_post, p->win_pre); /* adaptative threshold */ 185 183 fvec_add (mag, -p->threshold); /* fixed threshold */ 186 184 { … … 190 188 count = aubio_pitchmcomb_quadpick (peaks, mag); 191 189 for (j = 0; j < count; j++) 192 peaks[j].mag = newmag->data[ i][peaks[j].bin];190 peaks[j].mag = newmag->data[peaks[j].bin]; 193 191 /* reset non peaks */ 194 192 for (j = count; j < length; j++) … … 261 259 candidate[l]->ecomb[k] = peaks[position].ebin; 262 260 candidate[l]->ene += /* ecomb rounded to nearest int */ 263 POW (newmag->data[ 0][(uint_t) FLOOR (candidate[l]->ecomb[k] + .5)],261 POW (newmag->data[(uint_t) FLOOR (candidate[l]->ecomb[k] + .5)], 264 262 0.25); 265 263 candidate[l]->len += 1. / curlen; … … 290 288 aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, fvec_t * X) 291 289 { 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 } 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 } 302 299 return count; 303 300 } … … 364 361 365 362 aubio_pitchmcomb_t * 366 new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize , uint_t channels)363 new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize) 367 364 { 368 365 aubio_pitchmcomb_t *p = AUBIO_NEW (aubio_pitchmcomb_t); … … 386 383 //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348); 387 384 /* allocate temp memory */ 388 p->newmag = new_fvec (spec_size , 1);385 p->newmag = new_fvec (spec_size); 389 386 /* array for median */ 390 p->scratch = new_fvec (spec_size , 1);387 p->scratch = new_fvec (spec_size); 391 388 /* array for phase */ 392 p->theta = new_fvec (spec_size , channels);389 p->theta = new_fvec (spec_size); 393 390 /* array for adaptative threshold */ 394 p->scratch2 = new_fvec (p->win_post + p->win_pre + 1 , 1);391 p->scratch2 = new_fvec (p->win_post + p->win_pre + 1); 395 392 /* array of spectral peaks */ 396 393 p->peaks = AUBIO_ARRAY (aubio_spectralpeak_t, spec_size); -
src/pitch/pitchmcomb.h
r0536612 rf658288 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 analyse60 59 \param samplerate sampling rate of the signal 61 60 62 61 */ 63 aubio_pitchmcomb_t *new_aubio_pitchmcomb (uint_t buf_size, uint_t hop_size, 64 uint_t channels); 62 aubio_pitchmcomb_t *new_aubio_pitchmcomb (uint_t buf_size, uint_t hop_size); 65 63 66 64 /** deletion of the pitch detection object -
src/pitch/pitchschmitt.c
r0536612 rf658288 51 51 fvec_t * output) 52 52 { 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); 53 uint_t j; 54 for (j = 0; j < input->length; j++) { 55 p->buf[j] = input->data[j] * 32768.; 59 56 } 57 output->data[0] = aubio_schmittS16LE (p, input->length, p->buf); 60 58 } 61 59 -
src/pitch/pitchyin.c
r0536612 rf658288 65 65 { 66 66 aubio_pitchyin_t *o = AUBIO_NEW (aubio_pitchyin_t); 67 o->yin = new_fvec (bufsize / 2 , 1);67 o->yin = new_fvec (bufsize / 2); 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 c,j, tau;83 uint_t j, tau; 84 84 smpl_t 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 } 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); 94 92 } 95 93 } … … 100 98 aubio_pitchyin_getcum (fvec_t * yin) 101 99 { 102 uint_t c,tau;100 uint_t tau; 103 101 smpl_t tmp; 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"); 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]); 114 109 } 110 //AUBIO_DBG("\n"); 115 111 } 116 112 … … 118 114 aubio_pitchyin_getpitch (fvec_t * yin) 119 115 { 120 uint_t c = 0,tau = 1;116 uint_t tau = 1; 121 117 do { 122 if (yin->data[ c][tau] < 0.1) {123 while (yin->data[ c][tau + 1] < yin->data[c][tau]) {118 if (yin->data[tau] < 0.1) { 119 while (yin->data[tau + 1] < yin->data[tau]) { 124 120 tau++; 125 121 } … … 139 135 smpl_t tol = o->tol; 140 136 fvec_t *yin = o->yin; 141 uint_t c,j, tau = 0;137 uint_t j, tau = 0; 142 138 sint_t period; 143 139 smpl_t tmp = 0., tmp2 = 0.; 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 } 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); 160 146 } 161 out->data[c][0] = fvec_quadint (yin, fvec_min_elem (yin), c); 162 beach: 163 continue; 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 } 164 155 } 165 //return 0; 156 out->data[0] = fvec_quadint (yin, fvec_min_elem (yin)); 157 beach: 158 return; 166 159 } 167 160 -
src/pitch/pitchyinfft.c
r0536612 rf658288 56 56 { 57 57 aubio_pitchyinfft_t *p = AUBIO_NEW (aubio_pitchyinfft_t); 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);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); 64 64 p->tol = 0.85; 65 65 p->win = new_aubio_window ("hanningz", bufsize); 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])); 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; 93 73 } 74 a0 = weight[j - 1]; 75 f0 = freqs[j - 1]; 76 a1 = weight[j]; 77 f1 = freqs[j]; 78 if (f0 == f1) { // just in case 79 p->weight->data[i] = a0; 80 } else if (f0 == 0) { // y = ax+b 81 p->weight->data[i] = (a1 - a0) / f1 * freq + a0; 82 } else { 83 p->weight->data[i] = (a1 - a0) / (f1 - f0) * freq + 84 (a0 - (a1 - a0) / (f1 / f0 - 1.)); 85 } 86 while (freq > freqs[j]) { 87 j += 1; 88 } 89 //AUBIO_DBG("%f\n",p->weight->data[i]); 90 p->weight->data[i] = DB2LIN (p->weight->data[i]); 91 //p->weight->data[i] = SQRT(DB2LIN(p->weight->data[i])); 94 92 } 95 93 return p; … … 99 97 aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output) 100 98 { 101 uint_t i,tau, l;99 uint_t tau, l; 102 100 uint_t halfperiod; 103 101 smpl_t tmp, sum; 104 102 cvec_t *res = (cvec_t *) p->res; 105 103 fvec_t *yin = (fvec_t *) p->yinfft; 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]; 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); 141 } 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); 112 148 } 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 } 152 } else { 153 output->data[i][0] = 0.; 154 } 149 } else { 150 output->data[0] = 0.; 155 151 } 156 152 } -
src/spectral/fft.c
r0536612 rf658288 75 75 struct _aubio_fft_t { 76 76 uint_t winsize; 77 uint_t channels;78 77 uint_t fft_size; 79 78 real_t *in, *out; … … 83 82 }; 84 83 85 aubio_fft_t * new_aubio_fft(uint_t winsize , uint_t channels) {84 aubio_fft_t * new_aubio_fft(uint_t winsize) { 86 85 aubio_fft_t * s = AUBIO_NEW(aubio_fft_t); 87 86 uint_t i; 88 87 s->winsize = winsize; 89 s->channels = channels;90 88 /* allocate memory */ 91 89 s->in = AUBIO_ARRAY(real_t,winsize); 92 90 s->out = AUBIO_ARRAY(real_t,winsize); 93 s->compspec = new_fvec(winsize ,channels);91 s->compspec = new_fvec(winsize); 94 92 /* create plans */ 95 93 #ifdef HAVE_COMPLEX_H … … 136 134 137 135 void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) { 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 } 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 157 153 } 158 154 159 155 void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) { 160 uint_t i,j;156 uint_t j; 161 157 const smpl_t renorm = 1./(smpl_t)s->winsize; 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 } 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; 179 173 } 180 174 } … … 191 185 192 186 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) { 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 } 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.; 209 201 } 210 202 } 211 203 212 204 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) { 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 } 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]); 223 213 } 224 214 225 215 void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) { 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 } 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]); 232 220 } 233 221 } 234 222 235 223 void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec) { 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 } 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 } -
src/spectral/fft.h
r0536612 rf658288 45 45 46 46 \param size length of the FFT 47 \param channels number of channels48 47 49 48 */ 50 aubio_fft_t * new_aubio_fft (uint_t size, uint_t channels);49 aubio_fft_t * new_aubio_fft (uint_t size); 51 50 /** delete FFT object 52 51 -
src/spectral/filterbank.c
r0536612 rf658288 22 22 #include "aubio_priv.h" 23 23 #include "fvec.h" 24 #include "fmat.h" 24 25 #include "cvec.h" 25 26 #include "spectral/filterbank.h" … … 31 32 uint_t win_s; 32 33 uint_t n_filters; 33 f vec_t *filters;34 fmat_t *filters; 34 35 }; 35 36 … … 42 43 fb->n_filters = n_filters; 43 44 44 /* allocate filter tables, a n fvec of length win_s and of filter_cnt channel*/45 fb->filters = new_f vec(win_s / 2 + 1, n_filters);45 /* allocate filter tables, a matrix of length win_s and of height n_filters */ 46 fb->filters = new_fmat (win_s / 2 + 1, n_filters); 46 47 47 48 return fb; … … 51 52 del_aubio_filterbank (aubio_filterbank_t * fb) 52 53 { 53 del_f vec(fb->filters);54 del_fmat (fb->filters); 54 55 AUBIO_FREE (fb); 55 56 } … … 58 59 aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out) 59 60 { 60 uint_t i,j, fn;61 uint_t j, fn; 61 62 62 63 /* 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 /* apply filters on all channels*/71 for ( i = 0; i < max_channels; i++) {70 /* for each filter */ 71 for (fn = 0; fn < max_filters; fn++) { 72 72 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 } 73 /* for each sample */ 74 for (j = 0; j < max_length; j++) { 75 out->data[fn] += in->norm[j] * f->filters->data[fn][j]; 80 76 } 81 77 } … … 84 80 } 85 81 86 f vec_t *82 fmat_t * 87 83 aubio_filterbank_get_coeffs (aubio_filterbank_t * f) 88 84 { … … 91 87 92 88 uint_t 93 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, f vec_t * filters)89 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filter_coeffs) 94 90 { 95 f vec_copy(filters, f->filters);91 fmat_copy(filter_coeffs, f->filters); 96 92 return 0; 97 93 } -
src/spectral/filterbank.h
r0536612 rf658288 63 63 void aubio_filterbank_do (aubio_filterbank_t * fb, cvec_t * in, fvec_t * out); 64 64 65 /** return a pointer to the fvecobject containing all filter coefficients65 /** return a pointer to the matrix object containing all filter coefficients 66 66 67 67 \param f filterbank object to get coefficients from 68 68 69 69 */ 70 f vec_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f);70 fmat_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 vec_t * filters);78 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filters); 79 79 80 80 #ifdef __cplusplus -
src/spectral/filterbank_mel.c
r0536612 rf658288 21 21 22 22 #include "aubio_priv.h" 23 #include "fmat.h" 23 24 #include "fvec.h" 24 25 #include "cvec.h" … … 31 32 { 32 33 33 f vec_t *filters = aubio_filterbank_get_coeffs (fb);34 uint_t n_filters = filters-> channels, win_s = filters->length;34 fmat_t *filters = aubio_filterbank_get_coeffs (fb); 35 uint_t n_filters = filters->height, win_s = filters->length; 35 36 36 37 uint_t fn; /* filter counter */ … … 49 50 } 50 51 51 if (freqs->data[ 0][freqs->length - 1] > samplerate / 2) {52 if (freqs->data[freqs->length - 1] > samplerate / 2) { 52 53 AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \ 53 %fHz\n", samplerate / 2, freqs->data[ 0][freqs->length - 1]);54 %fHz\n", samplerate / 2, freqs->data[freqs->length - 1]); 54 55 } 55 56 56 57 /* convenience reference to lower/center/upper frequency for each triangle */ 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);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); 60 61 61 62 /* height of each triangle */ 62 fvec_t *triangle_heights = new_fvec (n_filters , 1);63 fvec_t *triangle_heights = new_fvec (n_filters); 63 64 64 65 /* lookup table of each bin frequency in hz */ 65 fvec_t *fft_freqs = new_fvec (win_s , 1);66 fvec_t *fft_freqs = new_fvec (win_s); 66 67 67 68 /* fill up the lower/center/upper */ 68 69 for (fn = 0; fn < n_filters; fn++) { 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];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]; 72 73 } 73 74 74 75 /* compute triangle heights so that each triangle has unit area */ 75 76 for (fn = 0; fn < n_filters; fn++) { 76 triangle_heights->data[ 0][fn] =77 2. / (upper_freqs->data[ 0][fn] - lower_freqs->data[0][fn]);77 triangle_heights->data[fn] = 78 2. / (upper_freqs->data[fn] - lower_freqs->data[fn]); 78 79 } 79 80 80 81 /* fill fft_freqs lookup table, which assigns the frequency in hz to each bin */ 81 82 for (bin = 0; bin < win_s; bin++) { 82 fft_freqs->data[ 0][bin] =83 fft_freqs->data[bin] = 83 84 aubio_bintofreq (bin, samplerate, (win_s - 1) * 2); 84 85 } 85 86 86 87 /* zeroing of all filters */ 87 f vec_zeros (filters);88 89 if (fft_freqs->data[ 0][1] >= lower_freqs->data[0][0]) {88 fmat_zeros (filters); 89 90 if (fft_freqs->data[1] >= lower_freqs->data[0]) { 90 91 /* - 1 to make sure we don't miss the smallest power of two */ 91 92 uint_t min_win_s = 92 (uint_t) FLOOR (samplerate / lower_freqs->data[0] [0]) - 1;93 (uint_t) FLOOR (samplerate / lower_freqs->data[0]) - 1; 93 94 AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \ 94 95 band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n", 95 fft_freqs->data[ 0][1], lower_freqs->data[0][0],96 upper_freqs->data[0] [0], (win_s - 1) * 2,96 fft_freqs->data[1], lower_freqs->data[0], 97 upper_freqs->data[0], (win_s - 1) * 2, 97 98 aubio_next_power_of_two (min_win_s)); 98 99 } … … 103 104 /* skip first elements */ 104 105 for (bin = 0; bin < win_s - 1; bin++) { 105 if (fft_freqs->data[ 0][bin] <= lower_freqs->data[0][fn] &&106 fft_freqs->data[ 0][bin + 1] > lower_freqs->data[0][fn]) {106 if (fft_freqs->data[bin] <= lower_freqs->data[fn] && 107 fft_freqs->data[bin + 1] > lower_freqs->data[fn]) { 107 108 bin++; 108 109 break; … … 112 113 /* compute positive slope step size */ 113 114 smpl_t riseInc = 114 triangle_heights->data[ 0][fn] /115 (center_freqs->data[ 0][fn] - lower_freqs->data[0][fn]);115 triangle_heights->data[fn] / 116 (center_freqs->data[fn] - lower_freqs->data[fn]); 116 117 117 118 /* compute coefficients in positive slope */ 118 119 for (; bin < win_s - 1; bin++) { 119 120 filters->data[fn][bin] = 120 (fft_freqs->data[ 0][bin] - lower_freqs->data[0][fn]) * riseInc;121 122 if (fft_freqs->data[ 0][bin + 1] >= center_freqs->data[0][fn]) {121 (fft_freqs->data[bin] - lower_freqs->data[fn]) * riseInc; 122 123 if (fft_freqs->data[bin + 1] >= center_freqs->data[fn]) { 123 124 bin++; 124 125 break; … … 128 129 /* compute negative slope step size */ 129 130 smpl_t downInc = 130 triangle_heights->data[ 0][fn] /131 (upper_freqs->data[ 0][fn] - center_freqs->data[0][fn]);131 triangle_heights->data[fn] / 132 (upper_freqs->data[fn] - center_freqs->data[fn]); 132 133 133 134 /* compute coefficents in negative slope */ 134 135 for (; bin < win_s - 1; bin++) { 135 136 filters->data[fn][bin] += 136 (upper_freqs->data[ 0][fn] - fft_freqs->data[0][bin]) * downInc;137 (upper_freqs->data[fn] - fft_freqs->data[bin]) * downInc; 137 138 138 139 if (filters->data[fn][bin] < 0.) { … … 140 141 } 141 142 142 if (fft_freqs->data[ 0][bin + 1] >= upper_freqs->data[0][fn])143 if (fft_freqs->data[bin + 1] >= upper_freqs->data[fn]) 143 144 break; 144 145 } … … 176 177 177 178 /* buffers to compute filter frequencies */ 178 fvec_t *freqs = new_fvec (n_filters + 2 , 1);179 fvec_t *freqs = new_fvec (n_filters + 2); 179 180 180 181 /* first step: fill all the linear filter frequencies */ 181 182 for (fn = 0; fn < linearFilters; fn++) { 182 freqs->data[ 0][fn] = lowestFrequency + fn * linearSpacing;183 } 184 smpl_t lastlinearCF = freqs->data[ 0][fn - 1];183 freqs->data[fn] = lowestFrequency + fn * linearSpacing; 184 } 185 smpl_t lastlinearCF = freqs->data[fn - 1]; 185 186 186 187 /* second step: fill all the log filter frequencies */ 187 188 for (fn = 0; fn < logFilters + 2; fn++) { 188 freqs->data[ 0][fn + linearFilters] =189 freqs->data[fn + linearFilters] = 189 190 lastlinearCF * (POW (logSpacing, fn + 1)); 190 191 } -
src/spectral/mfcc.c
r0536612 rf658288 22 22 #include "aubio_priv.h" 23 23 #include "fvec.h" 24 #include "fmat.h" 24 25 #include "cvec.h" 25 26 #include "mathutils.h" … … 40 41 aubio_filterbank_t *fb; /** filter bank */ 41 42 fvec_t *in_dct; /** input buffer for dct * [fb->n_filters] */ 42 f vec_t *dct_coeffs; /** DCT transform n_filters * n_coeffs */43 fmat_t *dct_coeffs; /** DCT transform n_filters * n_coeffs */ 43 44 }; 44 45 … … 64 65 65 66 /* allocating buffers */ 66 mfcc->in_dct = new_fvec (n_filters , 1);67 mfcc->in_dct = new_fvec (n_filters); 67 68 68 mfcc->dct_coeffs = new_f vec(n_coefs, n_filters);69 mfcc->dct_coeffs = new_fmat (n_coefs, n_filters); 69 70 70 71 /* compute DCT transform dct_coeffs[i][j] as … … 100 101 aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out) 101 102 { 102 uint_t i,j, k;103 uint_t j, k; 103 104 104 105 /* compute filterbank */ … … 115 116 116 117 /* compute discrete cosine transform */ 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 } 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]; 123 122 } 124 123 } -
src/spectral/phasevoc.c
r0536612 rf658288 30 30 uint_t win_s; /** grain length */ 31 31 uint_t hop_s; /** overlap step */ 32 uint_t channels; /** number of channels */33 32 aubio_fft_t * fft; /** fft object */ 34 33 fvec_t * synth; /** cur output grain [win_s] */ … … 49 48 50 49 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) { 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 } 50 /* slide */ 51 aubio_pvoc_swapbuffers(pv->data->data,pv->dataold->data, 52 datanew->data,pv->win_s,pv->hop_s); 57 53 /* windowing */ 58 54 fvec_weight(pv->data, pv->w); … … 64 60 65 61 void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) { 66 uint_t i;67 62 /* calculate rfft */ 68 63 aubio_fft_rdo(pv->fft,fftgrain,pv->synth); 69 64 /* unshift */ 70 65 fvec_shift(pv->synth); 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 } 66 aubio_pvoc_addsynth(pv->synth->data,pv->synthold->data, 67 synthnew->data,pv->win_s,pv->hop_s); 75 68 } 76 69 77 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s , uint_t channels) {70 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s) { 78 71 aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t); 79 72 … … 88 81 } 89 82 90 pv->fft = new_aubio_fft (win_s,channels);83 pv->fft = new_aubio_fft (win_s); 91 84 92 85 /* remember old */ 93 pv->data = new_fvec (win_s , channels);94 pv->synth = new_fvec (win_s , channels);86 pv->data = new_fvec (win_s); 87 pv->synth = new_fvec (win_s); 95 88 96 89 /* new input output */ 97 pv->dataold = new_fvec (win_s-hop_s , channels);98 pv->synthold = new_fvec (win_s-hop_s , channels);90 pv->dataold = new_fvec (win_s-hop_s); 91 pv->synthold = new_fvec (win_s-hop_s); 99 92 pv->w = new_aubio_window ("hanningz", win_s); 100 93 101 pv->channels = channels;102 94 pv->hop_s = hop_s; 103 95 pv->win_s = win_s; -
src/spectral/phasevoc.h
r0536612 rf658288 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. Multiple channels are fully supported.28 at creation time. 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 channels47 46 48 47 */ 49 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s , uint_t channels);48 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s); 50 49 /** delete phase vocoder object 51 50 … … 57 56 /** compute spectral frame 58 57 59 This function accepts an input vector of size [ channels]x[hop_s]. The58 This function accepts an input vector of size [hop_s]. The 60 59 analysis buffer is rotated and filled with the new data. After windowing of 61 60 this signal window, the Fourier transform is computed and returned in … … 71 70 72 71 This function takes an input spectral frame fftgrain of size 73 [ channels]x[buf_s] and computes its inverse Fourier transform. Overlap-add72 [buf_s] and computes its inverse Fourier transform. Overlap-add 74 73 synthesis is then computed using the previously synthetised frames, and the 75 74 output stored in out. … … 94 93 */ 95 94 uint_t aubio_pvoc_get_hop(aubio_pvoc_t* pv); 96 /** get channel number97 98 \param pv phase vocoder to get the number of channels from99 100 */101 uint_t aubio_pvoc_get_channels(aubio_pvoc_t* pv);102 95 103 96 #ifdef __cplusplus -
src/spectral/specdesc.c
r0536612 rf658288 89 89 void aubio_specdesc_energy (aubio_specdesc_t *o UNUSED, 90 90 cvec_t * fftgrain, fvec_t * onset) { 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 } 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]); 97 95 } 98 96 } … … 101 99 void aubio_specdesc_hfc(aubio_specdesc_t *o UNUSED, 102 100 cvec_t * fftgrain, fvec_t * onset){ 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 } 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]; 109 105 } 110 106 } … … 113 109 /* Complex Domain Method onset detection function */ 114 110 void aubio_specdesc_complex (aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset) { 115 uint_t i,j;111 uint_t j; 116 112 uint_t nbins = fftgrain->length; 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 } 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]; 134 128 } 135 129 } … … 139 133 void aubio_specdesc_phase(aubio_specdesc_t *o, 140 134 cvec_t * fftgrain, fvec_t * onset){ 141 uint_t i,j;135 uint_t j; 142 136 uint_t nbins = fftgrain->length; 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 } 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); 168 160 } 169 161 … … 171 163 void aubio_specdesc_specdiff(aubio_specdesc_t *o, 172 164 cvec_t * fftgrain, fvec_t * onset){ 173 uint_t i,j;165 uint_t j; 174 166 uint_t nbins = fftgrain->length; 175 for (i=0;i<fftgrain->channels; i++) { 176 onset->data[i][0] = 0.0; 167 onset->data[0] = 0.0; 177 168 for (j=0;j<nbins; 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]);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]); 183 174 else 184 o->dev1->data[ i][j] = 0.0;185 o->oldmag->data[ i][j] = fftgrain->norm[i][j];175 o->dev1->data[j] = 0.0; 176 o->oldmag->data[j] = fftgrain->norm[j]; 186 177 } 187 178 … … 192 183 aubio_hist_weight(o->histog); 193 184 /* its mean is the result */ 194 onset->data[i][0] = aubio_hist_mean(o->histog); 195 196 } 185 onset->data[0] = aubio_hist_mean(o->histog); 197 186 } 198 187 … … 201 190 * negative (1.+) and infinite values (+1.e-10) */ 202 191 void aubio_specdesc_kl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){ 203 uint_t i,j; 204 for (i=0;i<fftgrain->channels;i++) { 205 onset->data[i][0] = 0.; 192 uint_t j; 193 onset->data[0] = 0.; 206 194 for (j=0;j<fftgrain->length;j++) { 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];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]; 210 198 } 211 if (isnan(onset->data[i][0])) onset->data[i][0] = 0.; 212 } 199 if (isnan(onset->data[0])) onset->data[0] = 0.; 213 200 } 214 201 … … 217 204 * negative (1.+) and infinite values (+1.e-10) */ 218 205 void aubio_specdesc_mkl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){ 219 uint_t i,j; 220 for (i=0;i<fftgrain->channels;i++) { 221 onset->data[i][0] = 0.; 206 uint_t j; 207 onset->data[0] = 0.; 222 208 for (j=0;j<fftgrain->length;j++) { 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];209 onset->data[0] += LOG(1.+fftgrain->norm[j]/(o->oldmag->data[j]+1.e-10)); 210 o->oldmag->data[j] = fftgrain->norm[j]; 225 211 } 226 if (isnan(onset->data[i][0])) onset->data[i][0] = 0.; 227 } 212 if (isnan(onset->data[0])) onset->data[0] = 0.; 228 213 } 229 214 230 215 /* Spectral flux */ 231 216 void aubio_specdesc_specflux(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){ 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 } 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]; 240 223 } 241 224 } … … 252 235 */ 253 236 aubio_specdesc_t * 254 new_aubio_specdesc (char_t * onset_mode, 255 uint_t size, uint_t channels){ 237 new_aubio_specdesc (char_t * onset_mode, uint_t size){ 256 238 aubio_specdesc_t * o = AUBIO_NEW(aubio_specdesc_t); 257 239 uint_t rsize = size/2+1; … … 303 285 /* the other approaches will need some more memory spaces */ 304 286 case aubio_onset_complex: 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);287 o->oldmag = new_fvec(rsize); 288 o->dev1 = new_fvec(rsize); 289 o->theta1 = new_fvec(rsize); 290 o->theta2 = new_fvec(rsize); 309 291 break; 310 292 case aubio_onset_phase: 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);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); 315 297 o->threshold = 0.1; 316 298 break; 317 299 case aubio_onset_specdiff: 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);300 o->oldmag = new_fvec(rsize); 301 o->dev1 = new_fvec(rsize); 302 o->histog = new_aubio_hist(0.0, PI, 10); 321 303 o->threshold = 0.1; 322 304 break; … … 324 306 case aubio_onset_mkl: 325 307 case aubio_onset_specflux: 326 o->oldmag = new_fvec(rsize ,channels);308 o->oldmag = new_fvec(rsize); 327 309 break; 328 310 default: -
src/spectral/specdesc.h
r0536612 rf658288 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 and per channel (stored in a vector of size [channels]x[1]).27 buffer (stored in a vector of size [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 channels171 170 172 171 */ 173 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size, 174 uint_t channels); 172 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size); 175 173 176 174 /** deletion of a spectral descriptor -
src/spectral/statistics.c
r0536612 rf658288 24 24 25 25 smpl_t 26 cvec_sum _channel (cvec_t * s, uint_t i)26 cvec_sum (cvec_t * s) 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[i][j]; 30 for (j = 0; j < s->length; j++) { 31 tmp += s->norm[j]; 32 } 32 33 return tmp; 33 34 } 34 35 35 36 smpl_t 36 cvec_mean _channel (cvec_t * s, uint_t i)37 cvec_mean (cvec_t * s) 37 38 { 38 return cvec_sum _channel(s, i) / (smpl_t) (s->length);39 return cvec_sum (s) / (smpl_t) (s->length); 39 40 } 40 41 41 42 smpl_t 42 cvec_centroid _channel (cvec_t * spec, uint_t i)43 cvec_centroid (cvec_t * spec) 43 44 { 44 45 smpl_t sum = 0., sc = 0.; 45 46 uint_t j; 46 sum = cvec_sum _channel (spec, i);47 sum = cvec_sum (spec); 47 48 if (sum == 0.) { 48 49 return 0.; 49 50 } else { 50 51 for (j = 0; j < spec->length; j++) { 51 sc += (smpl_t) j *spec->norm[ i][j];52 sc += (smpl_t) j *spec->norm[j]; 52 53 } 53 54 return sc / sum; … … 56 57 57 58 smpl_t 58 cvec_moment _channel (cvec_t * spec, uint_t i, uint_t order)59 cvec_moment (cvec_t * spec, uint_t order) 59 60 { 60 61 smpl_t sum = 0., centroid = 0., sc = 0.; 61 62 uint_t j; 62 sum = cvec_sum _channel (spec, i);63 sum = cvec_sum (spec); 63 64 if (sum == 0.) { 64 65 return 0.; 65 66 } else { 66 centroid = cvec_centroid _channel (spec, i);67 centroid = cvec_centroid (spec); 67 68 for (j = 0; j < spec->length; j++) { 68 sc += (smpl_t) POW(j - centroid, order) * spec->norm[ i][j];69 sc += (smpl_t) POW(j - centroid, order) * spec->norm[j]; 69 70 } 70 71 return sc / sum; … … 76 77 fvec_t * desc) 77 78 { 78 uint_t i; 79 for (i = 0; i < spec->channels; i++) { 80 desc->data[i][0] = cvec_centroid_channel (spec, i); 81 } 79 desc->data[0] = cvec_centroid (spec); 82 80 } 83 81 … … 86 84 fvec_t * desc) 87 85 { 88 uint_t i; 89 for (i = 0; i < spec->channels; i++) { 90 desc->data[i][0] = cvec_moment_channel (spec, i, 2); 91 } 86 desc->data[0] = cvec_moment (spec, 2); 92 87 } 93 88 … … 96 91 fvec_t * desc) 97 92 { 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 } 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); 107 100 } 108 101 } … … 112 105 fvec_t * desc) 113 106 { 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 } 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); 123 114 } 124 115 } … … 128 119 fvec_t * desc) 129 120 { 130 uint_t i,j;121 uint_t j; 131 122 smpl_t norm = 0, sum = 0.; 132 123 // compute N * sum(j**2) - sum(j)**2 … … 137 128 // sum_0^N(j) = length * (length + 1) / 2 138 129 norm -= SQR( (spec->length) * (spec->length - 1.) / 2. ); 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; 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]; 152 137 } 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; 153 142 } 154 143 } … … 158 147 fvec_t * desc) 159 148 { 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; 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; 172 158 } 159 desc->data[0] /= sum; 173 160 } 174 161 } … … 178 165 fvec_t *desc) 179 166 { 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]); 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++; 185 180 } 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 } 181 desc->data[0] = j; 197 182 } 198 183 } -
src/spectral/tss.c
r0536612 rf658288 44 44 cvec_t * trans, cvec_t * stead) 45 45 { 46 uint_t i,j;46 uint_t j; 47 47 uint_t test; 48 48 uint_t nbins = input->length; 49 uint_t channels = input->channels;50 49 smpl_t alpha = o->alpha; 51 50 smpl_t beta = o->beta; 52 51 smpl_t parm = o->parm; 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;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; 58 57 /* second phase derivative */ 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 } 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 } 66 64 67 68 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 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 } 73 71 74 75 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;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; 79 77 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 } 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; 94 91 } 95 92 } … … 101 98 } 102 99 103 aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size , uint_t channels)100 aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size) 104 101 { 105 102 aubio_tss_t * o = AUBIO_NEW(aubio_tss_t); … … 110 107 o->beta = 4.; 111 108 o->parm = o->threshold*o->thrsfact; 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);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); 117 114 return o; 118 115 } -
src/spectral/tss.h
r0536612 rf658288 49 49 \param buf_size buffer size 50 50 \param hop_size step size 51 \param channels number of input channels52 51 53 52 */ 54 aubio_tss_t *new_aubio_tss (uint_t buf_size, uint_t hop_size , uint_t channels);53 aubio_tss_t *new_aubio_tss (uint_t buf_size, uint_t hop_size); 55 54 56 55 /** delete tss object -
src/tempo/beattracking.c
r0536612 rf658288 55 55 56 56 aubio_beattracking_t * 57 new_aubio_beattracking (uint_t winlen , uint_t channels)57 new_aubio_beattracking (uint_t winlen) 58 58 { 59 59 … … 79 79 p->rayparam = rayparam; 80 80 p->step = step; 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);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); 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[ 0][i] = (EXP ((LOG (2.0) / rayparam) * (i + 1)))94 p->dfwv->data[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[ 0][i] = ((smpl_t) (i + 1.) / SQR ((smpl_t) rayparam)) *99 p->rwv->data[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[ 0][i] += bt->acf->data[0][a * (i + 1) + b - 1]163 bt->acfout->data[i] += bt->acf->data[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 , 0) : 1;173 bt->rp = maxindex ? fvec_quadint (bt->acfout, maxindex) : 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[ 0][i] += bt->dfrev->data[0][i + (uint_t) ROUND (bp * k)];193 bt->phout->data[i] += bt->dfrev->data[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 , 0);206 phase = fvec_quadint (bt->phout, maxindex); 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[ 0][i] = beat;239 output->data[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[ 0][i] = beat;246 output->data[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] [0]= i;252 output->data[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[ 0][3 * gp + k];263 four_energy += acf->data[ 0][4 * gp + k];262 three_energy += acf->data[3 * gp + k]; 263 four_energy += acf->data[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[ 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];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]; 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[ 0][i] += acf->data[0][a * (i + 1) + b - 1];303 acfout->data[i] += acf->data[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) , 0);308 gp = fvec_quadint (acfout, fvec_max_elem (acfout)); 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[ 0][j] =353 bt->gwv->data[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[ 0][j] =365 bt->phwv->data[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 , 0);412 return 5168. / fvec_quadint (bt->acfout, bt->bp); 413 413 } else { 414 414 return 0.; -
src/tempo/beattracking.h
r0536612 rf658288 48 48 49 49 \param hop_size number of onset detection samples [512] 50 \param channels number (not functionnal) [1]51 50 52 51 */ 53 aubio_beattracking_t * new_aubio_beattracking(uint_t hop_size , uint_t channels);52 aubio_beattracking_t * new_aubio_beattracking(uint_t hop_size); 54 53 55 54 /** track the beat -
src/tempo/tempo.c
r0536612 rf658288 59 59 /*if (usedoubled) { 60 60 aubio_specdesc_do(o2,fftgrain, onset2); 61 onset->data[0] [0] *= onset2->data[0][0];61 onset->data[0] *= onset2->data[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[ 0][i] = o->dfframe->data[0][i+step];69 o->dfframe->data[i] = o->dfframe->data[i+step]; 70 70 for (i = winlen - step ; i < winlen; i++ ) 71 o->dfframe->data[ 0][i] = 0.;71 o->dfframe->data[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[ 0][1] = o->onset->data[0][0];76 tempo->data[1] = o->onset->data[0]; 77 77 thresholded = aubio_peakpicker_get_thresholded_input(o->pp); 78 o->dfframe->data[ 0][winlen - step + o->blockpos] = thresholded->data[0][0];78 o->dfframe->data[winlen - step + o->blockpos] = thresholded->data[0]; 79 79 /* end of second level loop */ 80 tempo->data[0] [0]= 0; /* reset tactus */80 tempo->data[0] = 0; /* reset tactus */ 81 81 i=0; 82 for (i = 1; i < o->out->data[0] [0]; i++ ) {82 for (i = 1; i < o->out->data[0]; i++ ) { 83 83 /* if current frame is a predicted 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 */84 if (o->blockpos == FLOOR(o->out->data[i])) { 85 tempo->data[0] = o->out->data[i] - FLOOR(o->out->data[i]); /* set tactus */ 86 86 /* test for silence */ 87 87 if (aubio_silence_detection(input, o->silence)==1) { 88 tempo->data[ 0][1] = 0; /* unset onset */88 tempo->data[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 channels, uint_tsamplerate)107 uint_t buf_size, uint_t hop_size, 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 ,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);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(); 122 122 aubio_peakpicker_set_threshold (o->pp, o->threshold); 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);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); 127 127 /*if (usedoubled) { 128 o2 = new_aubio_specdesc(type_onset2,buffer_size ,channels);129 onset2 = new_fvec(1 , channels);128 o2 = new_aubio_specdesc(type_onset2,buffer_size); 129 onset2 = new_fvec(1); 130 130 }*/ 131 131 return o; -
src/tempo/tempo.h
r0536612 rf658288 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 channels, uint_tsamplerate);42 uint_t buf_size, uint_t hop_size, uint_t samplerate); 43 43 44 44 /** execute tempo detection */ -
src/temporal/a_weighting.c
r0536612 rf658288 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 [0], *a = as->data[0];34 lsmp_t *b = bs->data, *a = as->data; 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 channels, uint_tsamplerate)243 new_aubio_filter_a_weighting (uint_t samplerate) 244 244 { 245 aubio_filter_t *f = new_aubio_filter (7 , channels);245 aubio_filter_t *f = new_aubio_filter (7); 246 246 aubio_filter_set_a_weighting (f, samplerate); 247 247 return f; -
src/temporal/a_weighting.h
r0536612 rf658288 61 61 /** create new A-design filter 62 62 63 \param channels number of channels to allocate64 63 \param samplerate sampling frequency of the signal to filter. Should be one of 65 64 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, and … … 69 68 70 69 */ 71 aubio_filter_t *new_aubio_filter_a_weighting (uint_t channels, 72 uint_t samplerate); 70 aubio_filter_t *new_aubio_filter_a_weighting (uint_t samplerate); 73 71 74 72 /** set feedback and feedforward coefficients of a A-weighting filter -
src/temporal/biquad.c
r0536612 rf658288 36 36 return AUBIO_FAIL; 37 37 } 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;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; 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, 49 uint_t channels) 48 new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2, lsmp_t a1, lsmp_t a2) 50 49 { 51 aubio_filter_t *f = new_aubio_filter (3 , channels);50 aubio_filter_t *f = new_aubio_filter (3); 52 51 aubio_filter_set_biquad (f, b0, b1, b2, a1, a2); 53 52 return f; -
src/temporal/biquad.h
r0536612 rf658288 62 62 \param a1 feedback filter coefficient 63 63 \param a2 feedback filter coefficient 64 \param channels number of channels to allocate65 64 66 65 */ 67 66 aubio_filter_t *new_aubio_filter_biquad (lsmp_t b0, lsmp_t b1, lsmp_t b2, 68 lsmp_t a1, lsmp_t a2 , uint_t channels);67 lsmp_t a1, lsmp_t a2); 69 68 70 69 #ifdef __cplusplus -
src/temporal/c_weighting.c
r0536612 rf658288 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 [0], *a = as->data[0];34 lsmp_t *b = bs->data, *a = as->data; 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 channels, uint_tsamplerate) {200 aubio_filter_t * f = new_aubio_filter(5 , channels);199 aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate) { 200 aubio_filter_t * f = new_aubio_filter(5); 201 201 aubio_filter_set_c_weighting (f, samplerate); 202 202 return f; -
src/temporal/c_weighting.h
r0536612 rf658288 61 61 /** create new C-design filter 62 62 63 \param channels number of channels to allocate64 63 \param samplerate sampling frequency of the signal to filter. Should be one of 65 64 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, and … … 69 68 70 69 */ 71 aubio_filter_t *new_aubio_filter_c_weighting (uint_t channels, 72 uint_t samplerate); 70 aubio_filter_t *new_aubio_filter_c_weighting (uint_t samplerate); 73 71 74 72 /** set feedback and feedforward coefficients of a C-weighting filter -
src/temporal/filter.c
r0536612 rf658288 49 49 aubio_filter_do (aubio_filter_t * f, fvec_t * in) 50 50 { 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];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; 56 56 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 } 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]; 75 64 } 76 /* store for next run */ 77 f->x->data[i] = x; 78 f->y->data[i] = y; 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 } 79 72 } 80 73 } … … 84 77 aubio_filter_do_filtfilt (aubio_filter_t * f, fvec_t * in, fvec_t * tmp) 85 78 { 86 uint_t j , i = 0;79 uint_t j; 87 80 uint_t length = in->length; 88 81 /* apply filtering */ … … 91 84 /* mirror */ 92 85 for (j = 0; j < length; j++) 93 tmp->data[ i][length - j - 1] = in->data[i][j];86 tmp->data[length - j - 1] = in->data[j]; 94 87 /* apply filtering on mirrored */ 95 88 aubio_filter_do (f, tmp); … … 97 90 /* invert back */ 98 91 for (j = 0; j < length; j++) 99 in->data[ i][j] = tmp->data[i][length - j - 1];92 in->data[j] = tmp->data[length - j - 1]; 100 93 } 101 94 … … 139 132 140 133 aubio_filter_t * 141 new_aubio_filter (uint_t order , uint_t channels)134 new_aubio_filter (uint_t order) 142 135 { 143 136 aubio_filter_t *f = AUBIO_NEW (aubio_filter_t); 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);137 f->x = new_lvec (order); 138 f->y = new_lvec (order); 139 f->a = new_lvec (order); 140 f->b = new_lvec (order); 148 141 /* by default, samplerate is not set */ 149 142 f->samplerate = 0; 150 143 f->order = order; 151 144 /* set default to identity */ 152 f->a->data[ 0][1] = 1.;145 f->a->data[1] = 1.; 153 146 return f; 154 147 } -
src/temporal/filter.h
r0536612 rf658288 26 26 Digital filter 27 27 28 This object stores a digital filter of order \f$n\f$ for \f$c\f$ channels.28 This object stores a digital filter of order \f$n\f$. 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 an order154 and a specific number of channels.153 This function creates a new ::aubio_filter_t object, given the order of the 154 filter. 155 155 156 156 \param order order of the filter (number of coefficients) 157 \param channels number of channels to allocate158 157 159 158 \return the newly created filter object 160 159 161 160 */ 162 aubio_filter_t *new_aubio_filter (uint_t order , uint_t channels);161 aubio_filter_t *new_aubio_filter (uint_t order); 163 162 164 163 /** delete a filter object -
src/temporal/resampler.c
r0536612 rf658288 61 61 aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output) 62 62 { 63 uint_t i;64 63 s->proc->input_frames = input->length; 65 64 s->proc->output_frames = output->length; 66 65 s->proc->src_ratio = (double) s->ratio; 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 } 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); 74 71 } 75 72 … … 87 84 88 85 void 89 del_aubio_resampler (aubio_resampler_t * s )86 del_aubio_resampler (aubio_resampler_t * s UNUSED) 90 87 { 91 88 } 92 89 93 90 void 94 aubio_resampler_do (aubio_resampler_t * s , fvec_t * input, fvec_t * output)91 aubio_resampler_do (aubio_resampler_t * s UNUSED, fvec_t * input UNUSED, fvec_t * output UNUSED) 95 92 { 96 93 } -
src/utils/hist.c
r0536612 rf658288 32 32 fvec_t * hist; 33 33 uint_t nelems; 34 uint_t channels;35 34 fvec_t * cent; 36 35 aubio_scale_t *scaler; … … 40 39 * Object creation/deletion calls 41 40 */ 42 aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems , uint_t channels){41 aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems){ 43 42 aubio_hist_t * s = AUBIO_NEW(aubio_hist_t); 44 43 smpl_t step = (ihig-ilow)/(smpl_t)(nelems); 45 44 smpl_t accum = step; 46 45 uint_t i; 47 s->channels = channels;48 46 s->nelems = nelems; 49 s->hist = new_fvec(nelems , channels);50 s->cent = new_fvec(nelems , 1);47 s->hist = new_fvec(nelems); 48 s->cent = new_fvec(nelems); 51 49 52 50 /* use scale to map ilow/ihig -> 0/nelems */ 53 51 s->scaler = new_aubio_scale(ilow,ihig,0,nelems); 54 52 /* calculate centers now once */ 55 s->cent->data[0] [0]= ilow + 0.5 * step;53 s->cent->data[0] = ilow + 0.5 * step; 56 54 for (i=1; i < s->nelems; i++, accum+=step ) 57 s->cent->data[ 0][i] = s->cent->data[0][0] + accum;55 s->cent->data[i] = s->cent->data[0] + accum; 58 56 59 57 return s; … … 71 69 */ 72 70 void aubio_hist_do (aubio_hist_t *s, fvec_t *input) { 73 uint_t i,j;71 uint_t j; 74 72 sint_t tmp = 0; 75 73 aubio_scale_do(s->scaler, input); 76 74 /* reset data */ 77 for (i=0; i < s->channels; i++) 78 for (j=0; j < s->nelems; j++) 79 s->hist->data[i][j] = 0; 75 fvec_zeros(s->hist); 80 76 /* run accum */ 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; 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; 87 82 } 83 } 88 84 } 89 85 90 86 void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input) { 91 uint_t i,j;87 uint_t j; 92 88 sint_t tmp = 0; 93 89 aubio_scale_do(s->scaler, input); 94 90 /* reset data */ 95 for (i=0; i < s->channels; i++) 96 for (j=0; j < s->nelems; j++) 97 s->hist->data[i][j] = 0; 91 fvec_zeros(s->hist); 98 92 /* run accum */ 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 } 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; 106 98 } 99 } 107 100 } 108 101 109 102 110 103 void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input) { 111 uint_t i ,j;104 uint_t i; 112 105 sint_t tmp = 0; 113 106 smpl_t ilow = fvec_min(input); … … 119 112 120 113 /* recalculate centers */ 121 s->cent->data[0] [0]= ilow + 0.5f * step;114 s->cent->data[0] = ilow + 0.5f * step; 122 115 for (i=1; i < s->nelems; i++) 123 s->cent->data[ 0][i] = s->cent->data[0][0] + i * step;116 s->cent->data[i] = s->cent->data[0] + i * step; 124 117 125 118 /* scale */ … … 127 120 128 121 /* reset data */ 129 for (i=0; i < s->channels; i++) 130 for (j=0; j < s->nelems; j++) 131 s->hist->data[i][j] = 0; 122 fvec_zeros(s->hist); 132 123 /* run accum */ 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 } 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; 140 129 } 130 } 141 131 } 142 132 143 133 void aubio_hist_weight (aubio_hist_t *s) { 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 } 134 uint_t j; 135 for (j=0; j < s->nelems; j++) { 136 s->hist->data[j] *= s->cent->data[j]; 137 } 149 138 } 150 139 151 140 smpl_t aubio_hist_mean (aubio_hist_t *s) { 152 uint_t i,j;141 uint_t j; 153 142 smpl_t tmp = 0.0; 154 for (i=0; i < s->channels; i++) 155 for (j=0; j < s->nelems; j++) 156 tmp += s->hist->data[i][j]; 143 for (j=0; j < s->nelems; j++) 144 tmp += s->hist->data[j]; 157 145 return tmp/(smpl_t)(s->nelems); 158 146 } -
src/utils/hist.h
r0536612 rf658288 40 40 * \param fhig maximum input 41 41 * \param nelems number of histogram columns 42 * \param channels number of channels43 42 */ 44 aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems , uint_t channels);43 aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems); 45 44 /** histogram deletion */ 46 45 void del_aubio_hist(aubio_hist_t *s); -
src/utils/scale.c
r0536612 rf658288 70 70 void aubio_scale_do (aubio_scale_t *s, fvec_t *input) 71 71 { 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 } 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; 79 77 } 80 78 } -
src/vecutils.c
r0536612 rf658288 9 9 void TYPE ## _ ## OPNAME (TYPE ## _t *o) \ 10 10 { \ 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 } \ 11 uint_t j; \ 12 for (j = 0; j < o->length; j++) { \ 13 o->OBJ[j] = OP (o->OBJ[j]); \ 16 14 } \ 17 15 } … … 35 33 void fvec_pow (fvec_t *s, smpl_t power) 36 34 { 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 } 35 uint_t j; 36 for (j = 0; j < s->length; j++) { 37 s->data[j] = POW(s->data[j], power); 42 38 } 43 39 } … … 45 41 void cvec_pow (cvec_t *s, smpl_t power) 46 42 { 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 } 43 uint_t j; 44 for (j = 0; j < s->length; j++) { 45 s->norm[j] = POW(s->norm[j], power); 52 46 } 53 47 } -
swig/aubio.i
r0536612 rf658288 12 12 13 13 /* fvec */ 14 fvec_t * new_fvec(uint_t length , uint_t channels);14 fvec_t * new_fvec(uint_t length); 15 15 void del_fvec(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); 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); 21 19 22 20 /* cvec */ 23 cvec_t * new_cvec(uint_t length , uint_t channels);21 cvec_t * new_cvec(uint_t length); 24 22 void del_cvec(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); 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); 35 29 36 30 37 31 /* fft */ 38 aubio_fft_t * new_aubio_fft(uint_t size , uint_t channels);32 aubio_fft_t * new_aubio_fft(uint_t size); 39 33 void del_aubio_fft(aubio_fft_t * s); 40 34 void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum); … … 50 44 51 45 /* filter */ 52 aubio_filter_t * new_aubio_filter(uint_t order , uint_t channels);46 aubio_filter_t * new_aubio_filter(uint_t order); 53 47 void aubio_filter_do(aubio_filter_t * b, fvec_t * in); 54 48 void aubio_filter_do_outplace(aubio_filter_t * b, fvec_t * in, fvec_t * out); … … 57 51 58 52 /* a_weighting */ 59 aubio_filter_t * new_aubio_filter_a_weighting (uint_t channels, uint_tsamplerate);53 aubio_filter_t * new_aubio_filter_a_weighting (uint_t samplerate); 60 54 uint_t aubio_filter_set_a_weighting (aubio_filter_t * b, uint_t samplerate); 61 55 62 56 /* c_weighting */ 63 aubio_filter_t * new_aubio_filter_c_weighting (uint_t channels, uint_tsamplerate);57 aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate); 64 58 uint_t aubio_filter_set_c_weighting (aubio_filter_t * b, uint_t samplerate); 65 59 66 60 /* biquad */ 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);61 aubio_filter_t * new_aubio_filter_biquad(lsmp_t b1, lsmp_t b2, lsmp_t b3, lsmp_t a2, lsmp_t a3); 68 62 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); 69 63 … … 94 88 95 89 /* pvoc */ 96 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s , uint_t channels);90 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s); 97 91 void del_aubio_pvoc(aubio_pvoc_t *pv); 98 92 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t *in, cvec_t * fftgrain); … … 101 95 /* pitch detection */ 102 96 aubio_pitch_t *new_aubio_pitch (char *pitch_mode, 103 uint_t bufsize, uint_t hopsize, uint_t channels, uint_tsamplerate);97 uint_t bufsize, uint_t hopsize, uint_t samplerate); 104 98 void aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf); 105 99 uint_t aubio_pitch_set_tolerance(aubio_pitch_t *p, smpl_t thres); … … 109 103 /* tempo */ 110 104 aubio_tempo_t * new_aubio_tempo (char_t * mode, 111 uint_t buf_size, uint_t hop_size, uint_t channels, uint_tsamplerate);105 uint_t buf_size, uint_t hop_size, uint_t samplerate); 112 106 void aubio_tempo_do (aubio_tempo_t *o, fvec_t * input, fvec_t * tempo); 113 107 uint_t aubio_tempo_set_silence(aubio_tempo_t * o, smpl_t silence); … … 120 114 void aubio_specdesc_do (aubio_specdesc_t * o, cvec_t * fftgrain, 121 115 fvec_t * desc); 122 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size, 123 uint_t channels); 116 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size); 124 117 void del_aubio_specdesc (aubio_specdesc_t * o); 125 118 126 119 /* peak picker */ 127 aubio_peakpicker_t * new_aubio_peakpicker( uint_t channels);120 aubio_peakpicker_t * new_aubio_peakpicker(); 128 121 void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out); 129 122 fvec_t * aubio_peakpicker_get_thresholded_input(aubio_peakpicker_t * p); … … 140 133 aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * existingfile, const char * outputname); 141 134 void aubio_sndfile_info(aubio_sndfile_t * file); 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);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); 144 137 int del_aubio_sndfile(aubio_sndfile_t * file); 145 138 uint_t aubio_sndfile_channels(aubio_sndfile_t * file); -
tests/src/temporal/test-aweighting.c
r0536612 rf658288 8 8 uint_t nrates = 6; 9 9 uint_t samplerate, i = 0; 10 uint_t channels = 2;11 10 12 11 for ( samplerate = rates[i]; i < nrates ; i++ ) { 13 f = new_aubio_filter_a_weighting ( channels,samplerate);12 f = new_aubio_filter_a_weighting (samplerate); 14 13 del_aubio_filter (f); 15 14 16 f = new_aubio_filter (7 , channels*2);15 f = new_aubio_filter (7); 17 16 aubio_filter_set_a_weighting (f, samplerate); 18 17 del_aubio_filter (f); … … 20 19 21 20 // samplerate unknown 22 f = new_aubio_filter_a_weighting ( channels,4200);21 f = new_aubio_filter_a_weighting (4200); 23 22 del_aubio_filter (f); 24 23 25 24 // order to small 26 f = new_aubio_filter (2 , channels*2);25 f = new_aubio_filter (2); 27 26 aubio_filter_set_a_weighting (f, samplerate); 28 27 del_aubio_filter (f); 29 28 30 29 // order to big 31 f = new_aubio_filter (12 , channels*2);30 f = new_aubio_filter (12); 32 31 aubio_filter_set_a_weighting (f, samplerate); 33 32 del_aubio_filter (f); -
tests/src/temporal/test-cweighting.c
r0536612 rf658288 8 8 uint_t nrates = 6; 9 9 uint_t samplerate, i = 0; 10 uint_t channels = 2;11 10 12 11 for ( samplerate = rates[i]; i < nrates ; i++ ) { 13 f = new_aubio_filter_c_weighting ( channels,samplerate);12 f = new_aubio_filter_c_weighting (samplerate); 14 13 del_aubio_filter (f); 15 14 16 f = new_aubio_filter (5 , channels*2);15 f = new_aubio_filter (5); 17 16 aubio_filter_set_c_weighting (f, samplerate); 18 17 del_aubio_filter (f); … … 20 19 21 20 // samplerate unknown 22 f = new_aubio_filter_c_weighting ( channels,4200);21 f = new_aubio_filter_c_weighting (4200); 23 22 del_aubio_filter (f); 24 23 25 24 // order to small 26 f = new_aubio_filter (2 , channels*2);25 f = new_aubio_filter (2); 27 26 aubio_filter_set_c_weighting (f, samplerate); 28 27 del_aubio_filter (f); 29 28 30 29 // order to big 31 f = new_aubio_filter (12 , channels*2);30 f = new_aubio_filter (12); 32 31 aubio_filter_set_c_weighting (f, samplerate); 33 32 del_aubio_filter (f); -
tests/src/test-beattracking.c
r0536612 rf658288 7 7 /* allocate some memory */ 8 8 uint_t win_s = 1024; /* window size */ 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 */ 9 fvec_t * in = new_fvec (win_s); /* input buffer */ 10 fvec_t * out = new_fvec (win_s/4); /* input buffer */ 12 11 13 12 /* allocate fft and other memory space */ 14 aubio_beattracking_t * tempo = new_aubio_beattracking(win_s , channels);13 aubio_beattracking_t * tempo = new_aubio_beattracking(win_s); 15 14 16 15 uint_t i = 0; -
tests/src/test-biquad.c
r0536612 rf658288 4 4 /* allocate some memory */ 5 5 uint_t win_s = 1024; /* window size */ 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); 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); 9 8 10 9 aubio_filter_do_filtfilt(o,in,in); -
tests/src/test-cvec.c
r0536612 rf658288 4 4 /* allocate some memory */ 5 5 uint_t win_s = 1024; /* window size */ 6 uint_t channels = 1; /* number of channel */ 7 cvec_t * sp = new_cvec (win_s, channels); /* input buffer */ 6 cvec_t * sp = new_cvec (win_s); /* input buffer */ 8 7 del_cvec(sp); 9 8 -
tests/src/test-fft.c
r0536612 rf658288 5 5 /* allocate some memory */ 6 6 uint_t win_s = 8; /* window size */ 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; 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; 19 18 /* allocate fft and other memory space */ 20 aubio_fft_t * fft = new_aubio_fft(win_s ,channels);19 aubio_fft_t * fft = new_aubio_fft(win_s); 21 20 /* fill input with some data */ 22 21 fvec_print(in); -
tests/src/test-filter.c
r0536612 rf658288 6 6 /* allocate some memory */ 7 7 uint_t win_s = 32; /* window size */ 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 */ 8 fvec_t *in = new_fvec (win_s); /* input buffer */ 9 fvec_t *out = new_fvec (win_s); /* input buffer */ 11 10 12 11 13 aubio_filter_t *o = new_aubio_filter_c_weighting ( channels,44100);14 in->data[ 0][12] = 0.5;12 aubio_filter_t *o = new_aubio_filter_c_weighting (44100); 13 in->data[12] = 0.5; 15 14 fvec_print (in); 16 15 aubio_filter_do (o, in); … … 18 17 del_aubio_filter (o); 19 18 20 o = new_aubio_filter_c_weighting ( channels,44100);21 in->data[ 0][12] = 0.5;19 o = new_aubio_filter_c_weighting (44100); 20 in->data[12] = 0.5; 22 21 fvec_print (in); 23 22 aubio_filter_do_outplace (o, in, out); … … 25 24 del_aubio_filter (o); 26 25 27 o = new_aubio_filter_c_weighting ( channels,44100);28 in->data[ 0][12] = 0.5;26 o = new_aubio_filter_c_weighting (44100); 27 in->data[12] = 0.5; 29 28 fvec_print (in); 30 29 aubio_filter_do_filtfilt (o, in, out); -
tests/src/test-filterbank.c
r0536612 rf658288 9 9 /* allocate some memory */ 10 10 uint_t win_s = 1024; /* window size */ 11 uint_t channels = 2; /* number of channel */12 11 uint_t n_filters = 13; /* number of filters */ 13 cvec_t *in = new_cvec (win_s , channels); /* input buffer */14 fvec_t *out = new_fvec (win_s , channels); /* input buffer */15 f vec_t *coeffs = NULL;12 cvec_t *in = new_cvec (win_s); /* input buffer */ 13 fvec_t *out = new_fvec (win_s); /* input buffer */ 14 fmat_t *coeffs = NULL; 16 15 17 16 /* allocate fft and other memory space */ … … 23 22 } 24 23 24 /* 25 25 if (fvec_max (coeffs) != 0.) { 26 26 return -1; … … 30 30 return -1; 31 31 } 32 */ 32 33 33 f vec_print (coeffs);34 fmat_print (coeffs); 34 35 35 36 aubio_filterbank_do (o, in, out); -
tests/src/test-filterbank_mel.c
r0536612 rf658288 9 9 /* allocate some memory */ 10 10 uint_t win_s = 512; /* fft size */ 11 uint_t channels = 2; /* number of channel */12 11 uint_t n_filters = 40; /* number of filters */ 13 cvec_t *in = new_cvec (win_s , channels); /* input buffer */14 fvec_t *out = new_fvec (win_s , channels); /* input buffer */15 f vec_t *coeffs = NULL;12 cvec_t *in = new_cvec (win_s); /* input buffer */ 13 fvec_t *out = new_fvec (win_s); /* input buffer */ 14 fmat_t *coeffs = NULL; 16 15 smpl_t samplerate = 16000.; 17 16 … … 27 26 } 28 27 29 //f vec_print (coeffs);28 //fmat_print (coeffs); 30 29 31 30 //fprintf(stderr, "%f\n", fvec_sum(coeffs)); -
tests/src/test-fvec.c
r0536612 rf658288 4 4 /* allocate some memory */ 5 5 uint_t win_s = 1024; /* window size */ 6 uint_t channels = 1; /* number of channel */ 7 fvec_t * in = new_fvec (win_s, channels); /* input buffer */ 6 fvec_t * in = new_fvec (win_s); /* input buffer */ 8 7 del_fvec(in); 9 8 -
tests/src/test-hist.c
r0536612 rf658288 8 8 uint_t length; 9 9 for (length = 1; length < 10; length ++ ) { 10 aubio_hist_t *o = new_aubio_hist(0, 1, length , 5);10 aubio_hist_t *o = new_aubio_hist(0, 1, length); 11 11 fvec_t *t = new_aubio_window("hanning", length); 12 12 aubio_hist_do(o,t); -
tests/src/test-mfcc.c
r0536612 rf658288 6 6 /* allocate some memory */ 7 7 uint_t win_s = 512; /* fft size */ 8 uint_t channels = 1; /* number of channel */9 8 uint_t n_filters = 40; /* number of filters */ 10 9 uint_t n_coefs = 13; /* number of coefficients */ 11 cvec_t *in = new_cvec (win_s , channels); /* input buffer */12 fvec_t *out = new_fvec (n_coefs , channels); /* input buffer */10 cvec_t *in = new_cvec (win_s); /* input buffer */ 11 fvec_t *out = new_fvec (n_coefs); /* input buffer */ 13 12 smpl_t samplerate = 16000.; 14 13 -
tests/src/test-onset.c
r0536612 rf658288 4 4 /* allocate some memory */ 5 5 uint_t win_s = 1024; /* window size */ 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.); 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.); 10 9 uint_t i = 0; 11 10 -
tests/src/test-onsetdetection.c
r0536612 rf658288 8 8 { 9 9 uint_t win_s = 1024; /* window size */ 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 */ 10 cvec_t *in = new_cvec (win_s); /* input buffer */ 11 fvec_t *out = new_fvec (1); /* input buffer */ 13 12 14 13 aubio_specdesc_t *o; 15 14 16 o = new_aubio_specdesc ("energy", win_s , channels);15 o = new_aubio_specdesc ("energy", win_s); 17 16 aubio_specdesc_do (o, in, out); 18 17 del_aubio_specdesc (o); 19 18 20 o = new_aubio_specdesc ("energy", win_s , channels);19 o = new_aubio_specdesc ("energy", win_s); 21 20 aubio_specdesc_do (o, in, out); 22 21 del_aubio_specdesc (o); 23 22 24 o = new_aubio_specdesc ("hfc", win_s , channels);23 o = new_aubio_specdesc ("hfc", win_s); 25 24 aubio_specdesc_do (o, in, out); 26 25 del_aubio_specdesc (o); 27 26 28 o = new_aubio_specdesc ("complex", win_s , channels);27 o = new_aubio_specdesc ("complex", win_s); 29 28 aubio_specdesc_do (o, in, out); 30 29 del_aubio_specdesc (o); 31 30 32 o = new_aubio_specdesc ("phase", win_s , channels);31 o = new_aubio_specdesc ("phase", win_s); 33 32 aubio_specdesc_do (o, in, out); 34 33 del_aubio_specdesc (o); 35 34 36 o = new_aubio_specdesc ("kl", win_s , channels);35 o = new_aubio_specdesc ("kl", win_s); 37 36 aubio_specdesc_do (o, in, out); 38 37 del_aubio_specdesc (o); 39 38 40 o = new_aubio_specdesc ("mkl", win_s , channels);39 o = new_aubio_specdesc ("mkl", win_s); 41 40 aubio_specdesc_do (o, in, out); 42 41 del_aubio_specdesc (o); -
tests/src/test-peakpick.c
r0536612 rf658288 6 6 /* allocate some memory */ 7 7 uint_t win_s = 1024; /* window size */ 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 */ 8 fvec_t * in = new_fvec (win_s); /* input buffer */ 9 fvec_t * out = new_fvec (1); /* input buffer */ 11 10 aubio_peakpicker_t * o = new_aubio_peakpicker(1); 12 11 aubio_peakpicker_set_threshold (o, 0.3); -
tests/src/test-phasevoc-jack.c
r0536612 rf658288 22 22 uint_t pos = 0; /* frames%dspblocksize for jack loop */ 23 23 24 fvec_t * in ;25 cvec_t * fftgrain ;26 fvec_t * out ;24 fvec_t * in[2]; 25 cvec_t * fftgrain[2]; 26 fvec_t * out[2]; 27 27 28 aubio_pvoc_t * pv ;28 aubio_pvoc_t * pv[2]; 29 29 30 30 int aubio_process(float **input, float **output, int nframes); … … 32 32 int main(){ 33 33 /* allocate some memory */ 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 */ 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 */ 37 39 /* allocate fft and other memory space */ 38 pv = new_aubio_pvoc(win_s,hop_s,channels); 40 pv[i] = new_aubio_pvoc(win_s,hop_s); 41 } 39 42 40 43 #ifdef HAVE_JACK … … 53 56 #endif 54 57 55 del_aubio_pvoc(pv); 56 del_cvec(fftgrain); 57 del_fvec(in); 58 del_fvec(out); 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 } 59 64 aubio_cleanup(); 60 65 return 0; … … 67 72 for (i=0;i<channels;i++) { 68 73 /* write input to datanew */ 69 fvec_write_sample(in , input[i][j], i, pos);74 fvec_write_sample(in[i], input[i][j], pos); 70 75 /* put synthnew in output */ 71 output[i][j] = fvec_read_sample(out , i, pos);76 output[i][j] = fvec_read_sample(out[i], pos); 72 77 } 73 78 /*time for fft*/ 74 79 if (pos == hop_s-1) { 75 80 /* block loop */ 76 aubio_pvoc_do (pv,in, fftgrain); 81 for (i=0;i<channels;i++) { 82 aubio_pvoc_do (pv[i], in[i], fftgrain[i]); 77 83 // zero phases of first channel 78 for (i=0;i<fftgrain ->length;i++) fftgrain->phas[0][i] = 0.;84 for (i=0;i<fftgrain[i]->length;i++) fftgrain[0]->phas[i] = 0.; 79 85 // double phases of second channel 80 for (i=0;i<fftgrain ->length;i++) {81 fftgrain ->phas[1][i] =82 aubio_unwrap2pi (fftgrain ->phas[1][i] * 2.);86 for (i=0;i<fftgrain[i]->length;i++) { 87 fftgrain[1]->phas[i] = 88 aubio_unwrap2pi (fftgrain[1]->phas[i] * 2.); 83 89 } 84 90 // copy second channel to third one 85 aubio_pvoc_rdo(pv ,fftgrain,out);91 aubio_pvoc_rdo(pv[i], fftgrain[i], out[i]); 86 92 pos = -1; 93 } 87 94 } 88 95 pos++; -
tests/src/test-phasevoc.c
r0536612 rf658288 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 */10 9 /* allocate some memory */ 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 */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 */ 14 13 /* allocate fft and other memory space */ 15 aubio_pvoc_t * pv = new_aubio_pvoc(win_s,hop_s ,channels);14 aubio_pvoc_t * pv = new_aubio_pvoc(win_s,hop_s); 16 15 /* fill input with some data */ 17 16 printf("initialised\n"); -
tests/src/test-pitchdetection.c
r0536612 rf658288 8 8 uint_t hop_s = win_s / 4; /* hop size */ 9 9 uint_t samplerate = 44100; /* samplerate */ 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 */ 10 fvec_t *in = new_fvec (hop_s); /* input buffer */ 11 fvec_t *out = new_fvec (1); /* input buffer */ 13 12 aubio_pitch_t *o = 14 new_aubio_pitch ("default", win_s, hop_s, channels,samplerate);13 new_aubio_pitch ("default", win_s, hop_s, samplerate); 15 14 uint_t i = 0; 16 15 -
tests/src/test-pitchfcomb.c
r0536612 rf658288 7 7 uint_t win_s = 1024; /* window size */ 8 8 uint_t hop_s = win_s/4; /* hop size */ 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); 9 fvec_t * in = new_fvec (hop_s); /* input buffer */ 10 fvec_t * out = new_fvec (1); 12 11 aubio_pitchfcomb_t * o = new_aubio_pitchfcomb ( 13 win_s, hop_s , channels);12 win_s, hop_s); 14 13 uint_t i = 0; 15 14 -
tests/src/test-pitchmcomb.c
r0536612 rf658288 7 7 uint_t win_s = 1024; /* window size */ 8 8 uint_t hop_s = win_s/4; /* hop size */ 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 */ 9 cvec_t * in = new_cvec (win_s); /* input buffer */ 10 fvec_t * out = new_fvec (1); /* input buffer */ 12 11 13 aubio_pitchmcomb_t * o = new_aubio_pitchmcomb(win_s, hop_s , channels);12 aubio_pitchmcomb_t * o = new_aubio_pitchmcomb(win_s, hop_s); 14 13 uint_t i = 0; 15 14 -
tests/src/test-pitchschmitt.c
r0536612 rf658288 6 6 /* allocate some memory */ 7 7 uint_t win_s = 1024; /* window size */ 8 fvec_t * in = new_fvec (win_s , 1); /* input buffer */9 fvec_t * out = new_fvec (1 , 1); /* input buffer */8 fvec_t * in = new_fvec (win_s); /* input buffer */ 9 fvec_t * out = new_fvec (1); /* input buffer */ 10 10 aubio_pitchschmitt_t * o = new_aubio_pitchschmitt(win_s); 11 11 uint_t i = 0; -
tests/src/test-pitchyin.c
r0536612 rf658288 6 6 /* allocate some memory */ 7 7 uint_t win_s = 1024; /* window size */ 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 */ 8 fvec_t * in = new_fvec (win_s); /* input buffer */ 9 fvec_t * out = new_fvec (win_s/2); /* input buffer */ 11 10 aubio_pitchyin_t *p = new_aubio_pitchyin (win_s); 12 11 uint_t i = 0; -
tests/src/test-pitchyinfft.c
r0536612 rf658288 6 6 /* allocate some memory */ 7 7 uint_t win_s = 1024; /* window size */ 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 */ 8 fvec_t * in = new_fvec (win_s); /* input buffer */ 9 fvec_t * out = new_fvec (1); /* output pitch periods */ 11 10 aubio_pitchyinfft_t * o = new_aubio_pitchyinfft(win_s); 12 11 aubio_pitchyinfft_set_tolerance (o, 0.2); -
tests/src/test-resample.c
r0536612 rf658288 7 7 /* allocate some memory */ 8 8 uint_t win_s = 1024; /* window size */ 9 uint_t channels = 1; /* number of channel */10 9 smpl_t ratio = 0.5; 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 */10 fvec_t *in = new_fvec (win_s); /* input buffer */ 11 fvec_t *out = new_fvec ((uint_t) (win_s * ratio)); /* input buffer */ 13 12 aubio_resampler_t *o = new_aubio_resampler (0.5, 0); 14 13 uint_t i = 0; -
tests/src/test-scale.c
r0536612 rf658288 6 6 /* allocate some memory */ 7 7 uint_t win_s = 1024; /* window size */ 8 uint_t channels = 1; /* number of channel */ 9 fvec_t * in = new_fvec (win_s, channels); /* input buffer */ 8 fvec_t * in = new_fvec (win_s); /* input buffer */ 10 9 aubio_scale_t * o = new_aubio_scale(0,1,2,3); 11 10 aubio_scale_set_limits (o,0,1,2,3); -
tests/src/test-tempo.c
r0536612 rf658288 5 5 /* allocate some memory */ 6 6 uint_t win_s = 1024; /* window size */ 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.); 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.); 11 10 uint_t i = 0; 12 11 -
tests/src/test-tss.c
r0536612 rf658288 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 */17 16 /* allocate some memory */ 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 */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 */ 24 23 /* allocate fft and other memory space */ 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);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); 28 27 29 aubio_tss_t * tss = new_aubio_tss(win_s,hop_s ,channels);28 aubio_tss_t * tss = new_aubio_tss(win_s,hop_s); 30 29 /* fill input with some data */ 31 30 printf("initialised\n");
Note: See TracChangeset
for help on using the changeset viewer.