Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Free code!

Sign in to follow this  
Evil Steve


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
Where m_hWnd is the handle to your applications window. Shutting down is even easier:

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().

  • 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.
  • Sign in to follow this  


    Recommended Comments

    <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.

    Share this comment

    Link to comment

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Advertisement

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

    Sign me up!