Skip to content

Commit

Permalink
Merge pull request #81508 from bluenote10/bugfix/fix_audio_stream_gen…
Browse files Browse the repository at this point in the history
…erator

Alternative minimal fix for audio stream generators
  • Loading branch information
akien-mga committed Sep 20, 2023
2 parents 712ebe7 + 4eac548 commit cc7227c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions servers/audio/effects/audio_stream_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ void AudioStreamGeneratorPlayback::clear_buffer() {
}

int AudioStreamGeneratorPlayback::_mix_internal(AudioFrame *p_buffer, int p_frames) {
if (!active) {
return 0;
}

int read_amount = buffer.data_left();
if (p_frames < read_amount) {
read_amount = p_frames;
Expand All @@ -151,16 +155,15 @@ int AudioStreamGeneratorPlayback::_mix_internal(AudioFrame *p_buffer, int p_fram
buffer.read(p_buffer, read_amount);

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++) {
p_buffer[i] = AudioFrame(0, 0);
}

skips++;
}

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() {
Expand All @@ -181,7 +184,7 @@ void AudioStreamGeneratorPlayback::stop() {
}

bool AudioStreamGeneratorPlayback::is_playing() const {
return active; //always playing, can't be stopped
return active;
}

int AudioStreamGeneratorPlayback::get_loop_count() const {
Expand Down

0 comments on commit cc7227c

Please sign in to comment.