SFML community forums
Help => Audio => Topic started by: adge on March 12, 2018, 04:07:21 pm
-
Hi there,
I am currently adding sounds to my game. It's a city building game so naturally there are a lot of sound emitting entities. I read that there is a limit of 256 sounds that should never be acceeded.
Does this limit refer to the number of instances of the sf::Sound class or the number of instances where a sound is actually playing? (Same for the sf::Music of course). Furthermore, I guess that this limit is related to multithreading. Hence I'd be interested when the thread playing the sound is created. (Just out of curiosity ;))
Thanks!
-
One approach to this is to have a set number of sf::Sound instances and then use and re-use them as necessary. This means that the sf::Sounds act as "voices" and whenever you start a new sound, you can use any sf::Sound that isn't currently in use. Consider how many things that will be actually playing at once and find your maximum. Do you really need over 200 things playing simultaneously?
A simple implementation of this can be found here: https://github.com/Hapaxia/SfmlSoundSystem
Also, as far as I'm aware, the thread is created when the sound is started/played.
-
I read that there is a limit of 256 sounds that should never be acceeded.
The "256" limit is an implementation detail of OpenAL-Soft, and might depend on the OS. So, for any detail about it, you should rather search there.
Does this limit refer to the number of instances of the sf::Sound class or the number of instances where a sound is actually playing?
It refers to the number of sf::Sound and sf::SoundStream (and derived classes) instanciated.
Furthermore, I guess that this limit is related to multithreading
I think it's rather related to the audio muxer. OpenAL-Soft uses a single thread, so there's no real multithreading.
Hence I'd be interested when the thread playing the sound is created
I have no idea; again, it happens inside OpenAL-Soft.
-
Ok thanks a lot guys! Hope I can present my game to you at some point next year... Also great work with the C++ 11 support (I know its a while ago now but still worth a mention)