diff options
author | MrCdK <contact@mrcdk.com> | 2017-12-17 22:30:28 +0100 |
---|---|---|
committer | MrCdK <contact@mrcdk.com> | 2017-12-17 22:30:28 +0100 |
commit | 1ccfb01cbc78a6678178a27514e8fd78b3b47163 (patch) | |
tree | 4b9c06bd851771c37984d0d3fbcfb4fcf98052d0 /modules/stb_vorbis | |
parent | 1ef123c57db0ab5f6395dd5e206234b0ed03f7b6 (diff) | |
download | redot-engine-1ccfb01cbc78a6678178a27514e8fd78b3b47163.tar.gz |
Fix ogg looping pop noise. Closes #11468
Diffstat (limited to 'modules/stb_vorbis')
-rw-r--r-- | modules/stb_vorbis/audio_stream_ogg_vorbis.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 5c252bda86..6f5bbba8d1 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -42,12 +42,17 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra int todo = p_frames; - while (todo && active) { + int start_buffer = 0; - int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, (float *)p_buffer, todo * 2); + while (todo && active) { + float *buffer = (float *)p_buffer; + if (start_buffer > 0) { + buffer = (buffer + start_buffer * 2); + } + int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, buffer, todo * 2); if (vorbis_stream->channels == 1 && mixed > 0) { //mix mono to stereo - for (int i = 0; i < mixed; i++) { + for (int i = start_buffer; i < mixed; i++) { p_buffer[i].r = p_buffer[i].l; } } @@ -60,11 +65,14 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra //loop seek(vorbis_stream->loop_offset); loops++; + // we still have buffer to fill, start from this element in the next iteration. + start_buffer = p_frames - todo; } else { - for (int i = mixed; i < p_frames; i++) { + for (int i = p_frames - todo; i < p_frames; i++) { p_buffer[i] = AudioFrame(0, 0); } active = false; + todo = 0; } } } |