Solved

Recording Program

Posted on 1998-02-05
8
396 Views
Last Modified: 2012-08-14
when I run the following code(REcording),
It doesn't recording ! What is the reason.
Thank You for your help

void PDlg::OnRec()
{
      // TODO: Add your control notification handler code here
      UINT wDeviceID;
      MCI_OPEN_PARMS mciOpen;
    MCI_RECORD_PARMS mciRec;
    MCI_GENERIC_PARMS mciClose;
    MCI_SAVE_PARMS      mciSave;

      wDeviceID = mciOpen.wDeviceID;

    mciRec.dwCallback = 0;
    mciSendCommand(mciOpen.wDeviceID, MCI_RECORD, MCI_WAIT, (DWORD)&mciRec);
      mciSave.lpfilename = "xxx.wav";
      mciSendCommand(wDeviceID, MCI_RECORD, MCI_TO | MCI_WAIT, (DWORD)(LPVOID) &mciRec);
      mciSave.dwCallback = 0;
      mciSendCommand(wDeviceID, MCI_SAVE, MCI_SAVE_FILE | MCI_WAIT, (DWORD)(LPVOID) &mciSave);
    mciClose.dwCallback = 0;
    mciSendCommand(mciOpen.wDeviceID, MCI_CLOSE, 0, (DWORD)&mciClose);
// TODO: Add your control notification handler code here

}
0
Comment
Question by:nba
  • 4
  • 3
8 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1180652
You miss out many parameters in your code. You can use the following example code, which is from the documentation.


Recording with a Waveform-Audio Device

The following example opens a waveform-audio device with a new file, records for the specified time, plays the recording, and prompts the user to save the recording if desired.

// Uses the MCI_OPEN, MCI_RECORD, and MCI_SAVE commands to record and
// save a waveform-audio file. Returns 0L if successful; otherwise,
// it returns an MCI error code.
DWORD recordWAVEFile(DWORD dwMilliSeconds)
{
    UINT wDeviceID;
    DWORD dwReturn;
    MCI_OPEN_PARMS mciOpenParms;
    MCI_RECORD_PARMS mciRecordParms;
    MCI_SAVE_PARMS mciSaveParms;
    MCI_PLAY_PARMS mciPlayParms;

    // Open a waveform-audio device with a new file for recording.
    mciOpenParms.lpstrDeviceType = "waveaudio";
    mciOpenParms.lpstrElementName = "";
    if (dwReturn = mciSendCommand(0, MCI_OPEN,
        MCI_OPEN_ELEMENT | MCI_OPEN_TYPE,         (DWORD)(LPVOID) &mciOpenParms))    {
        // Failed to open device; don't close it, just return error.
        return (dwReturn);
    }

    // The device opened successfully; get the device ID.
    wDeviceID = mciOpenParms.wDeviceID;

    // Begin recording and record for the specified number of
    // milliseconds. Wait for recording to complete before continuing.
    // Assume the default time format for the waveform-audio device
    // (milliseconds).
    mciRecordParms.dwTo = dwMilliSeconds;
    if (dwReturn = mciSendCommand(wDeviceID, MCI_RECORD,
        MCI_TO | MCI_WAIT, (DWORD)(LPVOID) &mciRecordParms))
    {
        mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
        return (dwReturn);
    }

    // Play the recording and query user to save the file.
    mciPlayParms.dwFrom = 0L;
    if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY,
        MCI_FROM | MCI_WAIT, (DWORD)(LPVOID) &mciPlayParms))
    {
        mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
        return (dwReturn);
    }
    if (MessageBox(hMainWnd, "Do you want to save this recording?",
        "", MB_YESNO) == IDNO)
    {
        mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
        return (0L);
    }

    // Save the recording to a file named TEMPFILE.WAV. Wait for
    // the operation to complete before continuing.
    mciSaveParms.lpfilename = "tempfile.wav";
    if (dwReturn = mciSendCommand(wDeviceID, MCI_SAVE,
        MCI_SAVE_FILE | MCI_WAIT, (DWORD)(LPVOID) &mciSaveParms))
    {
        mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
        return (dwReturn);
    }

    return (0L);
}

0
 

Author Comment

by:nba
ID: 1180653
How to assign the  dwMilliSeconds?
 dwMilliSeconds=1000 //(1000 HZ)  
0
 
LVL 23

Expert Comment

by:chensu
ID: 1180654
dwMilliSeconds specifies time in millisecond. If you want to record for 3 seconds (== 3000 milliseconds), dwMilliSeconds = 3000;
0
 

