The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_mixer: loops and fade out don't play together
Aki Koskinen
Guest

I'm new to this list so first of hello to everybody.

I have a problem with SDL_mixer. When I play a sound with loops, say

// Set a channel finish callback
Mix_ChannelFinished(ChannelDone);

Mix_Chunk *sound = ... // sound chunk here
int channel = Mix_PlayChannel(-1, sound, 10);
// or
int channel = Mix_FadeInChannel(-1, sound, 10, 1000);

and later fade it out while it is still playing

Mix_FadeOutChannel(channel, 1000);

After the fade out is complete I get a call to the callback function
notifying that the channel has stopped playing. But if I now call the

int Mix_Playing(int which);

function for the channel that was used for playing it tells me that
there is still a sound playing (returns non-zero). I'm expecting it to
tell me that there is no sound playing on that channel i.e. the channel
is free (return zero).

I think this is because the /Mix_Playing/ function in addition to
checking the /playing/ member of the /_Mix_Channel/ struct also checks
the /looping/ member. And if I see it correctly the /looping/ member is
not set to zero when the fade out completes.

So am I misunderstanding something here about how things should work,
using the mixer library incorrectly or is there simply a little bug there?

- Aki -
SDL_mixer: loops and fade out don't play together
Aki Koskinen
Guest

Aki Koskinen wrote:
Quote:
I think this is because the /Mix_Playing/ function in addition to
checking the /playing/ member of the /_Mix_Channel/ struct also checks
the /looping/ member. And if I see it correctly the /looping/ member is
not set to zero when the fade out completes.

As I got no immediate response to this I went on and assumed that I'm
using the mixer library correctly and there is a bug. So I made a change
to mixer.c to about line 192 and added

mix_channel[i].looping = 0;

to the code that is executed when the fade out is completed. This seemed
to make the mixer behave as I was expecting.

The patch to mixer.c looks like this

--- SDL_mixer-1.2.8.orig/mixer.c 2007-07-21 09:37:59.000000000 +0300
+++ SDL_mixer-1.2.8/mixer.c 2008-07-30 18:23:21.000000000 +0300
@@ -186,6 +186,7 @@
if( ticks > mix_channel[i].fade_length ) {
if( mix_channel[i].fading == MIX_FADING_OUT ) {
mix_channel[i].playing = 0;
+ mix_channel[i].looping = 0;
mix_channel[i].expire = 0;
Mix_Volume(i, mix_channel[i].fade_volume); /* Restore the volume */
_Mix_channel_done_playing(i);

As can be seen I'm not using the latest svn version but mixer.c hasn't
changed that much from my version.

I would still like to hear a second opinion about all this.

Cheers,
- Aki -
SDL_mixer: loops and fade out don't play together
Aki Koskinen
Guest

Aki Koskinen wrote:
Quote:
Aki Koskinen wrote:
Quote:
I think this is because the /Mix_Playing/ function in addition to
checking the /playing/ member of the /_Mix_Channel/ struct also checks
the /looping/ member. And if I see it correctly the /looping/ member
is not set to zero when the fade out completes.

As I got no immediate response to this I went on and assumed that I'm
using the mixer library correctly and there is a bug. So I made a change
to mixer.c to about line 192 and added

mix_channel[i].looping = 0;

to the code that is executed when the fade out is completed. This seemed
to make the mixer behave as I was expecting.

The patch to mixer.c looks like this

I found out that the same problem is present also in a few other
locations in mixer.c. The current patch that I have is attached.

Quote:
I would still like to hear a second opinion about all this.

This still applies though.


- Aki -
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SDL_mixer-1.2.8-set_looping_to_zero.patch
Type: text/x-patch
Size: 1321 bytes
Desc: not available
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080804/f2688de5/attachment.bin>