waveInProc / Windows audio question...

Posted by BTR on Stack Overflow See other posts from Stack Overflow or by BTR
Published on 2011-01-08T05:20:46Z Indexed on 2011/01/08 12:54 UTC
Read the original article Hit count: 215

Filed under:
|
|
|
|

I'm using the Windows API to get audio input. I've followed all the steps on MSDN and managed to record audio to a WAV file. No problem. I'm using multiple buffers and all that. I'd like to do more with the buffers than simply write to a file, so now I've got a callback set up. It works great and I'm getting the data, but I'm not sure what to do with it once I have it.

Here's my callback... everything here works:

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

}

Like I said, it works great, but I'm trying to do the following:

  • Convert the data to short and copy into an array
  • Convert the data to float and copy into an array
  • Copy the data to a larger char array which I'll write into a WAV
  • Relay the data to an arbitrary output device

I've worked with FMOD a lot and I'm familiar with interleaving and all that. But FMOD dishes everything out as floats. In this case, I'm going the other way. I guess I'm basically just looking for resources on how to go from LPSTR to short, float, and unsigned char.

Thanks much in advance!

© Stack Overflow or respective owner

Related posts about c++

Related posts about Windows