FadeIn Effect for Music

Hello! I’m creating a game with Slick2D library, and I have a problem to calculate fadeIn effect for a volume of the music. Sadly, class Music has a fadeOut method fade(duration, endVolume, stopAfterFade), but does not contain and fadeIn.
So I want to increase volume from 0.0f to 1.0f in 3s.


if (gameContainer.isMusicOn()) {
    if (!music.playing()) {
        music.play(1.0f, 0.0f);
    }
    
    int fadeInDuration = 3000;
    if (startTime + fadeInDuration > gameContainer.getTime()) {
        float increaseVol = music.getVolume() + 0.1f;        
        music.setVolume(vol);
    }
}

I haven’t used the Slick audio fadeout. Did you try making the end volume higher than the beginning volume?

Manually changing volumes is tricky for a couple reasons:
(1) the amount that you change the volume can cause a click if it is too large,
(2) the amount that you can change the volume without a click may not uniform for the full range of the sound,
(3) the volume may only be allowed to change at buffer switchovers, limiting the number of times that the volume can be changed.

For my library, I wrote a volume changer/envelope tool that calculates and executes an incremental change once every frame. Probably overkill, though. I’m not clear what support TinySound has for volume changes.

From my use of TinySound, it seems to work fine with volume changes. Its actually a decent little library, I’ve just had some unfortunate issues with it. Fading with TinySound shouldn’t be a problem.

What version of Slick are you using? The one in this repository has a Music class with simply a “fade” method, which can be used to fade the music out or in.

I’m using the latest version from slick.ninjacave.com
Anyway guys, I made it…
Somehow, I confuse my self with the parameter called endVolume :o… so I thought that a method called “fade” with that parameter endVolume, works only for fadeOut… :stuck_out_tongue: