Solved

Recording Program

Posted on 1998-02-05
8
404 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

808 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