Author Comment

by:nba
ID: 1180655
When I check it, It is PCM Mono,11.142Hz
Can I change to 8 bits Stereo?
And The Record file (temp.wav) is created.
However, the content is empty, (No sound in the wav file)
That file is only 1 bytes.
The Coding is not right?
--------------------------
void CAPhoneDlg::OnRec()
{
UINT wDeviceID;

DWORD dwMilliSeconds=0.0000001;
MCI_OPEN_PARMS mciOpenParms;
MCI_OPEN_PARMS mciOpen;

MCI_RECORD_PARMS mciRecordParms;
MCI_SAVE_PARMS mciSaveParms;
MCI_PLAY_PARMS mciPlayParms;
MCI_GENERIC_PARMS mciClose;

mciOpenParms.lpstrDeviceType = "waveaudio";
mciOpenParms.lpstrElementName = "";
mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT | MCI_OPEN_TYPE, (DWORD)(LPVOID) &mciOpenParms);

wDeviceID = mciOpenParms.wDeviceID;

mciRecordParms.dwTo = dwMilliSeconds;
mciSendCommand(wDeviceID, MCI_RECORD, MCI_TO | MCI_WAIT, (DWORD)(LPVOID) &mciRecordParms);

// Play the recording and query user to save the file.
mciPlayParms.dwFrom = 0L;
mciSendCommand(wDeviceID, MCI_PLAY, MCI_FROM | MCI_WAIT, (DWORD)(LPVOID) &mciPlayParms);


mciSaveParms.lpfilename = "temp.wav";
mciSendCommand(wDeviceID, MCI_SAVE, MCI_SAVE_FILE | MCI_WAIT, (DWORD)(LPVOID) &mciSaveParms);

//???
//??? I hope close all pointer and files. The following code is right?
mciClose.dwCallback = 0;
mciSendCommand(mciOpen.wDeviceID, MCI_CLOSE, 0, (DWORD)&mciClose);

      
}

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:nba
ID: 1180656
When I check it, It is PCM Mono,11.142Hz
Can I change to 8 bits Stereo?
And The Record file (temp.wav) is created.
However, the content is empty, (No sound in the wav file)
That file is only 1 bytes.
The Coding is not right?
--------------------------
void CAPhoneDlg::OnRec()
{
UINT wDeviceID;

DWORD dwMilliSeconds=0.0000001;
MCI_OPEN_PARMS mciOpenParms;
MCI_OPEN_PARMS mciOpen;

MCI_RECORD_PARMS mciRecordParms;
MCI_SAVE_PARMS mciSaveParms;
MCI_PLAY_PARMS mciPlayParms;
MCI_GENERIC_PARMS mciClose;

mciOpenParms.lpstrDeviceType = "waveaudio";
mciOpenParms.lpstrElementName = "";
mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT | MCI_OPEN_TYPE, (DWORD)(LPVOID) &mciOpenParms);

wDeviceID = mciOpenParms.wDeviceID;

mciRecordParms.dwTo = dwMilliSeconds;
mciSendCommand(wDeviceID, MCI_RECORD, MCI_TO | MCI_WAIT, (DWORD)(LPVOID) &mciRecordParms);

// Play the recording and query user to save the file.
mciPlayParms.dwFrom = 0L;
mciSendCommand(wDeviceID, MCI_PLAY, MCI_FROM | MCI_WAIT, (DWORD)(LPVOID) &mciPlayParms);


mciSaveParms.lpfilename = "temp.wav";
mciSendCommand(wDeviceID, MCI_SAVE, MCI_SAVE_FILE | MCI_WAIT, (DWORD)(LPVOID) &mciSaveParms);

//???
//??? I hope close all pointer and files. The following code is right?
mciClose.dwCallback = 0;
mciSendCommand(mciOpen.wDeviceID, MCI_CLOSE, 0, (DWORD)&mciClose);

      
}

0
 
LVL 23

Expert Comment

by:chensu
ID: 1180657
Of course it is empty since you record just 0.0000001 milliseconds. You can use MCI_SET command (MCI_WAVE_SET_CHANNELS) to change the recording format.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1180658
DWORD is 32-bit integer. 0.0000001 for DWORD is zero.
0
 

Expert Comment

by:joedean
ID: 1180659
I want it to record until the user clicks STOP.  I guess I use a callback.  Anyone know they syntax?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

930 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now