static void runTss(LV2_Handle instance, uint32_t sample_count) { tss_t* t=(tss_t*) instance; aubio_tss_set_thres(t->tss,*t->thresh_p); float * readptr=t->in_p; float * transwrite=t->trans_p; float * steadywrite=t->steady_p; while(sample_count) { unsigned int num_copy=HOP_SIZE-t->index; if(num_copy> sample_count) { num_copy=sample_count; } memcpy(transwrite,t->transbuff->data[0]+t->index, sizeof(float) *num_copy); memcpy(steadywrite,t->steadybuff->data[0]+t->index, sizeof(float) * num_copy); memcpy(t->inbuff->data[0] +t->index,readptr,num_copy*sizeof(float)); steadywrite+=num_copy; transwrite+=num_copy; sample_count-=num_copy; readptr+=num_copy; t->index+=num_copy; if(t->index==HOP_SIZE) { t->index=0; aubio_pvoc_do(t->pv,t->inbuff,t->ci); aubio_tss_do(t->tss,t->ci,t->ct,t->cs); aubio_pvoc_rdo(t->pvt,t->ct,t->transbuff); aubio_pvoc_rdo(t->pvs,t->cs,t->steadybuff); } } if(t->latency_p){ *t->latency_p=HOP_SIZE; } }
/* execute onset detection function on iput buffer */ void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset) { smpl_t isonset = 0; aubio_pvoc_do (o->pv,input, o->fftgrain); aubio_specdesc_do (o->od, o->fftgrain, o->desc); aubio_peakpicker_do(o->pp, o->desc, onset); isonset = onset->data[0]; if (isonset > 0.) { if (aubio_silence_detection(input, o->silence)==1) { //AUBIO_DBG ("silent onset, not marking as onset\n"); isonset = 0; } else { uint_t new_onset = o->total_frames + (uint_t)ROUND(isonset * o->hop_size); if (o->last_onset + o->minioi < new_onset) { //AUBIO_DBG ("accepted detection, marking as onset\n"); o->last_onset = new_onset; } else { //AUBIO_DBG ("doubled onset, not marking as onset\n"); isonset = 0; } } } else { // we are at the beginning of the file, and we don't find silence if (o->total_frames == 0 && aubio_silence_detection(input, o->silence) == 0) { //AUBIO_DBG ("beginning of file is not silent, marking as onset\n"); isonset = o->delay / o->hop_size; o->last_onset = o->delay; } } onset->data[0] = isonset; o->total_frames += o->hop_size; return; }
static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { unsigned int j; /*frames*/ for (j=0;j<(unsigned)nframes;j++) { if(usejack) { /* write input to datanew */ fvec_write_sample(ibuf, input[0][j], pos); /* put synthnew in output */ output[0][j] = fvec_read_sample(obuf, pos); } /*time for fft*/ if (pos == overlap_size-1) { /* block loop */ //compute mag spectrum aubio_pvoc_do (pv, ibuf, fftgrain); //compute mfccs aubio_mfcc_do(mfcc, fftgrain, mfcc_out); /* end of block loop */ pos = -1; /* so it will be zero next j loop */ } pos++; } return 1; }
/* do method for each algorithm */ void aubio_pitch_do_mcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf) { aubio_filter_do_outplace (p->filter, ibuf, p->filtered); aubio_pvoc_do (p->pv, ibuf, p->fftgrain); aubio_pitchmcomb_do (p->p_object, p->fftgrain, obuf); obuf->data[0] = aubio_bintofreq (obuf->data[0], p->samplerate, p->bufsize); }
void process_block (fvec_t *ibuf, fvec_t *obuf) { fvec_zeros(obuf); //compute mag spectrum aubio_pvoc_do (pv, ibuf, fftgrain); //compute mfccs aubio_mfcc_do(mfcc, fftgrain, mfcc_out); }
bool AubioOnsetDetector :: processframe(float* frame, const int& n){ bool newFrameResult = false; //Paul Brossier's aubioonsetclass~ code ported from Pd int j,isonset; for (j=0;j<n;j++) { // write input to datanew fvec_write_sample(vec, frame[j], 0, pos);//vec->data[0][pos] = frame[j] //time for fft if (pos == hopsize-1) { //hopsize is 512 newFrameResult = true; aubioOnsetFound = false; // block loop aubio_pvoc_do (pv,vec, fftgrain); fftgrain->norm[0][0] = fabs(fftgrain->norm[0][0]); //added hack to solve bug that norm[0][0] is negative sometimes. aubio_onsetdetection(o, fftgrain, onset); rawDetectionValue = onset->data[0][0]; //Paul Brossier's method to return value of peak picking process postProcessing(); // smpl_t my_sample_value; //peakPickedDetectionValue = aubio_peakpick_pimrt_getval(parms); //peakPickedDetectionValue = my_sample_value; //Paul Brossier's onset detection method isonset = aubio_peakpick_pimrt(onset,parms); if (isonset) { // test for silence if (aubio_silence_detection(vec, threshold2)==1){ isonset=0; } else{ // outlet_bang(x->bangoutlet); aubioOnsetFound = true; } }//end if (isonset) // end of block loop pos = -1; // so it will be zero next j loop } pos++; }//end for j //end of Paul's code return newFrameResult; }
/* execute onset detection function on iput buffer */ void aubio_onset_do (aubio_onset_t *o, const fvec_t * input, fvec_t * onset) { smpl_t isonset = 0; aubio_pvoc_do (o->pv,input, o->fftgrain); /* if (apply_filtering) { } */ if (o->apply_awhitening) { aubio_spectral_whitening_do(o->spectral_whitening, o->fftgrain); } if (o->apply_compression) { cvec_logmag(o->fftgrain, o->lambda_compression); } aubio_specdesc_do (o->od, o->fftgrain, o->desc); aubio_peakpicker_do(o->pp, o->desc, onset); isonset = onset->data[0]; if (isonset > 0.) { if (aubio_silence_detection(input, o->silence)==1) { //AUBIO_DBG ("silent onset, not marking as onset\n"); isonset = 0; } else { // we have an onset uint_t new_onset = o->total_frames + (uint_t)ROUND(isonset * o->hop_size); // check if last onset time was more than minioi ago if (o->last_onset + o->minioi < new_onset) { // start of file: make sure (new_onset - delay) >= 0 if (o->last_onset > 0 && o->delay > new_onset) { isonset = 0; } else { //AUBIO_DBG ("accepted detection, marking as onset\n"); o->last_onset = MAX(o->delay, new_onset); } } else { //AUBIO_DBG ("doubled onset, not marking as onset\n"); isonset = 0; } } } else { // we are at the beginning of the file if (o->total_frames <= o->delay) { // and we don't find silence if (aubio_silence_detection(input, o->silence) == 0) { uint_t new_onset = o->total_frames; if (o->total_frames == 0 || o->last_onset + o->minioi < new_onset) { isonset = o->delay / o->hop_size; o->last_onset = o->total_frames + o->delay; } } } } onset->data[0] = isonset; o->total_frames += o->hop_size; return; }
int main (void) { uint_t n = 10; // compute n times uint_t win_s = 1024; // window size uint_t hop_s = 256; // hop size // create some vectors fvec_t * in = new_fvec (hop_s); // input buffer cvec_t * fftgrain = new_cvec (win_s); // fft norm and phase cvec_t * cstead = new_cvec (win_s); // fft norm and phase cvec_t * ctrans = new_cvec (win_s); // fft norm and phase fvec_t * stead = new_fvec (hop_s); // output buffer fvec_t * trans = new_fvec (hop_s); // output buffer // create phase vocoder for analysis of input signal aubio_pvoc_t * pv = new_aubio_pvoc (win_s,hop_s); // create transient/steady-state separation object aubio_tss_t * tss = new_aubio_tss(win_s,hop_s); // create phase vocoder objects for synthesis of output signals aubio_pvoc_t * pvt = new_aubio_pvoc(win_s,hop_s); aubio_pvoc_t * pvs = new_aubio_pvoc(win_s,hop_s); /* execute stft */ while ( n-- ) { // fftgrain = pv(in) aubio_pvoc_do (pv, in, fftgrain); // ctrans, cstead = tss (fftgrain) aubio_tss_do (tss, fftgrain, ctrans, cstead); // stead = pvt_inverse (cstead) // trans = pvt_inverse (ctrans) aubio_pvoc_rdo (pvt, cstead, stead); aubio_pvoc_rdo (pvs, ctrans, trans); } aubio_tss_set_alpha(tss, 4.); aubio_tss_set_beta(tss, 3.); aubio_tss_set_threshold(tss, 3.); del_aubio_pvoc(pv); del_aubio_pvoc(pvt); del_aubio_pvoc(pvs); del_aubio_tss(tss); del_fvec(in); del_cvec(fftgrain); del_cvec(cstead); del_cvec(ctrans); del_fvec(stead); del_fvec(trans); aubio_cleanup(); return 0; }
/* execute tempo detection function on iput buffer */ void aubio_tempo_do(aubio_tempo_t *o, fvec_t * input, fvec_t * tempo) { uint_t i; uint_t winlen = o->winlen; uint_t step = o->step; fvec_t * thresholded; aubio_pvoc_do (o->pv, input, o->fftgrain); aubio_specdesc_do (o->od, o->fftgrain, o->of); /*if (usedoubled) { aubio_specdesc_do(o2,fftgrain, onset2); onset->data[0] *= onset2->data[0]; }*/ /* execute every overlap_size*step */ if (o->blockpos == (signed)step -1 ) { /* check dfframe */ aubio_beattracking_do(o->bt,o->dfframe,o->out); /* rotate dfframe */ for (i = 0 ; i < winlen - step; i++ ) o->dfframe->data[i] = o->dfframe->data[i+step]; for (i = winlen - step ; i < winlen; i++ ) o->dfframe->data[i] = 0.; o->blockpos = -1; } o->blockpos++; aubio_peakpicker_do (o->pp, o->of, o->onset); tempo->data[1] = o->onset->data[0]; thresholded = aubio_peakpicker_get_thresholded_input(o->pp); o->dfframe->data[winlen - step + o->blockpos] = thresholded->data[0]; /* end of second level loop */ tempo->data[0] = 0; /* reset tactus */ i=0; for (i = 1; i < o->out->data[0]; i++ ) { /* if current frame is a predicted tactus */ if (o->blockpos == FLOOR(o->out->data[i])) { tempo->data[0] = o->out->data[i] - FLOOR(o->out->data[i]); /* set tactus */ /* test for silence */ /* if (aubio_silence_detection(input, o->silence)==1) { tempo->data[0] = 0; // unset beat if silent } */ o->last_beat = o->total_frames + (uint_t)ROUND(tempo->data[0] * o->hop_size); } } o->total_frames += o->hop_size; return; }
int main (void) { uint_t n = 6; // compute n times uint_t win_s = 32; // window size uint_t hop_s = win_s / 4; // hop size fvec_t * in = new_fvec (hop_s); // input buffer cvec_t * fftgrain = new_cvec (win_s); // fft norm and phase fvec_t * out = new_fvec (hop_s); // output buffer // allocate fft and other memory space aubio_pvoc_t * pv = new_aubio_pvoc(win_s,hop_s); // fill input with some data fvec_set_all (in, 1.); fvec_print (in); while ( n-- ) { // get some fresh input data // .. // execute phase vocoder aubio_pvoc_do (pv,in,fftgrain); // do something with fftgrain // ... cvec_print (fftgrain); // optionally rebuild the signal aubio_pvoc_rdo(pv,fftgrain,out); // and do something with the result // ... fvec_print (out); } // clean up del_fvec(in); del_cvec(fftgrain); del_fvec(out); del_aubio_pvoc(pv); aubio_cleanup(); return 0; }
int *aubio_process(t_sample *sample, float *input, sf_count_t nframes) { unsigned int j, i; int *result; for (j=0; j < nframes; j++) { for (i=0; i < channels; i++) { /* write input to datanew */ fvec_write_sample(ibuf, input[channels*j+i], i, pos % overlap_size); } /*time for fft*/ if (pos % overlap_size == (overlap_size - 1)) { int isonset; /* block loop */ aubio_pvoc_do(pv, ibuf, fftgrain); aubio_onsetdetection(o, fftgrain, onset); if (usedoubled) { aubio_onsetdetection(o2,fftgrain, onset2); onset->data[0][0] *= onset2->data[0][0]; } isonset = aubio_peakpick_pimrt(onset, parms); if (isonset) { /* test for silence */ if (aubio_silence_detection(ibuf, silence)==1) { printf("silence.\n"); isonset=0; } else { printf("onset! %d\n", pos); onsets[onset_n++] = pos; } } } pos++; } result = (int *) calloc(1, sizeof(int) * (onset_n + 1)); memcpy(result, onsets, sizeof(int) * onset_n); result[onset_n] = -1; printf("found %d onsets\n", onset_n); return(result); }
/* execute tempo detection function on iput buffer */ void aubio_tempo(aubio_tempo_t *o, fvec_t * input, fvec_t * tempo) { uint_t i; uint_t winlen = o->winlen; uint_t step = o->step; aubio_pvoc_do (o->pv, input, o->fftgrain); aubio_onsetdetection(o->od, o->fftgrain, o->of); /*if (usedoubled) { aubio_onsetdetection(o2,fftgrain, onset2); onset->data[0][0] *= onset2->data[0][0]; }*/ /* execute every overlap_size*step */ if (o->blockpos == (signed)step -1 ) { /* check dfframe */ aubio_beattracking_do(o->bt,o->dfframe,o->out); /* rotate dfframe */ for (i = 0 ; i < winlen - step; i++ ) o->dfframe->data[0][i] = o->dfframe->data[0][i+step]; for (i = winlen - step ; i < winlen; i++ ) o->dfframe->data[0][i] = 0.; o->blockpos = -1; } o->blockpos++; tempo->data[0][1] = aubio_peakpick_pimrt_wt(o->of,o->pp, &(o->dfframe->data[0][winlen - step + o->blockpos])); /* end of second level loop */ tempo->data[0][0] = 0; /* reset tactus */ i=0; for (i = 1; i < o->out->data[0][0]; i++ ) { /* if current frame is a predicted tactus */ if (o->blockpos == o->out->data[0][i]) { /* test for silence */ if (aubio_silence_detection(input, o->silence)==1) { tempo->data[0][1] = 0; /* unset onset */ tempo->data[0][0] = 0; /* unset tactus */ } else { tempo->data[0][0] = 1; /* set tactus */ } } } }
int main(){ int i; uint_t win_s = 1024; /* window size */ uint_t hop_s = 256; /* hop size */ uint_t channels = 4; /* number of channels */ /* allocate some memory */ fvec_t * in = new_fvec (hop_s, channels); /* input buffer */ cvec_t * fftgrain = new_cvec (win_s, channels); /* fft norm and phase */ cvec_t * cstead = new_cvec (win_s, channels); /* fft norm and phase */ cvec_t * ctrans = new_cvec (win_s, channels); /* fft norm and phase */ fvec_t * stead = new_fvec (hop_s, channels); /* output buffer */ fvec_t * trans = new_fvec (hop_s, channels); /* output buffer */ /* allocate fft and other memory space */ aubio_pvoc_t * pv = new_aubio_pvoc (win_s,hop_s,channels); aubio_pvoc_t * pvt = new_aubio_pvoc(win_s,hop_s,channels); aubio_pvoc_t * pvs = new_aubio_pvoc(win_s,hop_s,channels); aubio_tss_t * tss = new_aubio_tss(0.01,3.,4.,win_s,hop_s,channels); /* fill input with some data */ printf("initialised\n"); /* execute stft */ for (i = 0; i < 10; i++) { aubio_pvoc_do (pv,in,fftgrain); aubio_tss_do (tss,fftgrain,ctrans,cstead); aubio_pvoc_rdo(pvt,cstead,stead); aubio_pvoc_rdo(pvs,ctrans,trans); } del_aubio_pvoc(pv); del_fvec(in); del_cvec(fftgrain); del_cvec(cstead); del_cvec(ctrans); del_fvec(stead); del_fvec(trans); aubio_cleanup(); printf("memory freed\n"); return 0; }
void ofxAubioMelBands::blockAudioIn() { aubio_pvoc_do(pv, aubio_input, spectrum); aubio_filterbank_do(fb, spectrum, bands); }
int main (int argc, char** argv) { sint_t err = 0; if (argc < 2) { err = 2; PRINT_WRN("no arguments, running tests\n"); err = test_wrong_params(); PRINT_MSG("usage: %s <input_path> [samplerate] [hop_size]\n", argv[0]); return err; } uint_t win_s; // fft size uint_t hop_s = 256; // block size uint_t samplerate = 0; // samplerate uint_t n_filters = 40; // number of filters uint_t n_coeffs = 13; // number of coefficients uint_t read = 0; char_t *source_path = argv[1]; if ( argc >= 3 ) samplerate = atoi(argv[2]); if ( argc >= 4 ) hop_s = atoi(argv[3]); win_s = 2 * hop_s; aubio_source_t *source = 0; aubio_pvoc_t *pv = 0; aubio_mfcc_t *mfcc = 0; fvec_t *in = new_fvec (hop_s); // phase vocoder input cvec_t *fftgrain = new_cvec (win_s); // pvoc output / mfcc input fvec_t *out = new_fvec (n_coeffs); // mfcc output if (!in || !fftgrain || !out) { err = 1; goto failure; } // source source = new_aubio_source(source_path, samplerate, hop_s); if (!source) { err = 1; goto failure; } if (samplerate == 0) samplerate = aubio_source_get_samplerate(source); // phase vocoder pv = new_aubio_pvoc(win_s, hop_s); if (!pv) { err = 1; goto failure; } // mfcc object mfcc = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate); if (!mfcc) { err = 1; goto failure; } // processing loop do { aubio_source_do(source, in, &read); aubio_pvoc_do(pv, in, fftgrain); aubio_mfcc_do(mfcc, fftgrain, out); fvec_print(out); } while (read == hop_s); failure: if (mfcc) del_aubio_mfcc(mfcc); if (pv) del_aubio_pvoc(pv); if (source) del_aubio_source(source); if (in) del_fvec(in); if (fftgrain) del_cvec(fftgrain); if (out) del_fvec(out); aubio_cleanup(); return err; }
bool AubioOnsetDetector :: processframe(float frame[], int n){ bool newFrameResult = false; //Paul Brossier's aubioonsetclass~ code ported from Pd int j,isonset; for (j=0;j<n;j++) { // write input to datanew fvec_write_sample(vec, frame[j], 0, pos);//vec->data[0][pos] = frame[j] //time for fft if (pos == hopsize-1) { //hopsize is 512 newFrameResult = true; aubioOnsetFound = false; // block loop aubio_pvoc_do (pv,vec, fftgrain); fftgrain->norm[0][0] = fabs(fftgrain->norm[0][0]); //added hack to solve bug that norm[0][0] is negative sometimes. aubio_onsetdetection(o, fftgrain, onset); rawDetectionValue = onset->data[0][0]; //Paul Brossier's method to return value of peak picking process anrMedianProcessedOnsetFound = checkForMedianOnset(rawDetectionValue); bestSlopeValue = getBestSlopeValue(rawDetectionValue); anrBestSlopeOnset = checkForSlopeOnset(bestSlopeValue); // smpl_t my_sample_value; peakPickedDetectionValue = aubio_peakpick_pimrt_getval(parms); //peakPickedDetectionValue = my_sample_value; //this was what got sent from max object:: // outlet_float(x->detectionFunctionOutlet, my_sample_value); // outlet_float(x->rawDetectionFunctionOutlet, x->onset->data[0][0]); isonset = aubio_peakpick_pimrt(onset,parms); if (isonset) { // test for silence if (aubio_silence_detection(vec, -ofGetMouseX())==1) { printf("silence \n"); isonset=0; } else{ // outlet_bang(x->bangoutlet); aubioOnsetFound = true; } }//end if (isonset) // end of block loop pos = -1; // so it will be zero next j loop } pos++; // outL[j] = frame[j];//have added this so signal is "see through": outputting the input signal } //end of Paul's code return newFrameResult; }