MultiMedia

How do you record sound from your sound card?

Visual Basic | Delphi | C++ Builder | Windows API | References

Visual Basic 6.0

Right click the Toolbox and select Components...
Under Controls, you can selct Under Insertable Objects, you can selct


Delphi

Delphi 5 - There are no components which support recording sounds.

There are no examples of recording sounds from the standard microphone input because it doesn't work very logically. The following works (sort of)

But MediaPlayer1.Save erases the file, and the program won't run again (because the format information was lost).

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;
The MPlayer unit (\Program Files\Borland\Delphi5\Source\Vcl\mplayer.pas) references the MMSystem unit (\Program Files\Borland\Delphi5\Source\Rtl\Win\mmsystem.pas) which encapsulates the Windows API (mmsystem.h -> winmm.dll).

Basic Windows API functions and related help (Help / Windows SDK)


Solution

Well, based on lots of reading, I now know why TMediaPlayer is unable to record a new Wave Audio File.
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.

Based on a search of the VCL source for "WaveFormat" and "WAVE_SET", none of the supplied Delphi components support wave recording.


References


Playing Sounds

This works


C++ Builder

This should have the same interface as Delphi, except that the syntax is different.


Windows API

See Waveform Audio and Waveform Audio Reference
  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.)

winmm.dll implements

   Specifically - mciSendCommand, sndPlaySound, PlaySound
   Generically  - mci, midi, joystick, mixer, waveIn, waveOut
                   and various related functions


References


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / MultiMedia.htm