[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Recording Program

Posted on 1998-02-05
8
Medium Priority
?
416 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
[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
  • 4
  • 3
8 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 150 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
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!

 

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
 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

649 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