bugfix for audio stream generators getting killed accidentally by audio server

(cherry picked from commit 4eac548202)
This commit is contained in:
Fabian Keller 2023-09-10 09:22:21 +02:00 committed by Yuri Sizov
parent e7978fe277
commit 76f61b3960
1 changed files with 7 additions and 4 deletions

View File

@ -143,6 +143,10 @@ void AudioStreamGeneratorPlayback::clear_buffer() {
} }
int AudioStreamGeneratorPlayback::_mix_internal(AudioFrame *p_buffer, int p_frames) { int AudioStreamGeneratorPlayback::_mix_internal(AudioFrame *p_buffer, int p_frames) {
if (!active) {
return 0;
}
int read_amount = buffer.data_left(); int read_amount = buffer.data_left();
if (p_frames < read_amount) { if (p_frames < read_amount) {
read_amount = p_frames; read_amount = p_frames;
@ -151,16 +155,15 @@ int AudioStreamGeneratorPlayback::_mix_internal(AudioFrame *p_buffer, int p_fram
buffer.read(p_buffer, read_amount); buffer.read(p_buffer, read_amount);
if (read_amount < p_frames) { if (read_amount < p_frames) {
//skipped, not ideal // Fill with zeros as fallback in case of buffer underrun.
for (int i = read_amount; i < p_frames; i++) { for (int i = read_amount; i < p_frames; i++) {
p_buffer[i] = AudioFrame(0, 0); p_buffer[i] = AudioFrame(0, 0);
} }
skips++; skips++;
} }
mixed += p_frames / generator->get_mix_rate(); mixed += p_frames / generator->get_mix_rate();
return read_amount < p_frames ? read_amount : p_frames; return p_frames;
} }
float AudioStreamGeneratorPlayback::get_stream_sampling_rate() { float AudioStreamGeneratorPlayback::get_stream_sampling_rate() {
@ -181,7 +184,7 @@ void AudioStreamGeneratorPlayback::stop() {
} }
bool AudioStreamGeneratorPlayback::is_playing() const { bool AudioStreamGeneratorPlayback::is_playing() const {
return active; //always playing, can't be stopped return active;
} }
int AudioStreamGeneratorPlayback::get_loop_count() const { int AudioStreamGeneratorPlayback::get_loop_count() const {