diff options
author | Juan Linietsky <reduzio@gmail.com> | 2021-08-27 15:38:20 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-27 15:38:20 -0300 |
commit | 54caaa21ce427ac3b240d5b514dc339fd8e13204 (patch) | |
tree | fc2bfcdf0c1cc8fc8fd66e9bf68c1b74b006b4f9 /modules | |
parent | 87f575efddf503297e056f169cfd8a68dbe859c5 (diff) | |
parent | 3598d300cb43797a4f18b34d921875d060ce7de7 (diff) |
Merge pull request #51296 from ellenhp/mix_in_audio_server
Move mixing out of the AudioStreamPlayback* nodes
Diffstat (limited to 'modules')
-rw-r--r-- | modules/minimp3/audio_stream_mp3.cpp | 8 | ||||
-rw-r--r-- | modules/minimp3/audio_stream_mp3.h | 2 | ||||
-rw-r--r-- | modules/stb_vorbis/audio_stream_ogg_vorbis.cpp | 8 | ||||
-rw-r--r-- | modules/stb_vorbis/audio_stream_ogg_vorbis.h | 2 |
4 files changed, 14 insertions, 6 deletions
diff --git a/modules/minimp3/audio_stream_mp3.cpp b/modules/minimp3/audio_stream_mp3.cpp index 2cc974322d..fb741f6266 100644 --- a/modules/minimp3/audio_stream_mp3.cpp +++ b/modules/minimp3/audio_stream_mp3.cpp @@ -37,11 +37,13 @@ #include "core/io/file_access.h" -void AudioStreamPlaybackMP3::_mix_internal(AudioFrame *p_buffer, int p_frames) { - ERR_FAIL_COND(!active); +int AudioStreamPlaybackMP3::_mix_internal(AudioFrame *p_buffer, int p_frames) { + ERR_FAIL_COND_V(!active, 0); int todo = p_frames; + int frames_mixed_this_step = p_frames; + while (todo && active) { mp3dec_frame_info_t frame_info; mp3d_sample_t *buf_frame = nullptr; @@ -60,6 +62,7 @@ void AudioStreamPlaybackMP3::_mix_internal(AudioFrame *p_buffer, int p_frames) { seek(mp3_stream->loop_offset); loops++; } else { + frames_mixed_this_step = p_frames - todo; //fill remainder with silence for (int i = p_frames - todo; i < p_frames; i++) { p_buffer[i] = AudioFrame(0, 0); @@ -69,6 +72,7 @@ void AudioStreamPlaybackMP3::_mix_internal(AudioFrame *p_buffer, int p_frames) { } } } + return frames_mixed_this_step; } float AudioStreamPlaybackMP3::get_stream_sampling_rate() { diff --git a/modules/minimp3/audio_stream_mp3.h b/modules/minimp3/audio_stream_mp3.h index ce001fc418..5dd88779f8 100644 --- a/modules/minimp3/audio_stream_mp3.h +++ b/modules/minimp3/audio_stream_mp3.h @@ -51,7 +51,7 @@ class AudioStreamPlaybackMP3 : public AudioStreamPlaybackResampled { Ref<AudioStreamMP3> mp3_stream; protected: - virtual void _mix_internal(AudioFrame *p_buffer, int p_frames) override; + virtual int _mix_internal(AudioFrame *p_buffer, int p_frames) override; virtual float get_stream_sampling_rate() override; public: diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 768b419348..3a938200e9 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -32,13 +32,15 @@ #include "core/io/file_access.h" -void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) { - ERR_FAIL_COND(!active); +int AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) { + ERR_FAIL_COND_V(!active, 0); int todo = p_frames; int start_buffer = 0; + int frames_mixed_this_step = p_frames; + while (todo && active) { float *buffer = (float *)p_buffer; if (start_buffer > 0) { @@ -64,6 +66,7 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra // we still have buffer to fill, start from this element in the next iteration. start_buffer = p_frames - todo; } else { + frames_mixed_this_step = p_frames - todo; for (int i = p_frames - todo; i < p_frames; i++) { p_buffer[i] = AudioFrame(0, 0); } @@ -72,6 +75,7 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra } } } + return frames_mixed_this_step; } float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() { diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index 2bd70a2722..756c241d1f 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -52,7 +52,7 @@ class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled { Ref<AudioStreamOGGVorbis> vorbis_stream; protected: - virtual void _mix_internal(AudioFrame *p_buffer, int p_frames) override; + virtual int _mix_internal(AudioFrame *p_buffer, int p_frames) override; virtual float get_stream_sampling_rate() override; public: |