?
Solved

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

Posted on 2005-02-28
5
Medium Priority
?
960 Views
Last Modified: 2012-06-21
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
Comment
Question by:jimmn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 13425729
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
 

Author Comment

by:jimmn
ID: 13425946
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
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 13986638
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question