SND_startPlay_4PCM_ENV bug, starting a new song, both play

SGDK only sub forum

Moderator: Stef

Post Reply
cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

SND_startPlay_4PCM_ENV bug, starting a new song, both play

Post by cero » Wed Sep 13, 2017 12:09 pm

SND_startPlay_4PCM_ENV docs say that if a sample is already playing on that channel, it is stopped and the new one started.

This doesn't happen. Both samples keep playing.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SND_startPlay_4PCM_ENV bug, starting a new song, both play

Post by Stef » Wed Sep 13, 2017 1:16 pm

No way to get 2 samples playing on the same channel :p
I guess you used it wrongly, can you provide the source code ?

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: SND_startPlay_4PCM_ENV bug, starting a new song, both play

Post by cero » Wed Sep 13, 2017 5:42 pm

Not complete source, but the important bits.

// Called on the title screen
SND_startPlay_4PCM_ENV(title_music, sizeof(title_music), 0, 1);

// Called in-game
SND_startPlay_4PCM_ENV(game_music, sizeof(game_music), 0, 1);

As you see, both are on channel 0 and looping. Imagine my surprise when both songs continued to play in-game.

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: SND_startPlay_4PCM_ENV bug, starting a new song, both play

Post by cero » Wed Sep 13, 2017 5:47 pm

And I see this is the guilty source in sound.c:

Code: Select all

void SND_startPlay_4PCM_ENV(const u8 *sample, const u32 len, const u16 channel, const u8 loop)
...
    // auto channel ?
    if (channel == SOUND_PCM_CH_AUTO)
    {
        // scan for first free channel
        ch = 0;

        while ((ch < 4) && (status & (Z80_DRV_STAT_PLAYING << ch))) ch++;

        // if all channel busy we use the first
        if (ch == 4) ch = 0;
    }
SOUND_PCM_CH_AUTO is 0, the same as channel 0.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SND_startPlay_4PCM_ENV bug, starting a new song, both play

Post by Stef » Wed Sep 13, 2017 6:06 pm

Outch ! that hurts ! What a stupid bug, i should have put auto to -1 of 0xFF..
Ok ^^ I will fix that quickly, thanks for reporting !

Post Reply