c++ - Checking Audio buffer for sound -


i have program recording 24/7 1.5sec audio buffer microphone. now, instead of sending buffer (which has no sound @ all) server, makes more laggy , wastes bandwith, want check wheter buffer has sound in or not..

the buffer looks :

    short int *wavein = new short int[numpts]; 

where :

const double seconds = 1; const int samplerate = 8000; const int numpts = samplerate * seconds; 

so, have array of short ints has 8000 cells, stores audio buffer...

now, checking visual studio debugger, after i've been capturing microphone audio buffer, buffer looks :

wavein[0] = -125 wavein[1] = -780; wavein[2] = -1320; 

and on...

now, need detect using buffer, if has captured audio, or buffer containing no sound...

after running couple of times, i've noticed when buffer have sound inside it, cells contain smaller numbers. example, array sound in :

wavein[0] = -1300; wavein[1] = -3200; wavein[2] = -2400; 

now, problem is, times, buffer contains audio, has big numbers (that closer 0), though theres sound inside..

so example, times cells can have numbers in range of -600 ~ -1200 , have nothing inside them, , times, can have numbers in range of -600 ~ 1200 , contains sound inside..

so, how can detect wheter audio buffer has sound inside or not ?

i hope clear enough...

thanks!

edit: forgot mention, i'm useing wave api handle audio...

assuming using wave_format_pcm individual samples can range between 32k , -32k, silence being small numbers near 0. compute magnitude of sound should take absolute value of number of samples (positive , negative samples equally significant), average them. looking @ 3 samples inadequate (that's 3/8000th of second) pick interval comparable real sound, such few tenths of second. there no magic magnitude threshold means sound present, better strategy compare magnitude of successive intervals, or running average, looking change low (near-quiet) substantially higher (louder). have moving threshold based on background noise level.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -