Posts Tagged ‘convert to value’

I used this projects as my reference to how record from the microhphone in Windows with c++:

my WAVEFORMATEX values are:

wFormatTag 1 unsigned short (WAVE_FORMAT_PCM)
nChannels 1 unsigned short
nSamplesPerSec 11025 unsigned long
nAvgBytesPerSec 11025 unsigned long
nBlockAlign 1 unsigned short
wBitsPerSample 8 unsigned short
cbSize 0 unsigned short

In the event of PCM buffer input I call a callback function that uses this data from lpData in the given WAVEHDR .

The trick to get real useful values from this data (0 means silence) is to do a static cast to unsigend char * (reinterpret) and decrement 128 which is the biased zero.

unsigned char * lpData = reinterpret_cast<unsigned char *> (_lpData); 

for (int i=0;i<buffLen;i++)
       value + = abs(lpData[i]-128);