There are no examples of recording sounds from the standard microphone input because it doesn't work very logically. The following works (sort of)
According to the Borland web site, Delphi 5 contains a design error in the MPlayer unit - Open fails for Wave Audio. So I downloaded Upgrade 1 (26 megs). Well, that was a waste of time.
Old mplayer.dcu 9-11-99 New mplayer.dcu 1-24-00
Yes, it records if a file name is provided when Open is called, but it only saves to a temporary file (ie, you can not write over the open file). If you assign a new filename before saving, the save is ok. However, you can not record a new wave file (which is of course what I want). Thus, this upgrade did NOT fix the problem.
According to the Windows SDK, the mciSendCommand requires a different structure when opening the Wave Audio device - it requires a parameter which specifies how many seconds to record.
tagMCI_OPEN_PARMSA = record dwCallback: DWORD; wDeviceID: MCIDEVICEID; lpstrDeviceType: PAnsiChar; lpstrElementName: PAnsiChar; lpstrAlias: PAnsiChar; end;
tagMCI_WAVE_OPEN_PARMSA = record dwCallback: DWORD; wDeviceID: MCIDEVICEID; lpstrDeviceType: PAnsiChar; lpstrElementName: PAnsiChar; lpstrAlias: PAnsiChar; dwBufferSeconds: DWORD; end;
Basic Windows API functions and related help (Help / Windows SDK)
First, based on TI1427D, in order to create a new recording, both MCI_OPEN_ELEMENT and mci_Open_Type must be set when MCI_OPEN is called. However, MCI_OPEN_ELEMENT is set only when a file name is given.
Equally important, there is no way to set the recording parameters
In fact the MCI_SET command is only used twice in TMediaPlayer, and neither of those includes an MCI_WAVE_SET_PARMS structure.
- Number of bits per sample - 8 or 16
- Samples per second - 11K, 22k, 44k
- Number of channels - 1 or 2 (mono or stereo)
Based on a search of the VCL source for "WaveFormat" and "WAVE_SET", none of the supplied Delphi components support wave recording.
uses mmsystem; // required for PlaySound procedure TForm1.Button1Click(Sender: TObject); begin PlaySound('C:\WINDOWS\Media\ding.wav', 0, 0); end;
PlaySound('C:\WINDOWS\Media\ding.wav', 0, SND_LOOP + SND_ASYNC); // loop forever PlaySound(nil, 0, 0); // stop the current sound
PlaySound("C:\\WINDOWS\\MEDIA\\Chord.wav", NULL, SND_SYNC);See Recording Waveform Audio for information on the wavein commands. These let you set all the necessary parameters and supply buffers. This API looks useful when your final product is not a .wav file. (Use the MCI API for that.)
Specifically - mciSendCommand, sndPlaySound, PlaySound Generically - mci, midi, joystick, mixer, waveIn, waveOut and various related functions