从ASIO驱动程序获取MM_WIM_DATA的音频数据

时间:2014-08-14 11:08:36

标签: c++ asio

我在Cc ++中有一个程序,它使用USB音频卡记录一些数据。它在Windows XP下完美运行。现在我必须将其移至Windows7。 Win7没有从该卡获取任何数据,所以我安装了ASIO驱动程序来解决这个问题。所以我尝试用Cooledit Pro获取一些数据并且它有效。但在我的程序中输入数据已损坏。 我正在使用fllowing函数来获取一些数据:

    void __fastcall AudioIn :: onMessage(TMessage & message) {
    if(message.Msg == MM_WIM_DATA && ! Terminated) {
    if(callback)
    callback(((WAVEHDR *)message.LParam) -> lpData,
       ((WAVEHDR *)message.LParam) -> dwBytesRecorded / 2);}

不幸的是,((WAVEHDR *)message.LParam) -> lpData包含ЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЃ之类的内容。我的错误在哪里?

添加其他代码:
1)找到我的USB设备

    for(int i = 0; deviceId == -1 && i < devNum; i ++)
    if(AudioDev :: getDevCaps(i).UpperCase().Pos(L"USB"))
      deviceId = i;
    zvvi -> initDevice(deviceId);

2)启动此设备

    initDevice(int deviceId) {
    if(wiState != wisClosed) closeDevice();
    wiDevice = deviceId;
    thread = new AudioIn(true);
    thread -> FreeOnTerminate = true;
    thread -> setCallback(callback);
    thread -> Start();}

3)准备WAVEHDR

    void __fastcall AudioIn :: prepareHeaders(int bCount, int bSize) {
    if(prepared)
    return;
    prepared = true;

    wiBuffCount = bCount;
    wiBuffSize = bSize;

    wavehdr = new WAVEHDR[wiBuffCount];
    buff = new char *[wiBuffCount];
    for(int i = 0; i < wiBuffCount; i ++)
    buff[i] = new char[wiBuffSize];

    for(int i = 0; i < wiBuffCount; i ++) {
    wavehdr[i].lpData = (char *)buff[i];
    wavehdr[i].dwBufferLength = wiBuffSize * sizeof(* buff[i]);
    wavehdr[i].dwLoops = 0;
    wavehdr[i].dwFlags = 0;
    check(waveInPrepareHeader(wiHandle, & wavehdr[i], sizeof(wavehdr[i])), L"wiPrepareHeader");
    }
  }

4)我也有配置设备的功能

    openDevice() {
    if(wiState != wisClosed)
      return;

    const samplerate = 44100;
    tWAVEFORMATEX format;
    format.wFormatTag = WAVE_FORMAT_PCM;
    format.nChannels = 1;
    format.nSamplesPerSec = samplerate;
    format.wBitsPerSample = 8;
    format.nBlockAlign = (format.nChannels * format.wBitsPerSample) / 8;
    format.nAvgBytesPerSec = (format.wBitsPerSample / 8) * samplerate;
    format.cbSize = 0;

5)启动线程,我的函数获取数据“AudioIn :: onMessage”

0 个答案:

没有答案