• entries
557
1237
• views
423619

# Free code!

157 views

I finally "finished" my sound manager code. It could probably do with some tweaking, but I haven't had the need yet. I'll upload a new version if I find cause to change anything much in it.

And now for the documentation. To initialize it, call
CSoundManager::Get().Init(m_hWnd);
Where m_hWnd is the handle to your applications window. Shutting down is even easier:
CSoundManager::Get().Shutdown();

And, the main bit - playing sound/music:
// Load some music //CSoundBuffer* pMusic = CSoundManager::Get().LoadOgg("Music.ogg");if(pMusic) pMusic->Play(true); // Play looping// Load a sound effect //CSoundBuffer* pSFX = CSoundManager::Get().LoadOgg("Sound.ogg");if(pSFX) pSFX->Play(false); // Play non-looping

That's it. If the sound file is under 3 seconds long, it'll be loaded as a static sound (uploaded to the sound card, and only read from the file once). The sound manager is threaded, so it'll happily play the sound while you leave it to it. When the music comes the end, it'll start from the start again. When the sound reaches the end, it'll stop.
To free the sound and music, call CSoundBuffer::Release().

Notes:
• You'll probably want to define NO_RESOURCE_MANAGER, and a DebugLog() function, as described in SoundManager.h.
• You need the ogg vorbis SDK installed to compile the source
• You can derive your own CSoundStream class, and pass that to CSoundBuffer::SetSource() to provide a new source to a sound buffer (so you can provide support for .WAV, .MP3, or any of your own formats, or even make a synthesizer or something).
• You can use CSoundManager::AllocateBuffer() instead of CSoundManager::LoadOgg() if you just want to create a buffer and assign a source to it later
• You can play, pause, and stop sound buffers with the appropritate functions
• Look through SoundManager.h for function reference

Do whatever the hell you want with the code, I don't care. If it doesn't work for you, tough. Post a comment here and I'll see if I can help, but I'm not promising anything. The code is also not very well tested, but it seems stable enough.

Anyway, that'll do. Have fun.

Now only if I programmed in SDL/C++....

Or even Win32/C++ :P

<3 singletons. My CD3DDevice class is also a singleton. And my CResourceManager. Yay!

I know that singletons can be used as an excuse for globals, but it makes sense in this situation.

## Create an account

Register a new account