audio_stream_player_3d.cpp 37 KB

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