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

Author Topic: [SOLVED] Crossfade between music  (Read 4655 times)

0 Members and 2 Guests are viewing this topic.

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
[SOLVED] Crossfade between music
« on: March 07, 2015, 04:51:41 pm »
Hi, what would be the best way to implement crossfading between two instances of sf::Music - or is there a library based on SFML which provides such stuff - as Thor does for other purposes?

My basic idea would be: having two instances of sf::Music. One holds the current track, the other the new track. Then fading can be done by changing the music's volume per frame. So the current music fades out by decreasing volume and the new music fades in by increasing music. After fading, the old instance (which played the previous track) will be used as "fade-in"-instance when fading again - and vice versa.

Of course, this change might be linear or not, depending on the desired result. But would this be the most suitable way?

Kind regards
Glocke
« Last Edit: March 07, 2015, 07:13:19 pm by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Crossfade between music
« Reply #1 on: March 07, 2015, 07:03:35 pm »
To fade a music you need to change its volume. And the only way to change the volume with sf::Music is with its setVolume function. So... I don't think there is any other implementation than the one you describe ;)
Laurent Gomila - SFML developer

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Crossfade between music
« Reply #2 on: March 07, 2015, 07:12:24 pm »
To fade a music you need to change its volume. And the only way to change the volume with sf::Music is with its setVolume function. So... I don't think there is any other implementation than the one you describe ;)

It's alway good to know whether I'm on the right path or not. Thank you!

If anyone is interested: My implementation is introduced here (including github link).
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

 

anything