Real-Time Onset Detection

Paul Brossier piem at piem.org
Tue Apr 1 00:00:04 CEST 2008


hi Paul,

On Wed, Mar 19, 2008 at 11:07:35AM -0700, Paul Dean wrote:
> Something is up with this and I can't find it.  I'm an AUBIO noob
> still.. lol
> 
> I'm trying to get onsets and their peak value in real-time.  It's
> actually working, but not 100%.
> 
>  
> 
> ISSUES:
> 
> *It seems if to many onsets happen at once, the program gets stuck and
> it no longer detects them. Buffer issues?

the overall code looks correct, but i don't think the following line
behaves as expected (didn't test):

ibuf->data = ∈ 

double check the values of the audio samples you send to the onset
detection, and the behaviour of the blocking loop over pos.

> 
> *The "threshold" variable seems to be ignored. It has no effect. 

it should. here is the number of onsets i find using two different
thresholds:

$ ./aubioonset -i /tmp/foo.wav -t 0.9 | wc -l
285
$ ./aubioonset -i /tmp/foo.wav -t 0.1 | wc -l
453
$ ./aubioonset -i /tmp/foo.wav -t 0.1 -O kl | wc -l
487
$ ./aubioonset -i /tmp/foo.wav -t 0.9 -O kl | wc -l
267

you can make sure you set the peak picker correctly using the function
aubio_peakpicker_get_threshold.

> *When I test for silence I get nothing. If I change silence to about
> -10.0, I get ALL silence. Is this working correctly?

-90.dB might be a bit low. try -70. if you have a lot of background
noise, even more for an input mic.

> Forgive me if there are obvious errors in this, I am new to AUBIO and
> DSP in general. This code was made in reference to aubioonset.c and
> utils.c.    I believe the issues are in my callback function.   Thanks
> for any help in advance.
> 

no problem. let us know if you find out more!

thanks, Paul

>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> //######################################################
> 
> //#  Real-Time Onset Detector
> 
> //#  
> 
> //#  Note: "currently NO error protection"
> 
> //#
> 
> //######################################################
> 
>  
> 
> #include <aubio.h>
> 
> #include "portaudio/include/portaudio.h"
> 
> #include "portaudio/src/common/pa_trace.h"
> 
> #include <windows.h>  //for Sleep() function
> 
>  
> 
>  
> 
> ///////// PORTAUDIO ///////
> 
> #define SAMPLE_RATE          (44100)
> 
> #define PA_SAMPLE_TYPE       paFloat32 
> 
> #define FRAMES_PER_BUFFER    (256)
> 
>  
> 
> typedef struct PaQaData
> 
> {
> 
>     unsigned long  framesLeft;
> 
>     int            numChannels;
> 
>     int            bytesPerSample;
> 
>     int            mode;
> 
>     short          sawPhase;
> 
>     PaSampleFormat format;
> 
> }PaQaData;
> 
>  
> 
>  
> 
> //////// AUBIO /////////
> 
> smpl_t threshold                      = (smpl_t)0.3;
> 
> smpl_t silence                        = -90.;
> 
> smpl_t peak;
> 
> fvec_t * ibuf;
> 
> aubio_pvoc_t * pv;
> 
> cvec_t * fftgrain;
> 
> uint_t buffer_size                    = (FRAMES_PER_BUFFER * 2);
> 
> uint_t overlap_size                   = FRAMES_PER_BUFFER;
> 
> uint_t channels                       = 1;
> 
> aubio_onsetdetection_type type_onset  = aubio_onset_kl;
> 
> aubio_onsetdetection_t *o;
> 
> fvec_t *onset;
> 
> aubio_pickpeak_t * parms;
> 
>  
> 
> uint_t isonset = 0;
> 
> uint_t pos = 0; /*frames%dspblocksize*/
> 
> uint_t number = 0;
> 
> static int gNumNoInputs = 0;
> 
>  
> 
>  
> 
> ///////////////////////////////////////////////////////////////////
> 
> class Audio
> 
> {
> 
> public:
> 
>       Audio() { inDev = new PaStreamParameters; Pa_Initialize(); }
> 
>       ~Audio() { Pa_Terminate(); delete inDev; }
> 
>  
> 
>       void StartCallback() { Pa_StartStream( stream ); }
> 
>       void StopCallback() { Pa_StopStream( stream ); }
> 
>       
> 
>       static int CallBack( const void *inputBuffer, void
> *outputBuffer,unsigned long framesPerBuffer,
> 
>                            const PaStreamCallbackTimeInfo* timeInfo,
> PaStreamCallbackFlags statusFlags,
> 
>                            void *userData );
> 
>  
> 
>       PaStreamParameters *inDev;
> 
>       PaStream *stream;
> 
>       PaQaData myData;
> 
> };
> 
>  
> 
> int Audio::CallBack( const void *inputBuffer, void *outputBuffer,
> unsigned long framesPerBuffer,
> 
>                               const PaStreamCallbackTimeInfo* timeInfo,
> PaStreamCallbackFlags statusFlags, void *userData )
> 
> {
> 
>       smpl_t *in = (smpl_t*)inputBuffer;
> 
>       isonset=0;
> 
>  
> 
>       /////// AUBIO ONSET DETECTION ////////////
> 
>     unsigned int f;       /*frames*/
> 
>     ibuf->data = ∈ 
> 
>  
> 
>     for (f=0;f<(unsigned)framesPerBuffer;f++) {
> 
>  
> 
>             //time for fft
> 
>             if (pos == overlap_size-1){    
> 
>  
> 
>                   aubio_pvoc_do(pv,ibuf, fftgrain);
> 
>                   aubio_onsetdetection(o,fftgrain, onset);
> 
>                   isonset = aubio_peakpick_pimrt(onset,parms);
> 
>  
> 
>                   if (isonset){
> 
>  
> 
>                         // test for silence 
> 
>                         if (aubio_silence_detection(ibuf, silence)==1){
> 
>  
> 
>                               isonset=0;
> 
>                         }
> 
>                         else{
> 
>  
> 
>                               peak = aubio_peakpick_pimrt_getval(parms);
> 
>                               printf("%d !ONSET DETECTED! %f \n",
> number++, peak);
> 
>                         }
> 
>                   } 
> 
>                   pos = -1; // so it will be zero next f loop 
> 
>             }
> 
>             pos++;
> 
>       }
> 
>   
> 
>       return 0;
> 
> }
> 
>  
> 
> ////////////////////////////////////////////////
> 
> int main(){
> 
>  
> 
>       ////////// AUBIO ////////////////////
> 
>       pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
> 
>       ibuf      = new_fvec(overlap_size, channels);
> 
>     fftgrain  = new_cvec(buffer_size, channels);
> 
>       parms = new_aubio_peakpicker(threshold);
> 
>       o = new_aubio_onsetdetection(type_onset,buffer_size,channels);
> 
>       onset = new_fvec(1, channels);
> 
>  
> 
>       //////// PORTAUDIO //////////////////
> 
>       Audio *audio = new Audio();
> 
>          
> 
>       audio->inDev->device = Pa_GetDefaultInputDevice();
> 
>       audio->inDev->channelCount = channels;
> 
>       audio->inDev->sampleFormat = PA_SAMPLE_TYPE;
> 
>       audio->inDev->suggestedLatency = Pa_GetDeviceInfo(
> audio->inDev->device )->defaultLowInputLatency;
> 
>       audio->inDev->hostApiSpecificStreamInfo = NULL;
> 
>  
> 
>       Pa_OpenStream  ( &audio->stream, audio->inDev, NULL, SAMPLE_RATE,
> FRAMES_PER_BUFFER, 0, audio->CallBack, NULL ); 
> 
>       audio->StartCallback();
> 
>  
> 
>       printf("\n The program will run for 30 seconds \n"); 
> 
>       Sleep(30000);
> 
>  
> 
>       return 0;
> 
> }
> 


-- 
To unsubscribe, send mail to aubio-unsubscribe at piem.org.




More information about the aubio-user mailing list