none
waveInAddBuffer failing with MMSYSERR_ERROR

    Question

  • I'm writing an application to record audio in Windows using the wave api. My call to waveInAddBuffer is failing with the generic error
    MMSYSERR_ERROR. Any help would be greatly appreciated. Here is my code:                                                                                                 

    HWAVEIN hWaveIn;
    WAVEFORMATEX waveFormat;
    WAVEHDR waveHeader;
    unsigned char waveIn[8000 * 10]; // 10 seconds at 8000 samples/sec
    HANDLE eventHandle;
    
    int channels = 2;
    int samplesPerSec = 8000;
    int bitsPerSample = 8;
    int blockAlign = (channels * bitsPerSample) / 8;
    int bytesPerSec = samplesPerSec * blockAlign;
    
    waveFormat.wFormatTag = WAVE_FORMAT_PCM;
    waveFormat.nChannels = channels;
    waveFormat.nSamplesPerSec = samplesPerSec;
    waveFormat.nAvgBytesPerSec = bytesPerSec;
    waveFormat.nBlockAlign = blockAlign;
    waveFormat.wBitsPerSample = bitsPerSample;
    waveFormat.cbSize = 0;
    
    mmResult = waveInOpen(&hWaveIn, waveInID, &waveFormat, (DWORD)&eventHandle, 0,  CALLBACK_EVENT);
    INFO("waveInOpen() returned %08x", mmResult);
    
    waveHeader.lpData = (LPSTR)waveIn;
    waveHeader.dwBufferLength = 80000;      
    waveHeader.dwBytesRecorded = 0;
    waveHeader.dwUser = 0L;
    waveHeader.dwFlags = 0L;
    waveHeader.dwLoops = 0L;
    
    mmResult = waveInPrepareHeader(hWaveIn, &waveHeader, sizeof(WAVEHDR));      
    INFO("waveInPrepareHeader() returned %08x", mmResult);
    
    mmResult = waveInAddBuffer(hWaveIn, &waveHeader, sizeof(WAVEHDR));      
    INFO("waveInAddBuffer() returned %08x", mmResult);

    Thursday, January 31, 2013 7:15 PM

All replies

  • Did the call to waveInPrepareHeader work ok?  I guess it's possible that it could not lock 80,000 bytes into non-paged RAM.

    Friday, February 01, 2013 3:14 AM