?
Solved

How to record using WaveInOpen() ???

Posted on 1999-12-16
5
Medium Priority
?
626 Views
Last Modified: 2013-11-20
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...
0
Comment
Question by:Shahzad_mca
  • 3
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 60 total points
ID: 2290752
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
 

Author Comment

by:Shahzad_mca
ID: 2307259
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
 
LVL 23

Expert Comment

by:chensu
ID: 2308092
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
 

Author Comment

by:Shahzad_mca
ID: 2309037
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
 
LVL 23

Expert Comment

by:chensu
ID: 2309078
if (MMRESULT mmr=::mmioAscend(hmmio, &mmckinfoParent, 0) != 0)

should read

MMRESULT mmr;
if ((mmr=::mmioAscend(hmmio, &mmckinfoParent, 0)) != 0)
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…

589 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