diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-20 16:06:28 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-09-20 16:06:28 +0200 |
commit | d2a5153c6608d0172ebfed3c5984cc6c76ee9c6f (patch) | |
tree | ce1afe8709fec746db4cca23079c132f9594511c /scene/3d/audio_stream_player_3d.cpp | |
parent | 7e62565f1e075cb5a2b090e320739daa4a8dce9a (diff) | |
parent | a3158d89bb7cba513fc2aa47cdc23fe39d2a1ad3 (diff) | |
download | redot-engine-d2a5153c6608d0172ebfed3c5984cc6c76ee9c6f.tar.gz |
Merge pull request #96677 from Wierdox/fix_audio_stream_player_3d_still_processing_when_out_of_range
Fix AudioStreamPlayer3D still processing when out of range
Diffstat (limited to 'scene/3d/audio_stream_player_3d.cpp')
-rw-r--r-- | scene/3d/audio_stream_player_3d.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 591528b915..98bee2115c 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -401,10 +401,19 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() { if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) { total_max = MAX(total_max, listener_area_pos.length()); } - if (total_max > max_distance) { + if (dist > total_max || total_max > max_distance) { + if (!was_further_than_max_distance_last_frame) { + HashMap<StringName, Vector<AudioFrame>> bus_volumes; + for (Ref<AudioStreamPlayback> &playback : internal->stream_playbacks) { + // So the player gets muted and mostly stops mixing when out of range. + AudioServer::get_singleton()->set_playback_bus_volumes_linear(playback, bus_volumes); + } + was_further_than_max_distance_last_frame = true; // Cache so we don't set the volume over and over. + } continue; //can't hear this sound in this listener } } + was_further_than_max_distance_last_frame = false; float multiplier = Math::db_to_linear(_get_attenuation_db(dist)); if (max_distance > 0) { |