SFML community forums

Help => Audio => Topic started by: Glocke on March 07, 2015, 04:51:41 pm

Title: [SOLVED] Crossfade between music
Post by: Glocke 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
Title: Re: Crossfade between music
Post by: Laurent 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 ;)
Title: Re: Crossfade between music
Post by: Glocke 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 (http://en.sfml-dev.org/forums/index.php?topic=17191.msg127009#msg127009) (including github link).