audio_stream_player_3d.cpp 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. /*************************************************************************/
  2. /* audio_stream_player_3d.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #include "audio_stream_player_3d.h"
  31. #include "core/engine.h"
  32. #include "scene/3d/area.h"
  33. #include "scene/3d/camera.h"
  34. #include "scene/3d/listener.h"
  35. #include "scene/main/viewport.h"
  36. // Based on "A Novel Multichannel Panning Method for Standard and Arbitrary Loudspeaker Configurations" by Ramy Sadek and Chris Kyriakakis (2004)
  37. // Speaker-Placement Correction Amplitude Panning (SPCAP)
  38. class Spcap {
  39. private:
  40. struct Speaker {
  41. Vector3 direction;
  42. real_t effective_number_of_speakers; // precalculated
  43. mutable real_t squared_gain; // temporary
  44. };
  45. PoolVector<Speaker> speakers;
  46. public:
  47. Spcap(unsigned int speaker_count, const Vector3 *speaker_directions) {
  48. this->speakers.resize(speaker_count);
  49. PoolVector<Speaker>::Write w = this->speakers.write();
  50. for (unsigned int speaker_num = 0; speaker_num < speaker_count; speaker_num++) {
  51. w[speaker_num].direction = speaker_directions[speaker_num];
  52. w[speaker_num].squared_gain = 0.0;
  53. w[speaker_num].effective_number_of_speakers = 0.0;
  54. for (unsigned int other_speaker_num = 0; other_speaker_num < speaker_count; other_speaker_num++) {
  55. w[speaker_num].effective_number_of_speakers += 0.5 * (1.0 + w[speaker_num].direction.dot(w[other_speaker_num].direction));
  56. }
  57. }
  58. }
  59. unsigned int get_speaker_count() const {
  60. return (unsigned int)this->speakers.size();
  61. }
  62. Vector3 get_speaker_direction(unsigned int index) const {
  63. return this->speakers.read()[index].direction;
  64. }
  65. void calculate(const Vector3 &source_direction, real_t tightness, unsigned int volume_count, real_t *volumes) const {
  66. PoolVector<Speaker>::Read r = this->speakers.read();
  67. real_t sum_squared_gains = 0.0;
  68. for (unsigned int speaker_num = 0; speaker_num < (unsigned int)this->speakers.size(); speaker_num++) {
  69. real_t initial_gain = 0.5 * powf(1.0 + r[speaker_num].direction.dot(source_direction), tightness) / r[speaker_num].effective_number_of_speakers;
  70. r[speaker_num].squared_gain = initial_gain * initial_gain;
  71. sum_squared_gains += r[speaker_num].squared_gain;
  72. }
  73. for (unsigned int speaker_num = 0; speaker_num < MIN(volume_count, (unsigned int)this->speakers.size()); speaker_num++) {
  74. volumes[speaker_num] = sqrtf(r[speaker_num].squared_gain / sum_squared_gains);
  75. }
  76. }
  77. };
  78. //TODO: hardcoded main speaker directions for 2, 3.1, 5.1 and 7.1 setups - these are simplified and could also be made configurable
  79. static const Vector3 speaker_directions[7] = {
  80. Vector3(-1.0, 0.0, -1.0).normalized(), // front-left
  81. Vector3(1.0, 0.0, -1.0).normalized(), // front-right
  82. Vector3(0.0, 0.0, -1.0).normalized(), // center
  83. Vector3(-1.0, 0.0, 1.0).normalized(), // rear-left
  84. Vector3(1.0, 0.0, 1.0).normalized(), // rear-right
  85. Vector3(-1.0, 0.0, 0.0).normalized(), // side-left
  86. Vector3(1.0, 0.0, 0.0).normalized(), // side-right
  87. };
  88. void AudioStreamPlayer3D::_calc_output_vol(const Vector3 &source_dir, real_t tightness, AudioStreamPlayer3D::Output &output) {
  89. unsigned int speaker_count; // only main speakers (no LFE)
  90. switch (AudioServer::get_singleton()->get_speaker_mode()) {
  91. default: //fallthrough
  92. case AudioServer::SPEAKER_MODE_STEREO:
  93. speaker_count = 2;
  94. break;
  95. case AudioServer::SPEAKER_SURROUND_31:
  96. speaker_count = 3;
  97. break;
  98. case AudioServer::SPEAKER_SURROUND_51:
  99. speaker_count = 5;
  100. break;
  101. case AudioServer::SPEAKER_SURROUND_71:
  102. speaker_count = 7;
  103. break;
  104. }
  105. Spcap spcap(speaker_count, speaker_directions); //TODO: should only be created/recreated once the speaker mode / speaker positions changes
  106. real_t volumes[7];
  107. spcap.calculate(source_dir, tightness, speaker_count, volumes);
  108. switch (AudioServer::get_singleton()->get_speaker_mode()) {
  109. case AudioServer::SPEAKER_SURROUND_71:
  110. output.vol[3].l = volumes[5]; // side-left
  111. output.vol[3].r = volumes[6]; // side-right
  112. //fallthrough
  113. case AudioServer::SPEAKER_SURROUND_51:
  114. output.vol[2].l = volumes[3]; // rear-left
  115. output.vol[2].r = volumes[4]; // rear-right
  116. //fallthrough
  117. case AudioServer::SPEAKER_SURROUND_31:
  118. output.vol[1].r = 1.0; // LFE - always full power
  119. output.vol[1].l = volumes[2]; // center
  120. //fallthrough
  121. case AudioServer::SPEAKER_MODE_STEREO:
  122. output.vol[0].r = volumes[1]; // front-right
  123. output.vol[0].l = volumes[0]; // front-left
  124. }
  125. }
  126. void AudioStreamPlayer3D::_mix_audio() {
  127. if (!stream_playback.is_valid() || !active.is_set() ||
  128. (stream_paused && !stream_paused_fade_out)) {
  129. return;
  130. }
  131. bool started = false;
  132. if (setseek.get() >= 0.0) {
  133. stream_playback->start(setseek.get());
  134. setseek.set(-1.0); //reset seek
  135. started = true;
  136. }
  137. //get data
  138. AudioFrame *buffer = mix_buffer.ptrw();
  139. int buffer_size = mix_buffer.size();
  140. if (stream_paused_fade_out) {
  141. // Short fadeout ramp
  142. buffer_size = MIN(buffer_size, 128);
  143. }
  144. // Mix if we're not paused or we're fading out
  145. if ((output_count.get() > 0 || out_of_range_mode == OUT_OF_RANGE_MIX)) {
  146. float output_pitch_scale = 0.0;
  147. if (output_count.get()) {
  148. //used for doppler, not realistic but good enough
  149. for (int i = 0; i < output_count.get(); i++) {
  150. output_pitch_scale += outputs[i].pitch_scale;
  151. }
  152. output_pitch_scale /= float(output_count.get());
  153. } else {
  154. output_pitch_scale = 1.0;
  155. }
  156. stream_playback->mix(buffer, pitch_scale * output_pitch_scale, buffer_size);
  157. }
  158. //write all outputs
  159. for (int i = 0; i < output_count.get(); i++) {
  160. Output current = outputs[i];
  161. //see if current output exists, to keep volume ramp
  162. bool found = false;
  163. for (int j = i; j < prev_output_count; j++) {
  164. if (prev_outputs[j].viewport == current.viewport) {
  165. if (j != i) {
  166. SWAP(prev_outputs[j], prev_outputs[i]);
  167. }
  168. found = true;
  169. break;
  170. }
  171. }
  172. bool interpolate_filter = !started;
  173. if (!found) {
  174. //create new if was not used before
  175. if (prev_output_count < MAX_OUTPUTS) {
  176. prev_outputs[prev_output_count] = prev_outputs[i]; //may be owned by another viewport
  177. prev_output_count++;
  178. }
  179. prev_outputs[i] = current;
  180. interpolate_filter = false;
  181. }
  182. //mix!
  183. int buffers = AudioServer::get_singleton()->get_channel_count();
  184. for (int k = 0; k < buffers; k++) {
  185. AudioFrame target_volume = stream_paused_fade_out ? AudioFrame(0.f, 0.f) : current.vol[k];
  186. AudioFrame vol_prev = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol[k];
  187. AudioFrame vol_inc = (target_volume - vol_prev) / float(buffer_size);
  188. AudioFrame vol = vol_prev;
  189. if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, k)) {
  190. continue; //may have been deleted, will be updated on process
  191. }
  192. AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, k);
  193. current.filter.set_mode(AudioFilterSW::HIGHSHELF);
  194. current.filter.set_sampling_rate(AudioServer::get_singleton()->get_mix_rate());
  195. current.filter.set_cutoff(attenuation_filter_cutoff_hz);
  196. current.filter.set_resonance(1);
  197. current.filter.set_stages(1);
  198. current.filter.set_gain(current.filter_gain);
  199. if (interpolate_filter) {
  200. current.filter_process[k * 2 + 0] = prev_outputs[i].filter_process[k * 2 + 0];
  201. current.filter_process[k * 2 + 1] = prev_outputs[i].filter_process[k * 2 + 1];
  202. current.filter_process[k * 2 + 0].set_filter(&current.filter, false);
  203. current.filter_process[k * 2 + 1].set_filter(&current.filter, false);
  204. current.filter_process[k * 2 + 0].update_coeffs(buffer_size);
  205. current.filter_process[k * 2 + 1].update_coeffs(buffer_size);
  206. for (int j = 0; j < buffer_size; j++) {
  207. AudioFrame f = buffer[j] * vol;
  208. current.filter_process[k * 2 + 0].process_one_interp(f.l);
  209. current.filter_process[k * 2 + 1].process_one_interp(f.r);
  210. target[j] += f;
  211. vol += vol_inc;
  212. }
  213. } else {
  214. current.filter_process[k * 2 + 0].set_filter(&current.filter);
  215. current.filter_process[k * 2 + 1].set_filter(&current.filter);
  216. current.filter_process[k * 2 + 0].update_coeffs();
  217. current.filter_process[k * 2 + 1].update_coeffs();
  218. for (int j = 0; j < buffer_size; j++) {
  219. AudioFrame f = buffer[j] * vol;
  220. current.filter_process[k * 2 + 0].process_one(f.l);
  221. current.filter_process[k * 2 + 1].process_one(f.r);
  222. target[j] += f;
  223. vol += vol_inc;
  224. }
  225. }
  226. if (current.reverb_bus_index >= 0) {
  227. if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.reverb_bus_index, k)) {
  228. continue; //may have been deleted, will be updated on process
  229. }
  230. AudioFrame *rtarget = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.reverb_bus_index, k);
  231. if (current.reverb_bus_index == prev_outputs[i].reverb_bus_index) {
  232. AudioFrame rvol_inc = (current.reverb_vol[k] - prev_outputs[i].reverb_vol[k]) / float(buffer_size);
  233. AudioFrame rvol = prev_outputs[i].reverb_vol[k];
  234. for (int j = 0; j < buffer_size; j++) {
  235. rtarget[j] += buffer[j] * rvol;
  236. rvol += rvol_inc;
  237. }
  238. } else {
  239. AudioFrame rvol = current.reverb_vol[k];
  240. for (int j = 0; j < buffer_size; j++) {
  241. rtarget[j] += buffer[j] * rvol;
  242. }
  243. }
  244. }
  245. }
  246. prev_outputs[i] = current;
  247. }
  248. prev_output_count = output_count.get();
  249. //stream is no longer active, disable this.
  250. if (!stream_playback->is_playing()) {
  251. active.clear();
  252. }
  253. output_ready.clear();
  254. stream_paused_fade_in = false;
  255. stream_paused_fade_out = false;
  256. }
  257. float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const {
  258. float att = 0;
  259. switch (attenuation_model) {
  260. case ATTENUATION_INVERSE_DISTANCE: {
  261. att = Math::linear2db(1.0 / ((p_distance / unit_size) + CMP_EPSILON));
  262. } break;
  263. case ATTENUATION_INVERSE_SQUARE_DISTANCE: {
  264. float d = (p_distance / unit_size);
  265. d *= d;
  266. att = Math::linear2db(1.0 / (d + CMP_EPSILON));
  267. } break;
  268. case ATTENUATION_LOGARITHMIC: {
  269. att = -20 * Math::log(p_distance / unit_size + CMP_EPSILON);
  270. } break;
  271. case ATTENUATION_DISABLED:
  272. break;
  273. default: {
  274. ERR_PRINT("Unknown attenuation type");
  275. break;
  276. }
  277. }
  278. att += unit_db;
  279. if (att > max_db) {
  280. att = max_db;
  281. }
  282. return att;
  283. }
  284. void _update_sound() {
  285. }
  286. void AudioStreamPlayer3D::_notification(int p_what) {
  287. if (p_what == NOTIFICATION_ENTER_TREE) {
  288. velocity_tracker->reset(get_global_transform().origin);
  289. AudioServer::get_singleton()->add_callback(_mix_audios, this);
  290. if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
  291. play();
  292. }
  293. }
  294. if (p_what == NOTIFICATION_EXIT_TREE) {
  295. AudioServer::get_singleton()->remove_callback(_mix_audios, this);
  296. }
  297. if (p_what == NOTIFICATION_PAUSED) {
  298. if (!can_process()) {
  299. // Node can't process so we start fading out to silence
  300. set_stream_paused(true);
  301. }
  302. }
  303. if (p_what == NOTIFICATION_UNPAUSED) {
  304. set_stream_paused(false);
  305. }
  306. if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
  307. if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
  308. velocity_tracker->update_position(get_global_transform().origin);
  309. }
  310. }
  311. if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
  312. //update anything related to position first, if possible of course
  313. if (!output_ready.is_set()) {
  314. Vector3 linear_velocity;
  315. //compute linear velocity for doppler
  316. if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
  317. linear_velocity = velocity_tracker->get_tracked_linear_velocity();
  318. }
  319. Ref<World> world = get_world();
  320. ERR_FAIL_COND(world.is_null());
  321. int new_output_count = 0;
  322. Vector3 global_pos = get_global_transform().origin;
  323. int bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus);
  324. //check if any area is diverting sound into a bus
  325. PhysicsDirectSpaceState *space_state = PhysicsServer::get_singleton()->space_get_direct_state(world->get_space());
  326. PhysicsDirectSpaceState::ShapeResult sr[MAX_INTERSECT_AREAS];
  327. int areas = space_state->intersect_point(global_pos, sr, MAX_INTERSECT_AREAS, Set<RID>(), area_mask, false, true);
  328. Area *area = nullptr;
  329. for (int i = 0; i < areas; i++) {
  330. if (!sr[i].collider) {
  331. continue;
  332. }
  333. Area *tarea = Object::cast_to<Area>(sr[i].collider);
  334. if (!tarea) {
  335. continue;
  336. }
  337. if (!tarea->is_overriding_audio_bus() && !tarea->is_using_reverb_bus()) {
  338. continue;
  339. }
  340. area = tarea;
  341. break;
  342. }
  343. List<Camera *> cameras;
  344. world->get_camera_list(&cameras);
  345. for (List<Camera *>::Element *E = cameras.front(); E; E = E->next()) {
  346. Camera *camera = E->get();
  347. Viewport *vp = camera->get_viewport();
  348. if (!vp->is_audio_listener()) {
  349. continue;
  350. }
  351. bool listener_is_camera = true;
  352. Spatial *listener_node = camera;
  353. Listener *listener = vp->get_listener();
  354. if (listener) {
  355. listener_node = listener;
  356. listener_is_camera = false;
  357. }
  358. Vector3 local_pos = listener_node->get_global_transform().orthonormalized().affine_inverse().xform(global_pos);
  359. float dist = local_pos.length();
  360. Vector3 area_sound_pos;
  361. Vector3 listener_area_pos;
  362. if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) {
  363. area_sound_pos = space_state->get_closest_point_to_object_volume(area->get_rid(), listener_node->get_global_transform().origin);
  364. listener_area_pos = listener_node->get_global_transform().affine_inverse().xform(area_sound_pos);
  365. }
  366. if (max_distance > 0) {
  367. float total_max = max_distance;
  368. if (area && area->is_using_reverb_bus() && area->get_reverb_uniformity() > 0) {
  369. total_max = MAX(total_max, listener_area_pos.length());
  370. }
  371. if (total_max > max_distance) {
  372. continue; //can't hear this sound in this listener
  373. }
  374. }
  375. float multiplier = Math::db2linear(_get_attenuation_db(dist));
  376. if (max_distance > 0) {
  377. multiplier *= MAX(0, 1.0 - (dist / max_distance));
  378. }
  379. Output output;
  380. output.bus_index = bus_index;
  381. output.reverb_bus_index = -1; //no reverb by default
  382. output.viewport = vp;
  383. float db_att = (1.0 - MIN(1.0, multiplier)) * attenuation_filter_db;
  384. if (emission_angle_enabled) {
  385. Vector3 listenertopos = global_pos - listener_node->get_global_transform().origin;
  386. float c = listenertopos.normalized().dot(get_global_transform().basis.get_axis(2).normalized()); //it's z negative
  387. float angle = Math::rad2deg(Math::acos(c));
  388. if (angle > emission_angle) {
  389. db_att -= -emission_angle_filter_attenuation_db;
  390. }
  391. }
  392. output.filter_gain = Math::db2linear(db_att);
  393. //TODO: The lower the second parameter (tightness) the more the sound will "enclose" the listener (more undirected / playing from
  394. // speakers not facing the source) - this could be made distance dependent.
  395. _calc_output_vol(local_pos.normalized(), 4.0, output);
  396. unsigned int cc = AudioServer::get_singleton()->get_channel_count();
  397. for (unsigned int k = 0; k < cc; k++) {
  398. output.vol[k] *= multiplier;
  399. }
  400. bool filled_reverb = false;
  401. int vol_index_max = AudioServer::get_singleton()->get_speaker_mode() + 1;
  402. if (area) {
  403. if (area->is_overriding_audio_bus()) {
  404. //override audio bus
  405. StringName bus_name = area->get_audio_bus();
  406. output.bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus_name);
  407. }
  408. if (area->is_using_reverb_bus()) {
  409. filled_reverb = true;
  410. StringName bus_name = area->get_reverb_bus();
  411. output.reverb_bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus_name);
  412. float uniformity = area->get_reverb_uniformity();
  413. float area_send = area->get_reverb_amount();
  414. if (uniformity > 0.0) {
  415. float distance = listener_area_pos.length();
  416. float attenuation = Math::db2linear(_get_attenuation_db(distance));
  417. //float dist_att_db = -20 * Math::log(dist + 0.00001); //logarithmic attenuation, like in real life
  418. float center_val[3] = { 0.5f, 0.25f, 0.16666f };
  419. AudioFrame center_frame(center_val[vol_index_max - 1], center_val[vol_index_max - 1]);
  420. if (attenuation < 1.0) {
  421. //pan the uniform sound
  422. Vector3 rev_pos = listener_area_pos;
  423. rev_pos.y = 0;
  424. rev_pos.normalize();
  425. if (cc >= 1) {
  426. // Stereo pair
  427. float c = rev_pos.x * 0.5 + 0.5;
  428. output.reverb_vol[0].l = 1.0 - c;
  429. output.reverb_vol[0].r = c;
  430. }
  431. if (cc >= 3) {
  432. // Center pair + Side pair
  433. float xl = Vector3(-1, 0, -1).normalized().dot(rev_pos) * 0.5 + 0.5;
  434. float xr = Vector3(1, 0, -1).normalized().dot(rev_pos) * 0.5 + 0.5;
  435. output.reverb_vol[1].l = xl;
  436. output.reverb_vol[1].r = xr;
  437. output.reverb_vol[2].l = 1.0 - xr;
  438. output.reverb_vol[2].r = 1.0 - xl;
  439. }
  440. if (cc >= 4) {
  441. // Rear pair
  442. // FIXME: Not sure what math should be done here
  443. float c = rev_pos.x * 0.5 + 0.5;
  444. output.reverb_vol[3].l = 1.0 - c;
  445. output.reverb_vol[3].r = c;
  446. }
  447. for (int i = 0; i < vol_index_max; i++) {
  448. output.reverb_vol[i] = output.reverb_vol[i].linear_interpolate(center_frame, attenuation);
  449. }
  450. } else {
  451. for (int i = 0; i < vol_index_max; i++) {
  452. output.reverb_vol[i] = center_frame;
  453. }
  454. }
  455. for (int i = 0; i < vol_index_max; i++) {
  456. output.reverb_vol[i] = output.vol[i].linear_interpolate(output.reverb_vol[i] * attenuation, uniformity);
  457. output.reverb_vol[i] *= area_send;
  458. }
  459. } else {
  460. for (int i = 0; i < vol_index_max; i++) {
  461. output.reverb_vol[i] = output.vol[i] * area_send;
  462. }
  463. }
  464. }
  465. }
  466. if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
  467. Vector3 listener_velocity;
  468. if (listener_is_camera) {
  469. listener_velocity = camera->get_doppler_tracked_velocity();
  470. }
  471. Vector3 local_velocity = listener_node->get_global_transform().orthonormalized().basis.xform_inv(linear_velocity - listener_velocity);
  472. if (local_velocity == Vector3()) {
  473. output.pitch_scale = 1.0;
  474. } else {
  475. float approaching = local_pos.normalized().dot(local_velocity.normalized());
  476. float velocity = local_velocity.length();
  477. float speed_of_sound = 343.0;
  478. output.pitch_scale = speed_of_sound / (speed_of_sound + velocity * approaching);
  479. output.pitch_scale = CLAMP(output.pitch_scale, (1 / 8.0), 8.0); //avoid crazy stuff
  480. }
  481. } else {
  482. output.pitch_scale = 1.0;
  483. }
  484. if (!filled_reverb) {
  485. for (int i = 0; i < vol_index_max; i++) {
  486. output.reverb_vol[i] = AudioFrame(0, 0);
  487. }
  488. }
  489. outputs[new_output_count] = output;
  490. new_output_count++;
  491. if (new_output_count == MAX_OUTPUTS) {
  492. break;
  493. }
  494. }
  495. output_count.set(new_output_count);
  496. output_ready.set();
  497. }
  498. //start playing if requested
  499. if (setplay.get() >= 0.0) {
  500. setseek.set(setplay.get());
  501. active.set();
  502. setplay.set(-1);
  503. //do not update, this makes it easier to animate (will shut off otherwise)
  504. ///_change_notify("playing"); //update property in editor
  505. }
  506. //stop playing if no longer active
  507. if (!active.is_set()) {
  508. set_physics_process_internal(false);
  509. //do not update, this makes it easier to animate (will shut off otherwise)
  510. //_change_notify("playing"); //update property in editor
  511. emit_signal("finished");
  512. }
  513. }
  514. }
  515. void AudioStreamPlayer3D::set_stream(Ref<AudioStream> p_stream) {
  516. // Instancing audio streams can cause large memory allocations, do it prior to AudioServer::lock.
  517. Ref<AudioStreamPlayback> pre_instanced_playback;
  518. if (p_stream.is_valid()) {
  519. pre_instanced_playback = p_stream->instance_playback();
  520. }
  521. AudioServer::get_singleton()->lock();
  522. mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size());
  523. if (stream_playback.is_valid()) {
  524. stream_playback.unref();
  525. stream.unref();
  526. active.clear();
  527. setseek.set(-1);
  528. }
  529. if (p_stream.is_valid()) {
  530. stream = p_stream;
  531. stream_playback = pre_instanced_playback;
  532. }
  533. AudioServer::get_singleton()->unlock();
  534. if (p_stream.is_valid() && stream_playback.is_null()) {
  535. stream.unref();
  536. }
  537. }
  538. Ref<AudioStream> AudioStreamPlayer3D::get_stream() const {
  539. return stream;
  540. }
  541. void AudioStreamPlayer3D::set_unit_db(float p_volume) {
  542. unit_db = p_volume;
  543. }
  544. float AudioStreamPlayer3D::get_unit_db() const {
  545. return unit_db;
  546. }
  547. void AudioStreamPlayer3D::set_unit_size(float p_volume) {
  548. unit_size = p_volume;
  549. }
  550. float AudioStreamPlayer3D::get_unit_size() const {
  551. return unit_size;
  552. }
  553. void AudioStreamPlayer3D::set_max_db(float p_boost) {
  554. max_db = p_boost;
  555. }
  556. float AudioStreamPlayer3D::get_max_db() const {
  557. return max_db;
  558. }
  559. void AudioStreamPlayer3D::set_pitch_scale(float p_pitch_scale) {
  560. ERR_FAIL_COND(p_pitch_scale <= 0.0);
  561. pitch_scale = p_pitch_scale;
  562. }
  563. float AudioStreamPlayer3D::get_pitch_scale() const {
  564. return pitch_scale;
  565. }
  566. void AudioStreamPlayer3D::play(float p_from_pos) {
  567. if (!is_playing()) {
  568. // Reset the prev_output_count if the stream is stopped
  569. prev_output_count = 0;
  570. }
  571. if (stream_playback.is_valid()) {
  572. setplay.set(p_from_pos);
  573. output_ready.clear();
  574. set_physics_process_internal(true);
  575. }
  576. }
  577. void AudioStreamPlayer3D::seek(float p_seconds) {
  578. if (stream_playback.is_valid()) {
  579. setseek.set(p_seconds);
  580. }
  581. }
  582. void AudioStreamPlayer3D::stop() {
  583. if (stream_playback.is_valid()) {
  584. active.clear();
  585. set_physics_process_internal(false);
  586. setplay.set(-1);
  587. }
  588. }
  589. bool AudioStreamPlayer3D::is_playing() const {
  590. if (stream_playback.is_valid()) {
  591. return active.is_set() || setplay.get() >= 0;
  592. }
  593. return false;
  594. }
  595. float AudioStreamPlayer3D::get_playback_position() {
  596. if (stream_playback.is_valid()) {
  597. float ss = setseek.get();
  598. if (ss >= 0.0) {
  599. return ss;
  600. }
  601. return stream_playback->get_playback_position();
  602. }
  603. return 0;
  604. }
  605. void AudioStreamPlayer3D::set_bus(const StringName &p_bus) {
  606. //if audio is active, must lock this
  607. AudioServer::get_singleton()->lock();
  608. bus = p_bus;
  609. AudioServer::get_singleton()->unlock();
  610. }
  611. StringName AudioStreamPlayer3D::get_bus() const {
  612. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  613. if (AudioServer::get_singleton()->get_bus_name(i) == bus) {
  614. return bus;
  615. }
  616. }
  617. return "Master";
  618. }
  619. void AudioStreamPlayer3D::set_autoplay(bool p_enable) {
  620. autoplay = p_enable;
  621. }
  622. bool AudioStreamPlayer3D::is_autoplay_enabled() {
  623. return autoplay;
  624. }
  625. void AudioStreamPlayer3D::_set_playing(bool p_enable) {
  626. if (p_enable) {
  627. play();
  628. } else {
  629. stop();
  630. }
  631. }
  632. bool AudioStreamPlayer3D::_is_active() const {
  633. return active.is_set();
  634. }
  635. void AudioStreamPlayer3D::_validate_property(PropertyInfo &property) const {
  636. if (property.name == "bus") {
  637. String options;
  638. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  639. if (i > 0) {
  640. options += ",";
  641. }
  642. String name = AudioServer::get_singleton()->get_bus_name(i);
  643. options += name;
  644. }
  645. property.hint_string = options;
  646. }
  647. }
  648. void AudioStreamPlayer3D::_bus_layout_changed() {
  649. _change_notify();
  650. }
  651. void AudioStreamPlayer3D::set_max_distance(float p_metres) {
  652. ERR_FAIL_COND(p_metres < 0.0);
  653. max_distance = p_metres;
  654. }
  655. float AudioStreamPlayer3D::get_max_distance() const {
  656. return max_distance;
  657. }
  658. void AudioStreamPlayer3D::set_area_mask(uint32_t p_mask) {
  659. area_mask = p_mask;
  660. }
  661. uint32_t AudioStreamPlayer3D::get_area_mask() const {
  662. return area_mask;
  663. }
  664. void AudioStreamPlayer3D::set_emission_angle_enabled(bool p_enable) {
  665. emission_angle_enabled = p_enable;
  666. update_gizmo();
  667. }
  668. bool AudioStreamPlayer3D::is_emission_angle_enabled() const {
  669. return emission_angle_enabled;
  670. }
  671. void AudioStreamPlayer3D::set_emission_angle(float p_angle) {
  672. ERR_FAIL_COND(p_angle < 0 || p_angle > 90);
  673. emission_angle = p_angle;
  674. update_gizmo();
  675. _change_notify("emission_angle");
  676. }
  677. float AudioStreamPlayer3D::get_emission_angle() const {
  678. return emission_angle;
  679. }
  680. void AudioStreamPlayer3D::set_emission_angle_filter_attenuation_db(float p_angle_attenuation_db) {
  681. emission_angle_filter_attenuation_db = p_angle_attenuation_db;
  682. }
  683. float AudioStreamPlayer3D::get_emission_angle_filter_attenuation_db() const {
  684. return emission_angle_filter_attenuation_db;
  685. }
  686. void AudioStreamPlayer3D::set_attenuation_filter_cutoff_hz(float p_hz) {
  687. attenuation_filter_cutoff_hz = p_hz;
  688. }
  689. float AudioStreamPlayer3D::get_attenuation_filter_cutoff_hz() const {
  690. return attenuation_filter_cutoff_hz;
  691. }
  692. void AudioStreamPlayer3D::set_attenuation_filter_db(float p_db) {
  693. attenuation_filter_db = p_db;
  694. }
  695. float AudioStreamPlayer3D::get_attenuation_filter_db() const {
  696. return attenuation_filter_db;
  697. }
  698. void AudioStreamPlayer3D::set_attenuation_model(AttenuationModel p_model) {
  699. ERR_FAIL_INDEX((int)p_model, 4);
  700. attenuation_model = p_model;
  701. }
  702. AudioStreamPlayer3D::AttenuationModel AudioStreamPlayer3D::get_attenuation_model() const {
  703. return attenuation_model;
  704. }
  705. void AudioStreamPlayer3D::set_out_of_range_mode(OutOfRangeMode p_mode) {
  706. ERR_FAIL_INDEX((int)p_mode, 2);
  707. out_of_range_mode = p_mode;
  708. }
  709. AudioStreamPlayer3D::OutOfRangeMode AudioStreamPlayer3D::get_out_of_range_mode() const {
  710. return out_of_range_mode;
  711. }
  712. void AudioStreamPlayer3D::set_doppler_tracking(DopplerTracking p_tracking) {
  713. if (doppler_tracking == p_tracking) {
  714. return;
  715. }
  716. doppler_tracking = p_tracking;
  717. if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
  718. set_notify_transform(true);
  719. velocity_tracker->set_track_physics_step(doppler_tracking == DOPPLER_TRACKING_PHYSICS_STEP);
  720. if (is_inside_tree()) {
  721. velocity_tracker->reset(get_global_transform().origin);
  722. }
  723. } else {
  724. set_notify_transform(false);
  725. }
  726. }
  727. AudioStreamPlayer3D::DopplerTracking AudioStreamPlayer3D::get_doppler_tracking() const {
  728. return doppler_tracking;
  729. }
  730. void AudioStreamPlayer3D::set_stream_paused(bool p_pause) {
  731. if (p_pause != stream_paused) {
  732. stream_paused = p_pause;
  733. stream_paused_fade_in = !stream_paused;
  734. stream_paused_fade_out = stream_paused;
  735. }
  736. }
  737. bool AudioStreamPlayer3D::get_stream_paused() const {
  738. return stream_paused;
  739. }
  740. Ref<AudioStreamPlayback> AudioStreamPlayer3D::get_stream_playback() {
  741. return stream_playback;
  742. }
  743. void AudioStreamPlayer3D::_bind_methods() {
  744. ClassDB::bind_method(D_METHOD("set_stream", "stream"), &AudioStreamPlayer3D::set_stream);
  745. ClassDB::bind_method(D_METHOD("get_stream"), &AudioStreamPlayer3D::get_stream);
  746. ClassDB::bind_method(D_METHOD("set_unit_db", "unit_db"), &AudioStreamPlayer3D::set_unit_db);
  747. ClassDB::bind_method(D_METHOD("get_unit_db"), &AudioStreamPlayer3D::get_unit_db);
  748. ClassDB::bind_method(D_METHOD("set_unit_size", "unit_size"), &AudioStreamPlayer3D::set_unit_size);
  749. ClassDB::bind_method(D_METHOD("get_unit_size"), &AudioStreamPlayer3D::get_unit_size);
  750. ClassDB::bind_method(D_METHOD("set_max_db", "max_db"), &AudioStreamPlayer3D::set_max_db);
  751. ClassDB::bind_method(D_METHOD("get_max_db"), &AudioStreamPlayer3D::get_max_db);
  752. ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer3D::set_pitch_scale);
  753. ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer3D::get_pitch_scale);
  754. ClassDB::bind_method(D_METHOD("play", "from_position"), &AudioStreamPlayer3D::play, DEFVAL(0.0));
  755. ClassDB::bind_method(D_METHOD("seek", "to_position"), &AudioStreamPlayer3D::seek);
  756. ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer3D::stop);
  757. ClassDB::bind_method(D_METHOD("is_playing"), &AudioStreamPlayer3D::is_playing);
  758. ClassDB::bind_method(D_METHOD("get_playback_position"), &AudioStreamPlayer3D::get_playback_position);
  759. ClassDB::bind_method(D_METHOD("set_bus", "bus"), &AudioStreamPlayer3D::set_bus);
  760. ClassDB::bind_method(D_METHOD("get_bus"), &AudioStreamPlayer3D::get_bus);
  761. ClassDB::bind_method(D_METHOD("set_autoplay", "enable"), &AudioStreamPlayer3D::set_autoplay);
  762. ClassDB::bind_method(D_METHOD("is_autoplay_enabled"), &AudioStreamPlayer3D::is_autoplay_enabled);
  763. ClassDB::bind_method(D_METHOD("_set_playing", "enable"), &AudioStreamPlayer3D::_set_playing);
  764. ClassDB::bind_method(D_METHOD("_is_active"), &AudioStreamPlayer3D::_is_active);
  765. ClassDB::bind_method(D_METHOD("set_max_distance", "metres"), &AudioStreamPlayer3D::set_max_distance);
  766. ClassDB::bind_method(D_METHOD("get_max_distance"), &AudioStreamPlayer3D::get_max_distance);
  767. ClassDB::bind_method(D_METHOD("set_area_mask", "mask"), &AudioStreamPlayer3D::set_area_mask);
  768. ClassDB::bind_method(D_METHOD("get_area_mask"), &AudioStreamPlayer3D::get_area_mask);
  769. ClassDB::bind_method(D_METHOD("set_emission_angle", "degrees"), &AudioStreamPlayer3D::set_emission_angle);
  770. ClassDB::bind_method(D_METHOD("get_emission_angle"), &AudioStreamPlayer3D::get_emission_angle);
  771. ClassDB::bind_method(D_METHOD("set_emission_angle_enabled", "enabled"), &AudioStreamPlayer3D::set_emission_angle_enabled);
  772. ClassDB::bind_method(D_METHOD("is_emission_angle_enabled"), &AudioStreamPlayer3D::is_emission_angle_enabled);
  773. ClassDB::bind_method(D_METHOD("set_emission_angle_filter_attenuation_db", "db"), &AudioStreamPlayer3D::set_emission_angle_filter_attenuation_db);
  774. ClassDB::bind_method(D_METHOD("get_emission_angle_filter_attenuation_db"), &AudioStreamPlayer3D::get_emission_angle_filter_attenuation_db);
  775. ClassDB::bind_method(D_METHOD("set_attenuation_filter_cutoff_hz", "degrees"), &AudioStreamPlayer3D::set_attenuation_filter_cutoff_hz);
  776. ClassDB::bind_method(D_METHOD("get_attenuation_filter_cutoff_hz"), &AudioStreamPlayer3D::get_attenuation_filter_cutoff_hz);
  777. ClassDB::bind_method(D_METHOD("set_attenuation_filter_db", "db"), &AudioStreamPlayer3D::set_attenuation_filter_db);
  778. ClassDB::bind_method(D_METHOD("get_attenuation_filter_db"), &AudioStreamPlayer3D::get_attenuation_filter_db);
  779. ClassDB::bind_method(D_METHOD("set_attenuation_model", "model"), &AudioStreamPlayer3D::set_attenuation_model);
  780. ClassDB::bind_method(D_METHOD("get_attenuation_model"), &AudioStreamPlayer3D::get_attenuation_model);
  781. ClassDB::bind_method(D_METHOD("set_out_of_range_mode", "mode"), &AudioStreamPlayer3D::set_out_of_range_mode);
  782. ClassDB::bind_method(D_METHOD("get_out_of_range_mode"), &AudioStreamPlayer3D::get_out_of_range_mode);
  783. ClassDB::bind_method(D_METHOD("set_doppler_tracking", "mode"), &AudioStreamPlayer3D::set_doppler_tracking);
  784. ClassDB::bind_method(D_METHOD("get_doppler_tracking"), &AudioStreamPlayer3D::get_doppler_tracking);
  785. ClassDB::bind_method(D_METHOD("set_stream_paused", "pause"), &AudioStreamPlayer3D::set_stream_paused);
  786. ClassDB::bind_method(D_METHOD("get_stream_paused"), &AudioStreamPlayer3D::get_stream_paused);
  787. ClassDB::bind_method(D_METHOD("get_stream_playback"), &AudioStreamPlayer3D::get_stream_playback);
  788. ClassDB::bind_method(D_METHOD("_bus_layout_changed"), &AudioStreamPlayer3D::_bus_layout_changed);
  789. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream");
  790. ADD_PROPERTY(PropertyInfo(Variant::INT, "attenuation_model", PROPERTY_HINT_ENUM, "Inverse,InverseSquare,Logarithmic,Disabled"), "set_attenuation_model", "get_attenuation_model");
  791. ADD_PROPERTY(PropertyInfo(Variant::REAL, "unit_db", PROPERTY_HINT_RANGE, "-80,80"), "set_unit_db", "get_unit_db");
  792. ADD_PROPERTY(PropertyInfo(Variant::REAL, "unit_size", PROPERTY_HINT_RANGE, "0.1,100,0.1"), "set_unit_size", "get_unit_size");
  793. ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_db", PROPERTY_HINT_RANGE, "-24,6"), "set_max_db", "get_max_db");
  794. ADD_PROPERTY(PropertyInfo(Variant::REAL, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,4,0.01,or_greater"), "set_pitch_scale", "get_pitch_scale");
  795. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "is_playing");
  796. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled");
  797. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stream_paused", PROPERTY_HINT_NONE, ""), "set_stream_paused", "get_stream_paused");
  798. ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_distance", PROPERTY_HINT_RANGE, "0,4096,0.01,or_greater"), "set_max_distance", "get_max_distance");
  799. ADD_PROPERTY(PropertyInfo(Variant::INT, "out_of_range_mode", PROPERTY_HINT_ENUM, "Mix,Pause"), "set_out_of_range_mode", "get_out_of_range_mode");
  800. ADD_PROPERTY(PropertyInfo(Variant::STRING, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus");
  801. ADD_PROPERTY(PropertyInfo(Variant::INT, "area_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_area_mask", "get_area_mask");
  802. ADD_GROUP("Emission Angle", "emission_angle");
  803. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emission_angle_enabled"), "set_emission_angle_enabled", "is_emission_angle_enabled");
  804. ADD_PROPERTY(PropertyInfo(Variant::REAL, "emission_angle_degrees", PROPERTY_HINT_RANGE, "0.1,90,0.1"), "set_emission_angle", "get_emission_angle");
  805. ADD_PROPERTY(PropertyInfo(Variant::REAL, "emission_angle_filter_attenuation_db", PROPERTY_HINT_RANGE, "-80,0,0.1"), "set_emission_angle_filter_attenuation_db", "get_emission_angle_filter_attenuation_db");
  806. ADD_GROUP("Attenuation Filter", "attenuation_filter_");
  807. ADD_PROPERTY(PropertyInfo(Variant::REAL, "attenuation_filter_cutoff_hz", PROPERTY_HINT_RANGE, "1,20500,1"), "set_attenuation_filter_cutoff_hz", "get_attenuation_filter_cutoff_hz");
  808. ADD_PROPERTY(PropertyInfo(Variant::REAL, "attenuation_filter_db", PROPERTY_HINT_RANGE, "-80,0,0.1"), "set_attenuation_filter_db", "get_attenuation_filter_db");
  809. ADD_GROUP("Doppler", "doppler_");
  810. ADD_PROPERTY(PropertyInfo(Variant::INT, "doppler_tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Physics"), "set_doppler_tracking", "get_doppler_tracking");
  811. BIND_ENUM_CONSTANT(ATTENUATION_INVERSE_DISTANCE);
  812. BIND_ENUM_CONSTANT(ATTENUATION_INVERSE_SQUARE_DISTANCE);
  813. BIND_ENUM_CONSTANT(ATTENUATION_LOGARITHMIC);
  814. BIND_ENUM_CONSTANT(ATTENUATION_DISABLED);
  815. BIND_ENUM_CONSTANT(OUT_OF_RANGE_MIX);
  816. BIND_ENUM_CONSTANT(OUT_OF_RANGE_PAUSE);
  817. BIND_ENUM_CONSTANT(DOPPLER_TRACKING_DISABLED);
  818. BIND_ENUM_CONSTANT(DOPPLER_TRACKING_IDLE_STEP);
  819. BIND_ENUM_CONSTANT(DOPPLER_TRACKING_PHYSICS_STEP);
  820. ADD_SIGNAL(MethodInfo("finished"));
  821. }
  822. AudioStreamPlayer3D::AudioStreamPlayer3D() {
  823. unit_db = 0;
  824. unit_size = 1;
  825. attenuation_model = ATTENUATION_INVERSE_DISTANCE;
  826. max_db = 3;
  827. pitch_scale = 1.0;
  828. autoplay = false;
  829. setseek.set(-1);
  830. prev_output_count = 0;
  831. max_distance = 0;
  832. setplay.set(-1);
  833. area_mask = 1;
  834. emission_angle = 45;
  835. emission_angle_enabled = false;
  836. emission_angle_filter_attenuation_db = -12;
  837. attenuation_filter_cutoff_hz = 5000;
  838. attenuation_filter_db = -24;
  839. out_of_range_mode = OUT_OF_RANGE_MIX;
  840. doppler_tracking = DOPPLER_TRACKING_DISABLED;
  841. stream_paused = false;
  842. stream_paused_fade_in = false;
  843. stream_paused_fade_out = false;
  844. velocity_tracker.instance();
  845. AudioServer::get_singleton()->connect("bus_layout_changed", this, "_bus_layout_changed");
  846. set_disable_scale(true);
  847. }
  848. AudioStreamPlayer3D::~AudioStreamPlayer3D() {
  849. }