Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix audio stream generators getting freed accidentally #81508

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seemed to be outdated. Or, in fact slightly ironic, because in Godot 4.x the generator playbacks get stopped all the time 😉

return active;
}

int AudioStreamGeneratorPlayback::get_loop_count() const {
Expand Down
Loading