Introduction
This is a simple application that shows you how to play and record sound
under windows.
It uses the old multimedia API. A better solution may be to
use DirectSound.
Quick Guide to the Code
Start with the two functions in CFisterDlg
called
OnPlay
and OnRecord
. Follow them down to the depth you
need to use the classes.
Short description
CSoundIn
is a wrapper class that will let you retreive sound
from the soundcard. The main functions are Start()
and
Stop()
CSoundOut
is a wrapper class that will let you play sound on the
soundcard. The main functions are 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 encapsulates 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 makes the Play button change it's label to stop when
it has finished playing the file.
CDialogDlg
enherits CPipe
and overloads a function that CPipe
can call when it has
finished playing the wave file.
- Another callback function make it possible for
CSoundIn
to
callback to CPipe
when it has filled the input buffer. Thus
CPipe
can give CSoundIn
a 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.
Problems that I encountered
I have spent 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 this callback function is not allowed
to call any of the ::waveInXXX(...)
functions it is not of much
use.