Skip to content

Commit

Permalink
fix ogg decoding adds silence at end
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Jan 19, 2024
1 parent 969d59f commit 20c2d70
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/SDL_sound_vorbis.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,23 @@ static Uint32 VORBIS_read(Sound_Sample *sample)
Uint32 retval;
int rc;
int err;
int delta;
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
stb_vorbis *stb = (stb_vorbis *) internal->decoder_private;
const int channels = (int) sample->actual.channels;
const int want_samples = (int) (internal->buffer_size / sizeof (float));
const int offset = stb_vorbis_get_playback_sample_offset(stb);

delta = internal->total_length - offset;

stb_vorbis_get_error(stb); /* clear any error state */
rc = stb_vorbis_get_samples_float_interleaved(stb, channels, (float *) internal->buffer, want_samples);
retval = (Uint32) (rc * channels * sizeof (float)); /* rc == number of sample frames read */
if(delta > 0 && delta < rc) {
retval = (Uint32) (delta * channels * sizeof (float)); /* prevents bug in stb_vorbis */
} else {
retval = (Uint32) (rc * channels * sizeof (float)); /* rc == number of sample frames read */
}

err = stb_vorbis_get_error(stb);

if (retval == 0)
Expand Down

0 comments on commit 20c2d70

Please sign in to comment.