int main(){ /* allocate some memory */ uint_t win_s = 1024; /* window size */ fvec_t * in = new_fvec (win_s); /* input buffer */ fvec_t * out = new_fvec (win_s/4); /* input buffer */ /* allocate fft and other memory space */ aubio_beattracking_t * tempo = new_aubio_beattracking(win_s); uint_t i = 0; smpl_t curtempo, curtempoconf; while (i < 10) { aubio_beattracking_do(tempo,in,out); curtempo = aubio_beattracking_get_bpm(tempo); if (curtempo != 0.) { fprintf(stdout,"%f\n",curtempo); return 1; } curtempoconf = aubio_beattracking_get_confidence(tempo); if (curtempoconf != 0.) { fprintf(stdout,"%f\n",curtempo); return 1; } i++; }; del_aubio_beattracking(tempo); del_fvec(in); del_fvec(out); 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; }
/* 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 */ } } } }
//-------------------------------------------------------------- void aubioAnalyzer::processAudio (float * input, int bufferSize){ float rmsAmplitude = 0; for (int i = 0; i < bufferSize; i++){ //calculate the root mean square amplitude rmsAmplitude += sqrt(input[i]*input[i]); //put the data into aubio in->data[0][i] = input[i]; } //now we need to get the average rmsAmplitude /= bufferSize; amplitude = rmsAmplitude; //don't update the pitch if the sound is very quiet if( amplitude > 0.001 ){ //finally get the pitch of the sound pitch = aubio_pitchdetection(pitch_output,in); long int p=(int)pitch; if (p!=0){ while(p>440){ p=p/2; } while(p<220){ p=p*2; } } top_pitches[p]+=amplitude; pitch_color=pitch_color.fromHsb(p-222,255, 255); } aubio_beattracking_do(tracker,in,beats); }
int main(){ /* allocate some memory */ uint_t win_s = 1024; /* window size */ uint_t channels = 1; /* number of channel */ fvec_t * in = new_fvec (win_s, channels); /* input buffer */ fvec_t * out = new_fvec (win_s/4, channels); /* input buffer */ /* allocate fft and other memory space */ aubio_beattracking_t * tempo = new_aubio_beattracking(win_s, channels); uint_t i = 0; while (i < 10) { aubio_beattracking_do(tempo,in,out); i++; }; del_aubio_beattracking(tempo); del_fvec(in); del_fvec(out); aubio_cleanup(); return 0; }