logout
asked on
Recording and Play Wave file IN VC++4.0
Dear
I want to play and record wave file VC++4.0
What is the function call coding and paramters?
Thank You for help
I want to play and record wave file VC++4.0
What is the function call coding and paramters?
Thank You for help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The function is PlaySound implemented in winmm.dll which can be found in system directory. Corresponding lib file is winmm.lib that comes with windows SDK or VC++ or BC++.Header file needed is mmsystem.h which also comes with Windows SDK, VC++ or BC++ and can be found in include directory.
Recording sounds.
DWORD recordWAVEFile(DWORD dwMilliSeconds);
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 device with a new file for recording.
*/
mciOpenParms.lpstrDeviceTy pe = "waveaudio";
mciOpenParms.lpstrElementN ame = "";
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;
}
/* 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 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 = 0;
if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY,
MCI_FROM | MCI_WAIT,
(DWORD)(LPVOID) &mciPlayParms)) {
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return dwReturn;
}
HWND hMainWnd;
hMainWnd=hwnd;
if (MessageBox(hMainWnd, "Do you want to save this recording?",
"", MB_YESNO) == IDNO) {
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return 0;
}
/*
* Save the recording to a file named TEMPFILE.WAV. Wait for
* the operation to finish 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 0;
}
DWORD recordWAVEFile(DWORD dwMilliSeconds);
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 device with a new file for recording.
*/
mciOpenParms.lpstrDeviceTy
mciOpenParms.lpstrElementN
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;
}
/* 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 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 = 0;
if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY,
MCI_FROM | MCI_WAIT,
(DWORD)(LPVOID) &mciPlayParms)) {
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return dwReturn;
}
HWND hMainWnd;
hMainWnd=hwnd;
if (MessageBox(hMainWnd, "Do you want to save this recording?",
"", MB_YESNO) == IDNO) {
mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
return 0;
}
/*
* Save the recording to a file named TEMPFILE.WAV. Wait for
* the operation to finish 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 0;
}
ASKER
DWORD dwMilliSeconds is parameter.
Does that parameter need to assign a value
Does that parameter need to assign a value
What's the deference between mci function and wavein function?
ASKER
Which lib function need to be called?