C++ Code Samples

DirectSound

StreamData - Enhanced sample from the DirectX SDK.  Streams data in from a file to a DirectSound buffer.  Enhancements made to show how to do things the right way so you don't get stuttering.

StreamDataTone - Shows how to create your own non-file source for DirectSound.  This one uses a tone generator class.

StreamDataTone2 - More of the same, added saw, reverse raw, and triangle to the tone generator class.

StreamDataTone3 - Basic graphic interface to demonstrate switching of sources, frequency etc.  Accuracy of tone generator improved.

StreamDataToneSurround - Sample that generates and sends a different frequency tone to each audio channel

DirectSoundEnumerator - Find the wave device ID's for DirectSound GUID's using the IKsPropertySet interface obtained from the IClassFactory interface without creating a DirectSound buffer.  The calls themselves are not well documented, but are listed in the dsconf.h file.

Kernel Streaming

KS_IO - Kernel Streaming, ultra-low latency. Sends input to output via buffer.

DirectShow

DirectShow Audio Transform - The basics of a DirectShow audio transform filter. Use as a starting point for audio transform filters.

Legacy HD Audio Filter - DirectShow filter to convert from standard WAVEFORMATEX to WAVEFORMATEXTENSIBLE on demand. Filter is registered as MERIT_NORMAL so that graph builder will automatically insert it as required.

Encoding HD WAV/PCM to WMA - Walkthrough on how to compress PCM audio to WMA using the WM ASF Writer, includes sample code.

DirectShow Audio Channel Shifter v1.0 (32-bit binary) (64-bit binary) - Filter to redirect stereo playback through different channel outputs on a surround sound card. Supports up to a 7.1 configuration and will expose itself as 4 separate filters in DirectShow. Currently it's a full transform filter but I plan to make this a trans-in-place filter so as to eliminate the needless buffer copy.

 

Diagnostic Apps

Soundcard Test - Enumerate all sound cards and the audio modes they support or supported by Windows.

 

Useful Apps

Volume Tracker - Great for systems using Digital Audio Out, such as SP-DIF. With Digital Audio output, only the wave volume effects the output level, not the master volume. Yet multimedia keyboards and remote controls only adjust the master volume. This app tracks the wave volume to the master volume by monitoring changes to the mixer control. Works on 2000, XP and Windows Media Center. Note that it will not work correctly with Vista due to changes in the audio mixer architecture. When I figure out a way to make it work in Vista I will post it here.

Legacy HD Audio Filter - Many audio processing applications still produce high-definition audio such as 24bit/96kHz in a legacy WAV format. By default DirectShow players (such as Media Player) won't be able to play these files as the Audio Renderer refuses to accept this legacy type even though it is perfectly capable of playing it. This filter registers itself as being able to handle this legacy format, and at the same time converts to a format the DirectShow Audio Renderer will accept (WAVEFORMATEXTENSIBLE). This is done without altering the audio data in any way. Save the .ax file somewhere convenient on your system and register it from the command line with "regsvr32 AudioTypeConvert.ax".  Curious how this simple process works?  Download the source code.

 

Links

http://tmhare.mvps.org/  Home of TMH's DirectShow FAQ, directions on how to get further DirectShow help in the community newsgroups.

http://www.gdcl.co.uk/  Geraint Davies Consulting home page.  Geraint is a DirectShow god living in North Wales.  Many useful filters here including the GMFBridge multi-graph filter set.

http://www.riseoftheants.com/mmx/faq.htm  Alessandro is one of the DirectShow guru's that frequents the newsgroups. He has collected some of his notes here on various programming techniques including some tricks with DirectShow.

http://www.codeproject.com/  Many useful DirectShow projects in both C++ and C#.

http://www.headbands.com/gspot/  GSpot is a useful tool for validating media files and ensuring that a system has the codecs necessary to successfully render.

http://www.updatexp.com/sherlock-codec-detective.html  Mark Liron's Codec Detective will enumerate all the codecs on a system and validate that they are installed correctly.

http://www.applied-mathematics.net/  Dr. Ir. Frank Vanden Berghen has a small powerful C++ oriented XML Parser that I really like.
[Aladdin Free Public License(AFPL), other licenses are available on request.]