SFML community forums
Help => Audio => Topic started by: gyscos on July 01, 2012, 11:29:58 am
-
Hey there :)
I'm considering using SFML audio classes to handle sounds and music in a game. I have a few questions about this.
- I want to play a music, and automatically starts a new music when this one is done. Is there a way to know when the streamed music is about to end ? Like a callback or something ?
- I want to play a sound everytime someone shoots. So one SoundBuffer for all of them, but how do I dynamically create the Sound objects ? Do I need to keep a list of all active sounds, and delete them when they're finished ? Is there some auto-delete flag ?
All I really want is the ability to chain musics, and to starts sounds at anytime, without knowing in advance how many Sound object I will need.
I'm not decided on a version yet, so I'll probably go with 2.0 if nothing's wrong with it.
Thanks :)
-
Is there a way to know when the streamed music is about to end ? Like a callback or something ?
No, sorry.
I want to play a sound everytime someone shoots. So one SoundBuffer for all of them, but how do I dynamically create the Sound objects ? Do I need to keep a list of all active sounds, and delete them when they're finished ? Is there some auto-delete flag ?
No auto-delete flag, you have to manage their lifetime yourself.
I'm not decided on a version yet, so I'll probably go with 2.0 if nothing's wrong with it.
Yeah, don't choose SFML 1.6, it's already outdated.
-
I recommend to have a std::queue<sf::Sound>. If you play a sound, you push a sf::Sound object to the queue and play it. In regular intervals you check if the sounds at the front of the queue have stopped and pop them.
By the way, I plan to implement a sound player in Thor 2.1, but I still have a lot to do before.
-
- I want to play a music, and automatically starts a new music when this one is done. Is there a way to know when the streamed music is about to end ? Like a callback or something ?
I think you'd have to periodically (perhaps at the end of your main loop, or in other thread) checking to see that the music is still playing.
- I want to play a sound everytime someone shoots. So one SoundBuffer for all of them, but how do I dynamically create the Sound objects ? Do I need to keep a list of all active sounds, and delete them when they're finished ? Is there some auto-delete flag ?
In order to avoid having to check if a sound is finished, I used a boost::circular_buffer rather than a queue as Nexus recommended. It does mean that sounds may be cut off occasionally, and it limits how many sounds you can play at once, but depending on your needs it may be sufficient. If you expect to have more then ten or twenty sounds simultaneously, though, it's probably more space-efficient to go with a non-fixed-size container like the queue.
-
Ok, thanks...
Sounds a bit complicated :-S
I don't really have an explicit event loop. I guess I'll stick with Phonon for now :(