
CMMSystem
v1.02 A set of MFC classes encapsulating the Win32 Multimedia
APIs
Welcome to CMMSystem, a collection of MFC
classes to encapsulate some of the Win32 Multimedia APIs. Areas covered include
the waveOut, waveIn, mmio and mixer APIs
Ever since studying Audio Signal Processing in college,
I've always been interested in computer based audio. These classes are the results
of my investigations into base Win32 support for this area.
Features
- Provide auto clean up through
the use of C++ destructors.
- Works equally well in Unicode
as well as ASCII builds.
- Automatically links to the
Windows Multimedia library namely "WinMM.lib"
- The classes make use of
exceptions to report errors to help client code which is developed to be as robust as possible.
- Hides the complicated buffer
management issues which are involved in using the waveIn / waveOut APIs.
- Included in the download is a
number of sample projects to exercise the various classes. They are:
PlayWav is a simple console application which reads from any wav file using CMMIOFile and plays it back
using the CWaveOut class.
RecordWave is a simple console application which records to a wav file using CMMIOFile and CWaveIn
ShowInput which displays a simple frequency spectrum of the audio data
received via waveIn in
real-time in an AppWizard generated MFC SDI application. This program opens the
wave input using hard coded values of 16 bit mono at a sampling frequency
of 11025 hertz.
ModifyInput which is a console application which reads from a 16 bit mono wav file and increases the pitch
of the signal by performing some simple frequency shifting and filtering of the signal
using a Fast Fourier Transform (FFT) and inverse FFT. Hopefully what you
should hear if you use a sample of your own voice as input is your voice as
if you have just inhaled a balloon full of helium!!. To compile both ShowInput and ModifyInput, you
should obtain the FFT class from http://www.codeproject.com/audio/waveInFFT.asp
which both of my sample projects use to implement an FFT.
The classes which constitute CMMSystem are:
CMMIOFile: This class implements a very simple
wrapper for the "mmio..." functions. These functions provide for
reading and writing of RIFF files, which the common .wav file is one instance
of. Like all the classes in CMMSystem it is exception based and will throw an
MFC style "CMMIOException" exception when any errors occur. For an
example on how easy it is to use this class, check out the code for the PlayWav
and RecordWav sample projects included in the download.
CWaveOut: This implements a wrapper for the
"waveOut.." functions. This was the first class developed in CMMSystem
and was based on the great tutorial on audio input processing from David Overton
at http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4422&lngWId=3.
If you are new to audio processing on Windows, then I'd recommend you check out
this very good introduction. The class internally looks after all the details of
buffer management and provides a very simple Write method to send audio data to
it. Again any errors which occur in the class are reported as standard MFC
style "CWaveOutException" exceptions.
CWaveIn: This is the corollary class to
CWaveOut and provides support for recording audio data. Again the details of
buffer management is handled by the class and a simple Read method is provided to
obtain the recorded audio data. Any errors will cause an MFC style
"CWaveInException" exception to be thrown.
CMixer: The final class in CMMSystem, CMixer
provides a thin veneer over the very complicated area of the mixer APIs. I do
not claim to be any expert on this particular area and the wrapping provided is
very thin. Again any errors which occur internally will cause an MFC style
"CMixerException" to be thrown.
Copyright
- You are allowed to include the source code in
any product (commercial, shareware, freeware or otherwise) when your product
is released in binary form.
- You are allowed to modify the source code in
any way you want except you cannot modify the copyright details at the top
of each module.
- If you want to distribute source code with
your application, then you are only allowed to distribute versions released
by the author. This is to maintain a single distribution point for the
source code.
Updates
V1.0 (2 August 2005)
V1.01 (26 June 2006)
- Updated the documentation to use the same style as the web site.
- Made AfxThrow*Exception classes part of the their respective classes.
- Code now uses new C++ style casts rather than old style C casts where
necessary.
- Updated copyright details
- Inclusion of a CMMSYSTEM_EXT_CLASS preprocessor define to allow the
class to be easily used in an extension dll.
- Optimized most of the constructor methods
- Made CWaveIn::GetBuffersFilled thread safe
- Made CWaveOut::GetBuffersFree thread safe
- Made the first parameter to CWaveOut::Write a "const void*".
- Made the first parameter to CWaveIn::Read a "void*".
- Updated code to ensure it clean(ish) compiles on VC 2005.
V1.02 (19 March 2008)
- Updated copyright details
- Updated the sample apps to clean compile on VC 2008
- Remove VC 6 style classwizard style comments from sample apps
- All Sleep calls now use 0 as their parameter to specify that the rest of
the time slice should be waited for