summaryrefslogtreecommitdiff
path: root/scene/3d/audio_stream_player_3d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/audio_stream_player_3d.cpp')
-rw-r--r--scene/3d/audio_stream_player_3d.cpp58
1 files changed, 50 insertions, 8 deletions
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index 6c102e4027..c2a50ec7bb 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -1,3 +1,33 @@
+/*************************************************************************/
+/* audio_stream_player_3d.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#include "audio_stream_player_3d.h"
#include "engine.h"
#include "scene/3d/area.h"
@@ -27,18 +57,18 @@ void AudioStreamPlayer3D::_mix_audio() {
//mix
if (output_count > 0 || out_of_range_mode == OUT_OF_RANGE_MIX) {
- float pitch_scale = 0.0;
+ float output_pitch_scale = 0.0;
if (output_count) {
//used for doppler, not realistic but good enough
for (int i = 0; i < output_count; i++) {
- pitch_scale += outputs[i].pitch_scale;
+ output_pitch_scale += outputs[i].pitch_scale;
}
- pitch_scale /= float(output_count);
+ output_pitch_scale /= float(output_count);
} else {
- pitch_scale = 1.0;
+ output_pitch_scale = 1.0;
}
- stream_playback->mix(buffer, pitch_scale, buffer_size);
+ stream_playback->mix(buffer, pitch_scale * output_pitch_scale, buffer_size);
}
//write all outputs
@@ -290,7 +320,7 @@ void AudioStreamPlayer3D::_notification(int p_what) {
total_max = MAX(total_max, cam_area_pos.length());
}
if (total_max > max_distance) {
- continue; //cant hear this sound in this camera
+ continue; //can't hear this sound in this camera
}
}
@@ -506,14 +536,14 @@ void AudioStreamPlayer3D::_notification(int p_what) {
setseek = setplay;
active = true;
setplay = -1;
- //do not update, this makes it easier to animate (will shut off otherise)
+ //do not update, this makes it easier to animate (will shut off otherwise)
///_change_notify("playing"); //update property in editor
}
//stop playing if no longer active
if (!active) {
set_physics_process_internal(false);
- //do not update, this makes it easier to animate (will shut off otherise)
+ //do not update, this makes it easier to animate (will shut off otherwise)
//_change_notify("playing"); //update property in editor
emit_signal("finished");
}
@@ -577,6 +607,13 @@ float AudioStreamPlayer3D::get_max_db() const {
return max_db;
}
+void AudioStreamPlayer3D::set_pitch_scale(float p_pitch_scale) {
+ pitch_scale = p_pitch_scale;
+}
+float AudioStreamPlayer3D::get_pitch_scale() const {
+ return pitch_scale;
+}
+
void AudioStreamPlayer3D::play(float p_from_pos) {
if (stream_playback.is_valid()) {
@@ -802,6 +839,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_pitch_scale", "pitch_scale"), &AudioStreamPlayer3D::set_pitch_scale);
+ ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer3D::get_pitch_scale);
+
ClassDB::bind_method(D_METHOD("play", "from_position"), &AudioStreamPlayer3D::play, DEFVAL(0.0));
ClassDB::bind_method(D_METHOD("seek", "to_position"), &AudioStreamPlayer3D::seek);
ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer3D::stop);
@@ -855,6 +895,7 @@ void AudioStreamPlayer3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "unit_db", PROPERTY_HINT_RANGE, "-80,80"), "set_unit_db", "get_unit_db");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "unit_size", PROPERTY_HINT_RANGE, "0.1,100,0.1"), "set_unit_size", "get_unit_size");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_db", PROPERTY_HINT_RANGE, "-24,6"), "set_max_db", "get_max_db");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,32,0.01"), "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");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_distance", PROPERTY_HINT_RANGE, "0,65536,1"), "set_max_distance", "get_max_distance");
@@ -891,6 +932,7 @@ AudioStreamPlayer3D::AudioStreamPlayer3D() {
unit_size = 1;
attenuation_model = ATTENUATION_INVERSE_DISTANCE;
max_db = 3;
+ pitch_scale = 1.0;
autoplay = false;
setseek = -1;
active = false;