[Windowns] [c++] PCM samples from microphone convert to value to sample and use with dsp fft loop over them

Posted: April 26, 2013 in DSP
Tags: , , , , , , , , , , ,

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);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s