Skip to content

Commit

Permalink
music_flac.c, music.ogg.c: add support for play count when looping
Browse files Browse the repository at this point in the history
Michael Day / https://bugzilla.libsdl.org/show_bug.cgi?id=4876 :

When looping using loop points specified by LOOP* metadata tags,
the looping logic should be affected by the user-specified play
count value. The patch here applies uniform looping logic to both
music_ogg.c and music_flac.c. Also, when the play count is 1, we
want to play the audio file straight through without any looping.
(This is not currently how the looping logic behaves.)
  • Loading branch information
sezero committed Nov 26, 2019
1 parent 065b28a commit 7462431
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/codecs/music_flac.c
Expand Up @@ -339,7 +339,8 @@ static FLAC__StreamDecoderWriteStatus flac_write_music_cb(
}
amount = frame->header.blocksize * channels * sizeof(*data);
music->pcm_pos += frame->header.blocksize;
if ((music->loop == 1) && (music->pcm_pos >= music->loop_end)) {
if ((music->loop == 1) && (music->play_count != 1) &&
(music->pcm_pos >= music->loop_end)) {
amount -= (music->pcm_pos - music->loop_end) * channels * sizeof(*data);
music->loop_flag = SDL_TRUE;
}
Expand Down Expand Up @@ -609,6 +610,11 @@ static int FLAC_GetSome(void *context, void *data, int bytes, SDL_bool *done)
flac.FLAC__stream_decoder_flush(music->flac_decoder);
return -1;
} else {
int play_count = -1;
if (music->play_count > 0) {
play_count = (music->play_count - 1);
}
music->play_count = play_count;
music->loop_flag = SDL_FALSE;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/codecs/music_ogg.c
Expand Up @@ -401,7 +401,7 @@ static int OGG_GetSome(void *context, void *data, int bytes, SDL_bool *done)
}

pcmPos = vorbis.ov_pcm_tell(&music->vf);
if ((music->loop == 1) && (music->play_count != 0) && (pcmPos >= music->loop_end)) {
if ((music->loop == 1) && (music->play_count != 1) && (pcmPos >= music->loop_end)) {
amount -= (int)((pcmPos - music->loop_end) * music->vi.channels) * (int)sizeof(Sint16);
result = vorbis.ov_pcm_seek(&music->vf, music->loop_start);
if (result < 0) {
Expand Down

0 comments on commit 7462431

Please sign in to comment.