c - Detect audio peak using gstreamer plugin -


i'm developing plugin in c detects audio peaks using gstreamer-1.0. don't have knowledge audio programming , far, plugin can detect sound impulsion (if there no audio, nothing happens, if there sound, print energy).

here sample code of (really simple) algorithm.

gfloat energy_of_sample(guint8 array[], int num_elements, gfloat *p) {     gfloat energy=0.f;     for(int i=0 ; i<num_elements ; i++)     {         energy += array[i]*array[i]/4096;         if (*p < (array[i]*array[i]/4096)) *p = array[i]*array[i]/4096;     }     return energy/num_elements; }  static void audio_process(gstbpmdetect *filter, gstbuffer *music) {      gstmapinfo info;     gint threshold = 6;   // gets information of buffer , put in "info"     gst_buffer_map (music, &info, gst_map_read);  // calculate average of buffer data     gfloat energy = 0;     gfloat peak = 0;     energy = energy_of_sample(info.data, info.size, &peak);     if (energy >= threshold )g_print("energy : %f , peak : %f \n", energy,peak); } 

if audio source is, exemple, simple hand clap or kick drum only, plugin detects audio peak fine. when audio source song, plugin detecting sound impulsion (always on threshold).

my solution issue add low-pass filter bass sound detected. doing that, i'm cutting every part of song containing high frequencies , not want (will not work high frequency beats).

so question : have idea on how detect beats (audio impulsion) without cutting high frequencies ? tanks , hope question clear !

you should measure energy not peak. there great method calculate energy. use variance formula statistics. need count square of sum , sum of squares points within interval of 20 - 50 milliseconds. using variance formula energy. formula here http://staff.icdi.wvu.edu/djhstats/variance1.jpg

as alternative may use existing plugin level in set of plugins.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -