Debian Codegraph @

scene/3d/audio_stream_player_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* audio_stream_player_3d.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "scene/3d/node_3d.h"
34 #include "servers/audio/audio_server.h"
35
36 #ifndef PHYSICS_3D_DISABLED
37 class Area3D;
38 #endif // PHYSICS_3D_DISABLED
39 struct AudioFrame;
40 class AudioStream;
41 class AudioStreamPlayback;
42 class AudioStreamPlayerInternal;
43 class VelocityTracker3D;
44
45 class AudioStreamPlayer3D : public Node3D {
46 GDCLASS(AudioStreamPlayer3D, Node3D);
47
48 public:
49 enum AttenuationModel {
50 ATTENUATION_INVERSE_DISTANCE,
51 ATTENUATION_INVERSE_SQUARE_DISTANCE,
52 ATTENUATION_LOGARITHMIC,
53 ATTENUATION_DISABLED,
54 };
55
56 enum DopplerTracking {
57 DOPPLER_TRACKING_DISABLED,
58 DOPPLER_TRACKING_IDLE_STEP,
59 DOPPLER_TRACKING_PHYSICS_STEP
60 };
61
62 private:
63 enum {
64 MAX_OUTPUTS = 8,
65 MAX_INTERSECT_AREAS = 32
66
67 };
68
69 AudioStreamPlayerInternal *internal = nullptr;
70
71 SafeNumeric<float> setplay{ -1.0 };
72 Ref<AudioStreamPlayback> setplayback;
73
74 AttenuationModel attenuation_model = ATTENUATION_INVERSE_DISTANCE;
75 float unit_size = 10.0;
76 float max_db = 3.0;
77 // Internally used to take doppler tracking into account.
78 float actual_pitch_scale = 1.0;
79
80 uint64_t last_mix_count = -1;
81 bool force_update_panning = false;
82
83 static void _calc_output_vol(const Vector3 &source_dir, real_t tightness, Vector<AudioFrame> &output);
84 static AudioFrame _calc_output_vol_stereo(const Vector3 &source_dir, real_t panning_strength);
85
86 #ifndef PHYSICS_3D_DISABLED
87 void _calc_reverb_vol(Area3D *area, Vector3 listener_area_pos, Vector<AudioFrame> direct_path_vol, Vector<AudioFrame> &reverb_vol);
88 #endif // PHYSICS_3D_DISABLED
89
90 static void _listener_changed_cb(void *self) { reinterpret_cast<AudioStreamPlayer3D *>(self)->force_update_panning = true; }
91
92 void _set_playing(bool p_enable);
93 bool _is_active() const;
94 StringName _get_actual_bus();
95 #ifndef PHYSICS_3D_DISABLED
96 Area3D *_get_overriding_area();
97 #endif // PHYSICS_3D_DISABLED
98 Vector<AudioFrame> _update_panning();
99
100 uint32_t area_mask = 1;
101
102 AudioServer::PlaybackType playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT;
103
104 bool emission_angle_enabled = false;
105 float emission_angle = 45.0;
106 float emission_angle_filter_attenuation_db = -12.0;
107 float attenuation_filter_cutoff_hz = 5000.0;
108 float attenuation_filter_db = -24.0;
109
110 float linear_attenuation = 0;
111
112 float max_distance = 0.0;
113 bool was_further_than_max_distance_last_frame = false;
114
115 Ref<VelocityTracker3D> velocity_tracker;
116
117 DopplerTracking doppler_tracking = DOPPLER_TRACKING_DISABLED;
118
119 float _get_attenuation_db(float p_distance) const;
120
121 float panning_strength = 1.0f;
122 float cached_global_panning_strength = 0.5f;
123
124 protected:
125 void _validate_property(PropertyInfo &p_property) const;
126 void _notification(int p_what);
127 static void _bind_methods();
128
129 bool _set(const StringName &p_name, const Variant &p_value);
130 bool _get(const StringName &p_name, Variant &r_ret) const;
131 void _get_property_list(List<PropertyInfo> *p_list) const;
132
133 #ifndef DISABLE_DEPRECATED
134 bool _is_autoplay_enabled_bind_compat_86907();
135 static void _bind_compatibility_methods();
136 #endif // DISABLE_DEPRECATED
137
138 public:
139 void set_stream(Ref<AudioStream> p_stream);
140 Ref<AudioStream> get_stream() const;
141
142 void set_volume_db(float p_volume);
143 float get_volume_db() const;
144
145 void set_volume_linear(float p_volume);
146 float get_volume_linear() const;
147
148 void set_unit_size(float p_volume);
149 float get_unit_size() const;
150
151 void set_max_db(float p_boost);
152 float get_max_db() const;
153
154 void set_pitch_scale(float p_pitch_scale);
155 float get_pitch_scale() const;
156
157 void play(float p_from_pos = 0.0);
158 void seek(float p_seconds);
159 void stop();
160 bool is_playing() const;
161 float get_playback_position();
162
163 void set_bus(const StringName &p_bus);
164 StringName get_bus() const;
165
166 void set_max_polyphony(int p_max_polyphony);
167 int get_max_polyphony() const;
168
169 void set_autoplay(bool p_enable);
170 bool is_autoplay_enabled() const;
171
172 void set_max_distance(float p_metres);
173 float get_max_distance() const;
174
175 void set_area_mask(uint32_t p_mask);
176 uint32_t get_area_mask() const;
177
178 void set_emission_angle_enabled(bool p_enable);
179 bool is_emission_angle_enabled() const;
180
181 void set_emission_angle(float p_angle);
182 float get_emission_angle() const;
183
184 void set_emission_angle_filter_attenuation_db(float p_angle_attenuation_db);
185 float get_emission_angle_filter_attenuation_db() const;
186
187 void set_attenuation_filter_cutoff_hz(float p_hz);
188 float get_attenuation_filter_cutoff_hz() const;
189
190 void set_attenuation_filter_db(float p_db);
191 float get_attenuation_filter_db() const;
192
193 void set_attenuation_model(AttenuationModel p_model);
194 AttenuationModel get_attenuation_model() const;
195
196 void set_doppler_tracking(DopplerTracking p_tracking);
197 DopplerTracking get_doppler_tracking() const;
198
199 void set_stream_paused(bool p_pause);
200 bool get_stream_paused() const;
201
202 void set_panning_strength(float p_panning_strength);
203 float get_panning_strength() const;
204
205 bool has_stream_playback();
206 Ref<AudioStreamPlayback> get_stream_playback();
207
208 AudioServer::PlaybackType get_playback_type() const;
209 void set_playback_type(AudioServer::PlaybackType p_playback_type);
210
211 AudioStreamPlayer3D();
212 ~AudioStreamPlayer3D();
213 };
214
215 VARIANT_ENUM_CAST(AudioStreamPlayer3D::AttenuationModel)
216 VARIANT_ENUM_CAST(AudioStreamPlayer3D::DopplerTracking)