Basename: ?? please check the spelling for me! Title: HOWTO play and record sound Author: Thomas.Holme Email: thomas.holme@openmpeg4.org Environment: VC++ 6.0, win2k Keywords: mmsystem, sound, play, record Level: Beginner Description: Howto record and play sound Section Multimedia SubSection Audio

This is a simple application that show you how to play and record sound under windows.
It uses the old multimedia API. A better solution may be to use DirectSound.
Start with the two functions in CFisterDlg called OnPlay
and OnRecord. Follow them down to the depth you need to use the
classes.
CSoundIn is a wrapper class that will let you retreive sound
from the soundcard. Main functions is Start() and Stop()
CSoundOut
is a wrapper class that will let you play sound on the soundcard. Main
functions is Start() and Stop()
CSoundFile is a wrapper class
of a single wave file, it can either be a file reader or a file writer object.
See the constructor.
CSoundBase is a very small class that
encapsulate the wave format.
CBuffer is a very small class that
encapsulates a simple one dimentional buffer.
The project has a number of different callback functions:
- One callback function make the Play button change it's lable to stop when it has finished playing the file.
CDialogDlgenheritsCPipeand overload a function thatCPipecan call when it has finished playing the wave file.- Another callback function make it possible for
CSoundInto callback toCPipewhen it has filled the input buffer. ThusCPipecan giveCSoundIna new buffer to fill.- A clone of the above principle is also used in
CSoundOut, which enables it to callback to the owner when it is finished playing the sound in a given buffer.
I have spend almost 2 days debugging the following stupid problem. When CSoundIn
and CSoundOut inherit from CSoundBase and CWinThread
the order in which they are listed MUST be as shown below. If not the callback
functions, which are started by the WinThread message handler, will not be
able to access the member variables of the CSoundIn object.
class CSoundIn : public CWinThread, public CSoundBase
During these two days of fustration I also tried to implement the callback as regular callback functions called by the device driver. This is possible using ::waveInOpen(...). But since the this callback function is not allowed to call any of the ::waveInXXX(...) functions it is not of much use.