This is a simple application that shows you how to play and record sound
It uses the old multimedia API. A better solution may be to
Quick Guide to the Code
Start with the two functions in
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. The main functions are
CSoundOut is a wrapper class that will let you play sound on the
soundcard. The main functions are
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
CBuffer is a very small class that encapsulates a simple one
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.
and overloads a function that
CPipe can call when it has
finished playing the wave file.
- Another callback function make it possible for
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
enables it to callback to the owner when it is finished playing the sound in a
Problems that I encountered
I have spent almost 2 days debugging the following stupid problem. When
CSoundOut inherit from
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
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