Correctly reset channel volumes after a fade out interrupts a fade in.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 11 Oct 2009 05:29:55 +0000
changeset 443d842a759e68a
parent 442 884a700fb3ff
child 444 41b7df493dad
Correctly reset channel volumes after a fade out interrupts a fade in.

Fixes Bugzilla #790.
mixer.c
     1.1 --- a/mixer.c	Sun Oct 11 02:59:12 2009 +0000
     1.2 +++ b/mixer.c	Sun Oct 11 05:29:55 2009 +0000
     1.3 @@ -70,6 +70,7 @@
     1.4  	Uint32 start_time;
     1.5  	Mix_Fading fading;
     1.6  	int fade_volume;
     1.7 +	int fade_volume_reset;
     1.8  	Uint32 fade_length;
     1.9  	Uint32 ticks_fade;
    1.10  	effect_info *effects;
    1.11 @@ -212,7 +213,7 @@
    1.12  			} else if ( mix_channel[i].fading != MIX_NO_FADING ) {
    1.13  				Uint32 ticks = sdl_ticks - mix_channel[i].ticks_fade;
    1.14  				if( ticks > mix_channel[i].fade_length ) {
    1.15 -				    Mix_Volume(i, mix_channel[i].fade_volume); /* Restore the volume */
    1.16 +				    Mix_Volume(i, mix_channel[i].fade_volume_reset); /* Restore the volume */
    1.17  					if( mix_channel[i].fading == MIX_FADING_OUT ) {
    1.18  						mix_channel[i].playing = 0;
    1.19  						mix_channel[i].expire = 0;
    1.20 @@ -350,6 +351,7 @@
    1.21  		mix_channel[i].looping = 0;
    1.22  		mix_channel[i].volume = SDL_MIX_MAXVOLUME;
    1.23  		mix_channel[i].fade_volume = SDL_MIX_MAXVOLUME;
    1.24 +		mix_channel[i].fade_volume_reset = SDL_MIX_MAXVOLUME;
    1.25  		mix_channel[i].fading = MIX_NO_FADING;
    1.26  		mix_channel[i].tag = -1;
    1.27  		mix_channel[i].expire = 0;
    1.28 @@ -404,6 +406,7 @@
    1.29  			mix_channel[i].looping = 0;
    1.30  			mix_channel[i].volume = SDL_MIX_MAXVOLUME;
    1.31  			mix_channel[i].fade_volume = SDL_MIX_MAXVOLUME;
    1.32 +			mix_channel[i].fade_volume_reset = SDL_MIX_MAXVOLUME;
    1.33  			mix_channel[i].fading = MIX_NO_FADING;
    1.34  			mix_channel[i].tag = -1;
    1.35  			mix_channel[i].expire = 0;
    1.36 @@ -826,6 +829,11 @@
    1.37  			mix_channel[which].fade_length = (Uint32)ms;
    1.38  			mix_channel[which].start_time = mix_channel[which].ticks_fade = sdl_ticks;
    1.39  			mix_channel[which].expire = (ticks > 0) ? (sdl_ticks+ticks) : 0;
    1.40 +
    1.41 +			/* only change fade_volume_reset if we're not fading. */
    1.42 +			if (mix_channel[which].fading == MIX_NO_FADING) {
    1.43 +				mix_channel[which].fade_volume_reset = mix_channel[which].volume;
    1.44 +			}
    1.45  		}
    1.46  	}
    1.47  	SDL_UnlockAudio();
    1.48 @@ -889,7 +897,7 @@
    1.49  		}
    1.50  		mix_channel[which].expire = 0;
    1.51  		if(mix_channel[which].fading != MIX_NO_FADING) /* Restore volume */
    1.52 -			mix_channel[which].volume = mix_channel[which].fade_volume;
    1.53 +			mix_channel[which].volume = mix_channel[which].fade_volume_reset;
    1.54  		mix_channel[which].fading = MIX_NO_FADING;
    1.55  		SDL_UnlockAudio();
    1.56  	}
    1.57 @@ -927,11 +935,15 @@
    1.58  			if ( mix_channel[which].playing && 
    1.59  			    (mix_channel[which].volume > 0) &&
    1.60  			    (mix_channel[which].fading != MIX_FADING_OUT) ) {
    1.61 -
    1.62 +				mix_channel[which].fade_volume = mix_channel[which].volume;
    1.63  				mix_channel[which].fading = MIX_FADING_OUT;
    1.64 -				mix_channel[which].fade_volume = mix_channel[which].volume;
    1.65  				mix_channel[which].fade_length = ms;
    1.66  				mix_channel[which].ticks_fade = SDL_GetTicks();
    1.67 +
    1.68 +				/* only change fade_volume_reset if we're not fading. */
    1.69 +				if (mix_channel[which].fading == MIX_NO_FADING) {
    1.70 +				    mix_channel[which].fade_volume_reset = mix_channel[which].volume;
    1.71 +				}
    1.72  				++status;
    1.73  			}
    1.74  			SDL_UnlockAudio();