I use the Windows API to receive audio input. I followed all the steps in MSDN and was able to record audio to a WAV file. No problems. I use several buffers and all that. I would like to do more with buffers than just writing to a file, so now I have a callback set. It works fine, and I get the data, but I'm not sure what to do with it as soon as it appears.
Here is my callback ... everything works here:
// Media API callback void CALLBACK AudioRecorder::waveInProc(HWAVEIN hWaveIn, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) { // Data received if (uMsg == WIM_DATA) { // Get wav header LPWAVEHDR mBuffer = (WAVEHDR *)dwParam1; // Now what? for (unsigned i = 0; i != mBuffer->dwBytesRecorded; ++i) { // I can see the char, how do get them into my file and audio buffers? cout << mBuffer->lpData[i] << "\n"; } // Re-use buffer mResultHnd = waveInAddBuffer(hWaveIn, mBuffer, sizeof(mInputBuffer[0])); // mInputBuffer is a const WAVEHDR * } } // waveInOpen cannot use an instance method as its callback, // so we create a static method which calls the instance version void CALLBACK AudioRecorder::staticWaveInProc(HWAVEIN hWaveIn, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) { // Call instance version of method reinterpret_cast<AudioRecorder *>(dwParam1)->waveInProc(hWaveIn, uMsg, dwInstance, dwParam1, dwParam2); }
As I said, it works fine, but I'm trying to do the following:
- Convert data to short and copy to array
- Convert data to float and copy to array
- Copy the data to a char array, which I will write in WAV
- Transferring data to an arbitrary output device
I worked a lot with FMOD, and I am familiar with interleaving and all that. But FMOD offers everything that floats. In this case, I go the other way. I guess I'm just looking for resources to go from LPSTR to short, float and unsigned char.
Thank you very much!
source share