diff --git a/doc/classes/AudioStreamPlayer3D.xml b/doc/classes/AudioStreamPlayer3D.xml index aadbc865bb81..ecfa51529b53 100644 --- a/doc/classes/AudioStreamPlayer3D.xml +++ b/doc/classes/AudioStreamPlayer3D.xml @@ -103,6 +103,9 @@ If [code]true[/code], the playback is paused. You can resume it by setting [code]stream_paused[/code] to [code]false[/code]. + + How much the sound will "enclose" the listener (more undirected / playing from speakers not facing the source). Lower values enclose more. + Base sound level unaffected by dampening, in dB. diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 6e4db8f382fd..ff1658270b3f 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -474,7 +474,7 @@ void AudioStreamPlayer3D::_notification(int p_what) { //TODO: The lower the second parameter (tightness) the more the sound will "enclose" the listener (more undirected / playing from // speakers not facing the source) - this could be made distance dependent. - _calc_output_vol(local_pos.normalized(), 4.0, output); + _calc_output_vol(local_pos.normalized(), tightness, output); unsigned int cc = AudioServer::get_singleton()->get_channel_count(); for (unsigned int k = 0; k < cc; k++) { @@ -674,6 +674,13 @@ float AudioStreamPlayer3D::get_max_db() const { return max_db; } +void AudioStreamPlayer3D::set_tightness(float p_tightness) { + tightness = p_tightness; +} +float AudioStreamPlayer3D::get_tightness() const { + return tightness; +} + void AudioStreamPlayer3D::set_pitch_scale(float p_pitch_scale) { ERR_FAIL_COND(p_pitch_scale <= 0.0); pitch_scale = p_pitch_scale; @@ -912,6 +919,9 @@ void AudioStreamPlayer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_max_db", "max_db"), &AudioStreamPlayer3D::set_max_db); ClassDB::bind_method(D_METHOD("get_max_db"), &AudioStreamPlayer3D::get_max_db); + ClassDB::bind_method(D_METHOD("set_tightness", "tightness"), &AudioStreamPlayer3D::set_tightness); + ClassDB::bind_method(D_METHOD("get_tightness"), &AudioStreamPlayer3D::get_tightness); + ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer3D::set_pitch_scale); ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer3D::get_pitch_scale); @@ -971,6 +981,7 @@ void AudioStreamPlayer3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "unit_db", PROPERTY_HINT_RANGE, "-80,80"), "set_unit_db", "get_unit_db"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "unit_size", PROPERTY_HINT_RANGE, "0.1,100,0.1"), "set_unit_size", "get_unit_size"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_db", PROPERTY_HINT_RANGE, "-24,6"), "set_max_db", "get_max_db"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "tightness", PROPERTY_HINT_RANGE, "0,8"), "set_tightness", "get_tightness"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,4,0.01,or_greater"), "set_pitch_scale", "get_pitch_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "is_playing"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled"); @@ -1010,6 +1021,7 @@ AudioStreamPlayer3D::AudioStreamPlayer3D() { attenuation_model = ATTENUATION_INVERSE_DISTANCE; max_db = 3; pitch_scale = 1.0; + tightness = 4.0; autoplay = false; setseek = -1; active = false; diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index 339475b4693f..96384cee54fe 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -107,6 +107,7 @@ class AudioStreamPlayer3D : public Node3D { float unit_size; float max_db; float pitch_scale; + float tightness; bool autoplay; bool stream_paused; bool stream_paused_fade_in; @@ -161,6 +162,9 @@ class AudioStreamPlayer3D : public Node3D { void set_pitch_scale(float p_pitch_scale); float get_pitch_scale() const; + void set_tightness(float p_tightness); + float get_tightness() const; + void play(float p_from_pos = 0.0); void seek(float p_seconds); void stop();