Solved

Recording Program

Posted on 1998-02-05
8
394 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
Comment Utility
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
Comment Utility
How to assign the  dwMilliSeconds?
 dwMilliSeconds=1000 //(1000 HZ)  
0
 
LVL 23

Expert Comment

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

Author Comment

by:nba
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:nba
Comment Utility
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
Comment Utility
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
Comment Utility
DWORD is 32-bit integer. 0.0000001 for DWORD is zero.
0
 

Expert Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 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