• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 983
  • Last Modified:

Failure using GSM 610 Windows CODEC with wave input/output devices (C++)

I have a program that records and sends audio over a network.  Right now it sends PCM audio but I would like it to send using the GSM codec that comes with.  I see it in my list of available codecs but the following code fails when it tries to create a wave in and output header.  Does anyone see where my settings are wrong or is there something further that needs to be set up to create a input device header?

Thanks in advance for the help!
-Jim M.

 if(codecType == PCM)
    {
        // prepare the WAVEFORMATEX structure
        waveFormatEx.wFormatTag = WAVE_FORMAT_PCM;
        waveFormatEx.nChannels = 1;
        waveFormatEx.nSamplesPerSec = (DWORD)sampleRate;
        waveFormatEx.nAvgBytesPerSec = (DWORD)sampleRate*2;
        waveFormatEx.nBlockAlign = 2;
        waveFormatEx.wBitsPerSample = 16;
        waveFormatEx.cbSize = 0;  // ignored for WAVE_FORMAT_PCM
    }
    else
    {
        waveFormatEx.wFormatTag = WAVE_FORMAT_GSM610;
        waveFormatEx.nChannels = 1;
        waveFormatEx.nSamplesPerSec = 8000;
        waveFormatEx.nAvgBytesPerSec = 1625;
        waveFormatEx.nBlockAlign = 65;
        waveFormatEx.wBitsPerSample = 0;
        waveFormatEx.cbSize = 2;
    }
    // open output device
    mmResult = waveOutOpen( &hWaveOutDevice,
                            WAVE_MAPPER,
                            &waveFormatEx,
                            (DWORD)hwnd,
                            (DWORD)NULL,
                            CALLBACK_WINDOW);

///ALWAYS FAILS FOR GSM regardless of the computer I've tried it on Win2k or XP.

    if( mmResult != MMSYSERR_NOERROR )
    {
        MessageBox(hwnd, "waveOutOpen() ERROR", "Sound2", MB_OK);
        waveOutGetErrorText(mmResult, tmpBuf, 100);
        MessageBox(hwnd, tmpBuf, "Sound2", MB_OK);
    }
0
jimmn
Asked:
jimmn
1 Solution
 
jkrCommented:
Hmm, you aren't setting 'wSamplesPerBlock'. Could that be the reason? See e.g. http://support.microsoft.com/default.aspx?scid=kb;en-us;153866 ("How To Use GSM Compression in Low-level Wave Recording"):

   pgsmwavefmt->wfx.wFormatTag = WAVE_FORMAT_GSM610;
   pgsmwavefmt->wfx.nChannels = 1;
   pgsmwavefmt->wfx.nSamplesPerSec = 8000;
   pgsmwavefmt->wfx.nAvgBytesPerSec = 1625;
   pgsmwavefmt->wfx.nBlockAlign = 65;
   pgsmwavefmt->wfx.wBitsPerSample = 0;
   pgsmwavefmt->wfx.cbSize = 2;
   pgsmwavefmt->wSamplesPerBlock = 320;
0
 
jimmnAuthor Commented:
Hi, thanks for the feedback.  No, sadly this code didn't fix the problem.  

Here's what I now have based on the suggestion:

void
waveInit(HWND hwnd)
{
    MMRESULT        mmResult;
    WAVEFORMATEX    waveFormatEx;
    HANDLE hgsmwavefmt;
    LPGSM610WAVEFORMAT pgsmwavefmt;

    char            tmpBuf[100];

    //gsm stuff      
    hgsmwavefmt = GlobalAlloc(GMEM_MOVEABLE,(UINT)(sizeof(GSM610WAVEFORMAT)));
    pgsmwavefmt = (LPGSM610WAVEFORMAT)GlobalLock(hgsmwavefmt);


    if(codecType == PCM)
    {
        // prepare the WAVEFORMATEX structure
        waveFormatEx.wFormatTag = WAVE_FORMAT_PCM;
        waveFormatEx.nChannels = 1;
        waveFormatEx.nSamplesPerSec = (DWORD)sampleRate;
        waveFormatEx.nAvgBytesPerSec = (DWORD)sampleRate*2;
        waveFormatEx.nBlockAlign = 2;
        waveFormatEx.wBitsPerSample = 16;
        waveFormatEx.cbSize = 0;  // ignored for WAVE_FORMAT_PCM
        mmResult = waveOutOpen( &hWaveOutDevice,
                        WAVE_MAPPER,
                        &waveFormatEx,
                        (DWORD)hwnd,
                        (DWORD)NULL,
                        CALLBACK_WINDOW);
    }
    else
    {
        pgsmwavefmt->wfx.wFormatTag = WAVE_FORMAT_GSM610;
        pgsmwavefmt->wfx.nChannels = 1;
        pgsmwavefmt->wfx.nSamplesPerSec = 9920;
        pgsmwavefmt->wfx.nAvgBytesPerSec = 1625;
        pgsmwavefmt->wfx.nBlockAlign = 65;
        pgsmwavefmt->wfx.wBitsPerSample = 0;
        pgsmwavefmt->wfx.cbSize = 2;
        pgsmwavefmt->wSamplesPerBlock = 320;

        waveInOpen(&hWaveInDevice, (UINT)WAVE_MAPPER,
            (LPWAVEFORMATEX)&(pgsmwavefmt->wfx),
            (DWORD)(UINT)hwnd, (DWORD)NULL,
            CALLBACK_WINDOW);
    }
    // open output device

    if( mmResult != MMSYSERR_NOERROR )
    {
        MessageBox(hwnd, "waveOutOpen() ERROR", "Sound2", MB_OK);
        waveOutGetErrorText(mmResult, tmpBuf, sizeof(tmpBuf));
        MessageBox(hwnd, tmpBuf, "Sound2", MB_OK);
    }  <-------SHOWS THIS ERROR EVERY TIME, the 2nd messagebox is blank...

0
 
DarthModCommented:
Submitted to PAQ with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now