I've set up a program that can record sounds from a microphone using a Wave-in header, and it stores the data inside the WaveInHDR, I believe, in the "lpstr" part of the header. I am planning to use this data to perform some analysis, such as determining the frequency of a sample.
What I was wondering was how I should access this data? I know that I can retrieve the length of the data I need in bytes via WaveInHDR.dwBufferLength, but how should it be read? As far as I know, lpstr is a pointer to a string, and what do I need to do with it to retrieve the integers for the PCM (I'm assuming that it is Pulse Code Modulation that is at the pointer)?
If anyone has any knowledge about this, or a better way for me to retrieve the frequency from a Wave-in header sample that'd be great. Thanks!
You only need to cast the lpstr member to the appropriate type. For 16-bit PCM data it would be short. Calculating the number of shorts is done like this:
int nSamples = phdr->dwBytesRecorded * 8 / pwfex->wBitsPerSample;
Of course, this assumes that you are also using as WAVEFORMATEX structure (which you should be). For 16-bit PCM, the calculation resolves to dwBytesRecorded / 2 -or- dwBytesRecorded * 8/16.
Be careful that you are recording the microphone in mono. If you try to analyze stereo wave files then you will need to account for the two channels being interlaced. Two ways of doing this are to split the single stereo buffer into two mono buffers and analyze individually, or make sure your analysis functions understand both mono and stereo.
Thankyou, that's great. I am recording in mono, so that isn't an issue, and yes, I am using a waveformatex structure as well.
Although, how should I cast the lpstr member to a short? Obviously it will need to be an array of shorts, and whenever I try to cast the lpstr data into shorts, I get what appears to be garbage. How should I appropriately do this?
So far, I have
PCMdata[j] = BufferData[j] //BufferData is the lpstr variable, and PCM data an array of short ints
I know that this is wrong and was wondering how it should be done?