Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Recycle Sound Players Using Callback  (Read 1844 times)

0 Members and 1 Guest are viewing this topic.

polymesh

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Portfolio of Shaun Graham
Recycle Sound Players Using Callback
« on: March 03, 2014, 10:10:57 pm »
Hi! I am new to SFML. My only audio experience to this point is OpenSL ES on Android. I am trying to convert over my OpenSL ES code to use SFML-audio and just ran into a hiccup.

The way I am playing sounds currently is by keeping a pool of sound players, where when a player is finished it marks itself as available so it can be "recycled." I saw in another post on these forums that we should be recycling Sound players in SFML as well because of the internal limit. However the hiccup comes when there is no callback ability on the sf::sound object.

So how do most people recycle their sound players without a callback? Do you call a function after every frame or some interval to see what sounds are finished playing? That seems pretty wasteful, but looks like the only workaround as far as I can tell aside from modifying the SFML code to add callbacks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Recycle Sound Players Using Callback
« Reply #1 on: March 03, 2014, 11:49:24 pm »
Why would you want to recycle sounds as soon as they are finished? Just pick a finished sound when you need one.

for each (sound)
{
    if (sound->getStatus() == sf::Sound::Stopped)
    {
        recycle sound...
    }
}
Laurent Gomila - SFML developer

polymesh

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Portfolio of Shaun Graham
Re: Recycle Sound Players Using Callback
« Reply #2 on: March 04, 2014, 12:09:04 am »
That is certainly better than my workaround because it only runs once when a new sound needs to play.

I still think a callback would be better to put things in constant time, but this solution works for me because the number of players will not be too ridiculous in my case, neither should the number of sounds played simultaneously. So the fact that this solution deals in linear time is a non-issue, at least in this case.

Thanks Laurent!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Recycle Sound Players Using Callback
« Reply #3 on: March 04, 2014, 07:50:50 am »
OpenAL doesn't provide such callbacks, nor any way to implement them efficiently. This is something that I miss too. The only solution would be to have a dedicated thread that polls the sounds' status at a high rate -- definitely not the best thing to do.

Linear or constant time... I don't think this is a big deal, since you don't do anything other than reading the status. Even with millions of sounds this would not be a problem performance-wise ;)
Laurent Gomila - SFML developer

 

anything