c – waveInProc / Windows音频问题

我正在使用 Windows API来获取音频输入.我已经按照MSDN上的所有步骤进行操作,并设法将音频录制到WAV文件中.没问题.我正在使用多个缓冲区.我想用缓冲区做更多事情而不是简单地写入文件,所以现在我已经设置了一个回调函数.它工作得很好,而且我正在获取数据,但是一旦我拥有它,我不知道该怎么做.

这是我的回调……这里的一切都有效:

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

}

就像我说的那样,效果很好,但我正在努力做到以下几点:

>将数据转换为short并复制到数组中
>将数据转换为float并复制到数组中
>将数据复制到一个更大的char数组,我将写入WAV
>将数据中继到任意输出设备

我和FMOD合作很多,我熟悉交错和所有这些.但FMOD把所有东西都当作花车.在这种情况下,我会走另一条路.我想我基本上只是在寻找有关如何从LPSTR转到short,float和unsigned char的资源.

非常感谢!

typedef struct { 
    LPSTR      lpData; 
    // etc..
} WAVEHDR;

Hmya,那里有尴尬的类型.它当然不是STR,应该是PVOID.只需将其转换为您需要的任何类型:

short* data = (short*)(mBuffer->lpData);
unsigned samples = mBuffer->dwBytesRecorded / sizeof(short);
// etc..
相关文章
相关标签/搜索