We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 790 - FadeInChannel/FadeOutChannel can corrupt volume level.
Summary: FadeInChannel/FadeOutChannel can corrupt volume level.
Status: RESOLVED FIXED
Alias: None
Product: SDL_mixer
Classification: Unclassified
Component: misc (show other bugs)
Version: 1.2.8
Hardware: x86 All
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-09 11:17 UTC by Joe Keen
Modified: 2009-10-10 22:37 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Keen 2009-09-09 11:17:06 UTC
When Mix_FadeInChannel is called Mix_Channel.fade_volume is set to the current volume and Mix_Channel.volume is set to 0.  If Mix_FadeOutChannel is called prior to Mix_FadeInChannel finishing it sets Mix_Channel.fade_volume to the current volume rather than the desired volume for that channel.  When Mix_FadeOutChannel is finished it uses that fade_volume attribute to reset the volume on the channel.

The following program reproduces the problem.

#include <stdio.h>
#include <unistd.h>
#include <SDL/SDL_mixer.h>

bool done = false;

void channelFinished(int channel) {
    done = true;
}

int main() {
    Mix_OpenAudio(48000, MIX_DEFAULT_FORMAT, 2, 512);
    Mix_ChannelFinished(channelFinished);
    Mix_AllocateChannels(50);
    Mix_Volume(-1,MIX_MAX_VOLUME);

    Mix_Chunk *chunk = Mix_LoadWAV("/tmp/foo.wav");

    printf("volume start: %i\n",Mix_Volume(1,-1));

    Mix_FadeInChannel(1,chunk,-1,5000);
    sleep(1);
    Mix_FadeOutChannel(1,500);

    while(!done) {
        usleep(10);
    }

    printf("volume end:   %i\n",Mix_Volume(1,-1));
}
Comment 1 Sam Lantinga 2009-09-26 02:24:04 UTC
Ryan, can you take a look at this?

Thanks!
Comment 2 Ryan C. Gordon 2009-10-10 22:37:13 UTC
Fixed in svn revision #5047.

Please note that the channel's volume is changing during the fade, so if you call Mix_Volume(channel, -1) while the fade is progressing, you'll get changing values, but now the final volume is reset correctly at the end of the fade.

Also note that if you change the Mix_Volume() during the fade, it'll ignore this (next run of the audio callback changes it, end of the fade resets it). This is how it worked before this patch, too.

--ryan.