How to record using WaveInOpen() ???

The help in MSDN for Recording with WaveIn is given ,but doesn't mentioned how to save it in a file....
Earlier I've done the same with MCI..
Now I want to record using WaveIn...
Shahzad_mcaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
WAVE files are RIFF files. You need to use the mmio* functions. Download the following sample and extract the saving part.

Direct-to-Disk Recorder with ACM
http://support.microsoft.com/support/kb/articles/q116/2/93.asp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shahzad_mcaAuthor Commented:
hi Chensu,
  I;ve used the mmio functions in the below given code.the code saves the file in RIFF form also,but when i open that file for playing , gives an error that its not a waveform Audio type file...
 Also i noticed that the fuction

if (::mmioAscend(hmmio, &mmckinfoSubchunk, 0) != 0)
    {
        // Failed to write the data subchunk.
        ::mmioClose(hmmio, 0);
        return 6;
    }

 fails...
Please help me out if u can...

UINT WINAPI CSoundIn::WriteWaveToFile(LPCSTR lpszWaveFilename,
                            PCMWAVEFORMAT lppcmWaveFormat,
                            LPTSTR hpWaveData, DWORD dwWaveDataSize)
{/*
      ASSERT(lpszWaveFilename != NULL);
    ASSERT(::AfxIsValidString(lpszWaveFilename));
    ASSERT(lppcmWaveFormat != NULL);
    ASSERT(::IsValidPCMWaveFormat(lppcmWaveFormat)); */
     
    MMCKINFO mmckinfoParent, mmckinfoSubchunk;
    HMMIO hmmio;
     
    // Open the given file for writing using buffered I/O.
    if ((hmmio = ::mmioOpen((LPSTR)lpszWaveFilename, NULL,
                            MMIO_CREATE | MMIO_WRITE | MMIO_EXCLUSIVE))
        == NULL)
        // Failed to create wave file.
        return 1;
     
    // Create a 'RIFF' chunk with a 'WAVE' form type
    mmckinfoParent.fccType = mmioFOURCC('W', 'A', 'V', 'E');
    if (::mmioCreateChunk(hmmio, &mmckinfoParent, MMIO_CREATERIFF) != 0)
    {
        // Failed create 'RIFF' chunk.
        ::mmioClose(hmmio, 0);
        return 2;
    }
     
    // Create the format subchunk (form type 'fmt ').
    mmckinfoSubchunk.ckid = mmioFOURCC('f', 'm', 't', ' ');
    mmckinfoSubchunk.cksize = sizeof(PCMWAVEFORMAT);
    if (::mmioCreateChunk(hmmio, &mmckinfoSubchunk, 0) != 0)
    {
        // Failed create the format subchunk.
        ::mmioClose(hmmio, 0);
        return 3;
    }
     
    // Write the format subchunk.
    if (::mmioWrite(hmmio, hpWaveData, sizeof(PCMWAVEFORMAT))
        != (LONG)sizeof(PCMWAVEFORMAT))
    {
        // Failed to write the format subchunk.
        ::mmioClose(hmmio, 0);
        return 4;
    }
     
    // Ascend out of the format subchunk.
    if (::mmioAscend(hmmio, &mmckinfoSubchunk, 0) != 0)
    {
        // Failed to write the format subchunk.
        ::mmioClose(hmmio, 0);
        return 4;
    }
     
    // Create the data subchunk that holds the waveform samples.
    mmckinfoSubchunk.ckid = mmioFOURCC('d', 'a', 't', 'a');
    mmckinfoSubchunk.cksize = dwWaveDataSize;
    if (::mmioCreateChunk(hmmio, &mmckinfoSubchunk, 0) != 0)
    {
        // Failed to create the data subchunk.
        ::mmioClose(hmmio, 0);
        return 5;
    }
     
    if (hpWaveData != NULL && dwWaveDataSize != 0)
        // Write the waveform data subchunk.
        if (::mmioWrite(hmmio, hpWaveData, (LONG)dwWaveDataSize)
            != (LONG)dwWaveDataSize)
        {
            // Failed to write the data subchunk.
            ::mmioClose(hmmio, 0);
            return 6;
        }
     
    // Ascend out of the data subchunk.
    if (::mmioAscend(hmmio, &mmckinfoSubchunk, 0) != 0)
    {
        // Failed to write the data subchunk.
        ::mmioClose(hmmio, 0);
        return 6;
    }
     
    // Ascend out of the 'RIFF' chunk.
    if (MMRESULT mmr=::mmioAscend(hmmio, &mmckinfoParent, 0) != 0)
    {
        // Failed create 'RIFF' chunk.
        ::mmioClose(hmmio, 0);
            TRACE1("\n MMIOERR_CANNOTSEEK=%d",MMIOERR_CANNOTSEEK);
            TRACE1("\n MMIOERR_CANNOTWRITE=%d",MMIOERR_CANNOTWRITE);
            TRACE1("\n MMSYSERR_NOERROR =%d",MMSYSERR_NOERROR );
        return 2;
    }
     
    // We're done with the file, close it.
    ::mmioClose(hmmio, 0);
     
    return 0;    // successful
}
0
chensuCommented:
The WriteWaveToFile function (looks like my code posted to the other questions) should be working fine. I don't see anything wrong here. You have to debug it. You might also want to check out the wave.h, wave.cpp and wavwrite.h, wavwrite.cpp in the DirectX samples.
0
Shahzad_mcaAuthor Commented:
hi chensu,

 when debugged, I'm getting the error at the followint step..

if (MMRESULT mmr=::mmioAscend(hmmio, &mmckinfoParent, 0) != 0)
    {
        // Failed create 'RIFF' chunk.
        ::mmioClose(hmmio, 0);
TRACE1("\n MMIOERR_CANNOTSEEK=%d",MMIOERR_CANNOTSEEK);
TRACE1("\n MMIOERR_CANNOTWRITE=%d",MMIOERR_CANNOTWRITE);
TRACE1("\n MMSYSERR_NOERROR =%d",MMSYSERR_NOERROR );
        return 2;
    }
the error no .is 1 which is niether CANNOTSEEK nor CANNOTWRITE....

   And let me tell u that i have changed the parameters type form


UINT WINAPI ReadWaveFrommmio(HMMIO hmmio,
                             LPPCMWAVEFORMAT lppcmWaveFormat,
                             HPSTR FAR*lphpWaveData,                                          LPDWORD lpdwWaveDataSize)
To::

UINT WINAPI CSoundIn::WriteWaveToFile(LPCSTR lpszWaveFilename,
                            PCMWAVEFORMAT lppcmWaveFormat,
                            LPTSTR hpWaveData, DWORD dwWaveDataSize)

   will that affect....
Thankx...
0
chensuCommented:
if (MMRESULT mmr=::mmioAscend(hmmio, &mmckinfoParent, 0) != 0)

should read

MMRESULT mmr;
if ((mmr=::mmioAscend(hmmio, &mmckinfoParent, 0)) != 0)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.