Article ID: 152180
Article Last Modified on 7/11/2005
//#include <mmsystem.h> at the beginning of the program.
//Link with mmsystem.lib for 16-bit code, or
//link with winmm.lib for 32-bit code.
MCI_WAVE_SET_PARMS set_parms;
MCI_OPEN_PARMS open_parms;
DWORD dwReturn;
UINT wave_device_id;
char buffer[128];
// Open the wave audio device.
open_parms.lpstrDeviceType = "waveaudio";
open_parms.lpstrElementName = "";
if (dwReturn = mciSendCommand( 0, MCI_OPEN, MCI_OPEN_TYPE |
MCI_OPEN_ELEMENT, (DWORD) (LPVOID) &open_parms))
{
mciGetErrorString(dwReturn, buffer, sizeof (buffer));
MessageBox( NULL, buffer, "MCI_OPEN",
MB_ICONEXCLAMATION | MB_OK);
}
else
{
MessageBox( NULL, "Open Succeeded", "MCI_OPEN",
MB_ICONEXCLAMATION | MB_OK);
}
// Note the wave audio device ID
wave_device_id = open_parms.wDeviceID;
// Set PCM format of recording.
set_parms.wFormatTag = WAVE_FORMAT_PCM;
set_parms.wBitsPerSample = 16;
set_parms.nChannels = 2;
set_parms.nSamplesPerSec = 44100;
set_parms.nAvgBytesPerSec = ((set_parms.wBitsPerSample)/8) *
set_parms.nChannels *
set_parms.nSamplesPerSec;
set_parms.nBlockAlign = ((set_parms.wBitsPerSample)/8) *
set_parms.nChannels;
if (dwReturn = mciSendCommand( wave_device_id, MCI_SET, MCI_WAIT |
MCI_WAVE_SET_FORMATTAG |
MCI_WAVE_SET_BITSPERSAMPLE |
MCI_WAVE_SET_CHANNELS |
MCI_WAVE_SET_SAMPLESPERSEC |
MCI_WAVE_SET_AVGBYTESPERSEC |
MCI_WAVE_SET_BLOCKALIGN,
(DWORD)(LPVOID)&set_parms))
{
mciGetErrorString(dwReturn, buffer, sizeof(buffer));
MessageBox( NULL, buffer, "MCI_SET",
MB_ICONEXCLAMATION | MB_OK);
}
else
{
MessageBox( NULL, "MCI_WAVE_SET Succeeded", "MCI_SET",
MB_ICONEXCLAMATION | MB_OK);
}
//Close the wave device.
if (dwReturn = mciSendCommand( wave_device_id, MCI_CLOSE,
(DWORD)NULL, (DWORD)NULL))
{
mciGetErrorString(dwReturn, buffer, sizeof (buffer));
MessageBox( NULL, buffer, "MCI_CLOSE",
MB_ICONEXCLAMATION | MB_OK);
}
else
{
MessageBox( NULL, "MCI_CLOSE Succeeded", "MCI_CLOSE",
MB_ICONEXCLAMATION | MB_OK);
}
// Set PCM format recording, Part 1.
set_parms.wFormatTag = WAVE_FORMAT_PCM;
set_parms.wBitsPerSample = 16;
set_parms.nChannels = 2;
set_parms.nBlockAlign = ((set_parms.wBitsPerSample)/8) *
set_parms.nChannels;
if (dwReturn = mciSendCommand( wave_device_id, MCI_SET, MCI_WAIT |
MCI_WAVE_SET_FORMATTAG |
MCI_WAVE_SET_BITSPERSAMPLE |
MCI_WAVE_SET_CHANNELS |
MCI_WAVE_SET_BLOCKALIGN,
(DWORD)(LPVOID)&set_parms))
{
mciGetErrorString(dwReturn, buffer, sizeof(buffer));
MessageBox( NULL, buffer, "MCI_WAVE_SET_1", MB_OK);
}
else
}
MessageBox( NULL, "MCI_WAVE_SET-1 Succeeded", "MCI_SET",
MB_OK);
}
// Set PCM format recording, Part 2.
set_parms.nSamplesPerSec = 44100;
set_parms.nAvgBytesPerSec = ((set_parms.wBitsPerSample)/8) *
set_parms.nChannels *
set_parms.nSamplesPerSec;
if (dwReturn = mciSendCommand( wave_device_id, MCI_SET, MCI_WAIT |
MCI_WAVE_SET_SAMPLESPERSEC |
MCI_WAVE_SET_AVGBYTESPERSEC,
(DWORD)(LPVOID)&set_parms))
{
mciGetErrorString(dwReturn, buffer, sizeof(buffer));
MessageBox( NULL, buffer, "MCI_WAVE_SET_2", MB_OK);
}
else
{
MessageBox( NULL, "MCI_WAVE_SET_2 Succeeded", "MCI_SET",
MB_OK);
}
Additional query words: kbsound 3.11 4.00
Keywords: kbmm KB152180