Solved

Recording Program

Posted on 1998-02-05
8
400 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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 …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

776 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