|
@@ -30,6 +30,7 @@
|
|
|
|
|
|
#include "audio_stream_player_3d.h"
|
|
|
#include "core/engine.h"
|
|
|
+#include "core/project_settings.h"
|
|
|
#include "scene/3d/area.h"
|
|
|
#include "scene/3d/camera.h"
|
|
|
#include "scene/3d/listener.h"
|
|
@@ -471,9 +472,10 @@ void AudioStreamPlayer3D::_notification(int p_what) {
|
|
|
|
|
|
output.filter_gain = Math::db2linear(db_att);
|
|
|
|
|
|
- //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);
|
|
|
+ // Bake in a constant factor here to allow the project setting defaults for 2d and 3d to be normalized to 1.0.
|
|
|
+ float tightness = cached_global_panning_strength * 2.0f;
|
|
|
+ tightness *= panning_strength;
|
|
|
+ _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++) {
|
|
@@ -898,6 +900,15 @@ Ref<AudioStreamPlayback> AudioStreamPlayer3D::get_stream_playback() {
|
|
|
return stream_playback;
|
|
|
}
|
|
|
|
|
|
+void AudioStreamPlayer3D::set_panning_strength(float p_panning_strength) {
|
|
|
+ ERR_FAIL_COND_MSG(p_panning_strength < 0, "Panning strength must be a positive number.");
|
|
|
+ panning_strength = p_panning_strength;
|
|
|
+}
|
|
|
+
|
|
|
+float AudioStreamPlayer3D::get_panning_strength() const {
|
|
|
+ return panning_strength;
|
|
|
+}
|
|
|
+
|
|
|
void AudioStreamPlayer3D::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("set_stream", "stream"), &AudioStreamPlayer3D::set_stream);
|
|
|
ClassDB::bind_method(D_METHOD("get_stream"), &AudioStreamPlayer3D::get_stream);
|
|
@@ -963,6 +974,9 @@ void AudioStreamPlayer3D::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("set_stream_paused", "pause"), &AudioStreamPlayer3D::set_stream_paused);
|
|
|
ClassDB::bind_method(D_METHOD("get_stream_paused"), &AudioStreamPlayer3D::get_stream_paused);
|
|
|
|
|
|
+ ClassDB::bind_method(D_METHOD("set_panning_strength", "panning_strength"), &AudioStreamPlayer3D::set_panning_strength);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_panning_strength"), &AudioStreamPlayer3D::get_panning_strength);
|
|
|
+
|
|
|
ClassDB::bind_method(D_METHOD("get_stream_playback"), &AudioStreamPlayer3D::get_stream_playback);
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_bus_layout_changed"), &AudioStreamPlayer3D::_bus_layout_changed);
|
|
@@ -978,6 +992,7 @@ void AudioStreamPlayer3D::_bind_methods() {
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stream_paused", PROPERTY_HINT_NONE, ""), "set_stream_paused", "get_stream_paused");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_distance", PROPERTY_HINT_RANGE, "0,4096,0.01,or_greater"), "set_max_distance", "get_max_distance");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "out_of_range_mode", PROPERTY_HINT_ENUM, "Mix,Pause"), "set_out_of_range_mode", "get_out_of_range_mode");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "panning_strength", PROPERTY_HINT_RANGE, "0,3,0.01,or_greater"), "set_panning_strength", "get_panning_strength");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "area_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_area_mask", "get_area_mask");
|
|
|
ADD_GROUP("Emission Angle", "emission_angle");
|
|
@@ -1031,6 +1046,7 @@ AudioStreamPlayer3D::AudioStreamPlayer3D() {
|
|
|
velocity_tracker.instance();
|
|
|
AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed");
|
|
|
set_disable_scale(true);
|
|
|
+ cached_global_panning_strength = ProjectSettings::get_singleton()->get("audio/3d_panning_strength");
|
|
|
}
|
|
|
AudioStreamPlayer3D::~AudioStreamPlayer3D() {
|
|
|
}
|