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

Free code!

Sign in to follow this  
Evil Steve

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


    4 Comments


    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.

    We are the game development community.

    Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

    Sign me up!