🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Free code!

posted in DruinkJournal
Published September 26, 2005
Advertisement
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.
So, as promised, you can download it from Here.

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.
  • Previous Entry Mew
    Next Entry Yay, Digital
    0 likes 4 comments

    Comments

    H_o_p_s
    Now only if I programmed in SDL/C++....
    September 26, 2005 01:57 PM
    Evil Steve
    Or even Win32/C++ :P
    September 26, 2005 01:58 PM
    Mushu
    SINGLETON ALERT!!!
    September 26, 2005 04:48 PM
    Evil Steve
    <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.
    September 26, 2005 05:50 PM
    You must log in to join the conversation.
    Don't have a GameDev.net account? Sign up!
    Advertisement
    Advertisement