Introduction (back to top)This class is a "spin off" of the CGTetris application. The CDirectSound class makes it easy to play a WAVE file directly from the resource (without copying it into a temporary file) via Microsoft's DirectX component DirectSound. The class is designed to play small sounds, that can be placed completely into memory. No streaming is realized in this implementation. One can use the class to play WAVE files, too. In this case you have to load the entire file into memory and to pass the pointer to the beginning of the buffer to the Create() method. To use this class you need at least DirectX version 3.
Public Interface (back to top)// create the sound object. You cannot use a MIDI object until
// you "Create()" one!
BOOL Create(LPVOID pSoundData, DWORD dwSize, CWnd * pParent = 0);
BOOL Create(LPCTSTR pszResID, CWnd * pParent = 0);
BOOL Create(UINT uResID, CWnd * pParent = 0);
// Play the sound file. Normally the playback
will stop after
// the sound played off.
BOOL Play(DWORD dwStartPosition = 0, BOOL bInfinite = FALSE);
// Enable/disable the sound object. If you
call Play() on a
// disabled sound object, nothing will happen. This makes
// it somewhat easier to globally switch off sounds in an
BOOL EnableSound(BOOL bEnable = TRUE);
BOOL IsEnabled() const;
Usage (back to top)The source consists of 2 files:
Add a WAVE resource into your application (from the Menu Insert->Resource->import->*.wav).
"Create()" your CDirectSound (derived) object giving it the resource-id of your WAVE resource. Now you can call Play(), Pause(), Stop() etc.