Godot Engine – Multi-platform 2D and 3D game engine
Split AudioServer files and system classes
smix8b4ebc1cd682c
diff --git a/core/register_core_types.cpp b/core/register_core_types.cppindex d68a6d47d52..0b3e904290e 100644--- a/core/register_core_types.cpp+++ b/core/register_core_types.cpp@@ -347,7 +347,6 @@ void register_core_types() {_engine_debugger = memnew(CoreBind::EngineDebugger);GDREGISTER_NATIVE_STRUCT(ObjectID, "uint64_t id = 0");- GDREGISTER_NATIVE_STRUCT(AudioFrame, "float left;float right");GDREGISTER_NATIVE_STRUCT(ScriptLanguageExtensionProfilingInfo, "StringName signature;uint64_t call_count;uint64_t total_time;uint64_t self_time");worker_thread_pool = memnew(WorkerThreadPool);diff --git a/core/variant/native_ptr.h b/core/variant/native_ptr.hindex e2cc3fad9ff..8dde4f65a85 100644--- a/core/variant/native_ptr.h+++ b/core/variant/native_ptr.h@@ -30,12 +30,13 @@#pragma once-#include "core/math/audio_frame.h"#include "core/variant/method_ptrcall.h"#include "core/variant/type_info.h"#include "core/variant/variant_caster.h"#include "core/variant/variant_internal.h"+struct AudioFrame;+// Metafunction for pointee name. Specialized in GDVIRTUAL_NATIVE_PTR; takes into account const; falls back to "void".template <typename T>struct GDExtensionPtrName {diff --git a/drivers/alsa/audio_driver_alsa.h b/drivers/alsa/audio_driver_alsa.hindex d9c8ad211bd..3335ddaa95c 100644--- a/drivers/alsa/audio_driver_alsa.h+++ b/drivers/alsa/audio_driver_alsa.h@@ -35,7 +35,7 @@#include "core/os/mutex.h"#include "core/os/thread.h"#include "core/templates/safe_refcount.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_driver.h"typedef struct _snd_pcm snd_pcm_t;typedef unsigned long snd_pcm_uframes_t;diff --git a/drivers/coreaudio/audio_driver_coreaudio.h b/drivers/coreaudio/audio_driver_coreaudio.hindex 08c4ec475f9..4983ce34d99 100644--- a/drivers/coreaudio/audio_driver_coreaudio.h+++ b/drivers/coreaudio/audio_driver_coreaudio.h@@ -32,7 +32,8 @@#ifdef COREAUDIO_ENABLED-#include "servers/audio/audio_server.h"+#include "core/os/mutex.h"+#include "servers/audio/audio_driver.h"#import <AudioUnit/AudioUnit.h>#ifdef MACOS_ENABLEDdiff --git a/drivers/pulseaudio/audio_driver_pulseaudio.h b/drivers/pulseaudio/audio_driver_pulseaudio.hindex dde0e34a874..18caee84382 100644--- a/drivers/pulseaudio/audio_driver_pulseaudio.h+++ b/drivers/pulseaudio/audio_driver_pulseaudio.h@@ -35,7 +35,7 @@#include "core/os/mutex.h"#include "core/os/thread.h"#include "core/templates/safe_refcount.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_driver.h"#ifdef SOWRAP_ENABLED#include "drivers/pulseaudio/pulse-so_wrap.h" // IWYU pragma: keep. Relies on pulseaudio.h transitive includes.diff --git a/drivers/wasapi/audio_driver_wasapi.h b/drivers/wasapi/audio_driver_wasapi.hindex 2f7ba8d3d50..a7a349f7ccf 100644--- a/drivers/wasapi/audio_driver_wasapi.h+++ b/drivers/wasapi/audio_driver_wasapi.h@@ -35,7 +35,7 @@#include "core/os/mutex.h"#include "core/os/thread.h"#include "core/templates/safe_refcount.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_driver.h"#include <windows.h>diff --git a/drivers/xaudio2/audio_driver_xaudio2.h b/drivers/xaudio2/audio_driver_xaudio2.hindex e1da8e8be89..8058d029c96 100644--- a/drivers/xaudio2/audio_driver_xaudio2.h+++ b/drivers/xaudio2/audio_driver_xaudio2.h@@ -33,7 +33,7 @@#include "core/os/mutex.h"#include "core/os/thread.h"#include "core/templates/safe_refcount.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_driver.h"#include <windows.h>diff --git a/editor/animation/animation_track_editor.cpp b/editor/animation/animation_track_editor.cppindex 4c4613e5c74..fdf05aa430a 100644--- a/editor/animation/animation_track_editor.cpp+++ b/editor/animation/animation_track_editor.cpp@@ -67,7 +67,7 @@#include "scene/gui/view_panner.h"#include "scene/main/scene_tree.h"#include "scene/main/window.h"-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"constexpr double FPS_DECIMAL = 1.0;constexpr double SECOND_DECIMAL = 0.0001;diff --git a/editor/animation/animation_track_editor_plugins.cpp b/editor/animation/animation_track_editor_plugins.cppindex 61a5d0a5030..775f04de9db 100644--- a/editor/animation/animation_track_editor_plugins.cpp+++ b/editor/animation/animation_track_editor_plugins.cpp@@ -41,7 +41,7 @@#include "scene/2d/sprite_2d.h"#include "scene/3d/sprite_3d.h"#include "scene/animation/animation_player.h"-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"#include "servers/rendering/rendering_server.h"/// BOOL ///diff --git a/editor/audio/audio_stream_editor_plugin.cpp b/editor/audio/audio_stream_editor_plugin.cppindex 04eea59c747..459e4302e93 100644--- a/editor/audio/audio_stream_editor_plugin.cpp+++ b/editor/audio/audio_stream_editor_plugin.cpp@@ -35,7 +35,7 @@#include "editor/editor_string_names.h"#include "editor/settings/editor_settings.h"#include "editor/themes/editor_scale.h"-#include "scene/resources/audio_stream_wav.h"+#include "scene/resources/audio/audio_stream_wav.h"#include "servers/rendering/rendering_server.h"// AudioStreamEditordiff --git a/editor/audio/audio_stream_preview.cpp b/editor/audio/audio_stream_preview.cppindex ab297ddbc2b..05b32cad09f 100644--- a/editor/audio/audio_stream_preview.cpp+++ b/editor/audio/audio_stream_preview.cpp@@ -32,8 +32,7 @@#include "core/object/callable_mp.h"#include "core/object/class_db.h"--/////////////////////+#include "servers/audio/audio_server.h"float AudioStreamPreview::get_length() const {return length;diff --git a/editor/audio/audio_stream_preview.h b/editor/audio/audio_stream_preview.hindex 28903c4d132..08c2d2a8a0d 100644--- a/editor/audio/audio_stream_preview.h+++ b/editor/audio/audio_stream_preview.h@@ -33,7 +33,7 @@#include "core/object/worker_thread_pool.h"#include "core/templates/safe_refcount.h"#include "scene/main/node.h"-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"class AudioStreamPreview : public RefCounted {GDCLASS(AudioStreamPreview, RefCounted);diff --git a/editor/audio/audio_stream_randomizer_editor_plugin.cpp b/editor/audio/audio_stream_randomizer_editor_plugin.cppindex c0c231e5cf1..63cb66b289a 100644--- a/editor/audio/audio_stream_randomizer_editor_plugin.cpp+++ b/editor/audio/audio_stream_randomizer_editor_plugin.cpp@@ -33,7 +33,7 @@#include "core/object/callable_mp.h"#include "editor/editor_node.h"#include "editor/editor_undo_redo_manager.h"-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream_randomizer.h"void AudioStreamRandomizerEditorPlugin::edit(Object *p_object) {}diff --git a/editor/editor_node.cpp b/editor/editor_node.cppindex 9b51f91beda..a6b66ab9fa5 100644--- a/editor/editor_node.cpp+++ b/editor/editor_node.cpp@@ -177,6 +177,7 @@#include "scene/resources/portable_compressed_texture.h"#include "scene/theme/theme_db.h"#include "servers/audio/audio_server.h"+#include "servers/audio/audio_server_enums.h"#include "servers/display/display_server.h"#include "servers/navigation_2d/navigation_server_2d.h"#include "servers/navigation_3d/navigation_server_3d.h"@@ -6100,19 +6101,19 @@ String EditorNode::_get_system_info() const {const String audio_driver_name = AudioServer::get_singleton()->get_driver_name();const float mix_rate = AudioServer::get_singleton()->get_mix_rate();- AudioServer::SpeakerMode speaker_mode = AudioServer::get_singleton()->get_speaker_mode();+ AuSE::SpeakerMode speaker_mode = AudioServer::get_singleton()->get_speaker_mode();String speaker_mode_string;switch (speaker_mode) {- case AudioServer::SpeakerMode::SPEAKER_MODE_STEREO:+ case AuSE::SpeakerMode::SPEAKER_MODE_STEREO:speaker_mode_string = "Stereo/mono";break;- case AudioServer::SpeakerMode::SPEAKER_SURROUND_31:+ case AuSE::SpeakerMode::SPEAKER_SURROUND_31:speaker_mode_string = "Surround 3.1";break;- case AudioServer::SpeakerMode::SPEAKER_SURROUND_51:+ case AuSE::SpeakerMode::SPEAKER_SURROUND_51:speaker_mode_string = "Surround 5.1";break;- case AudioServer::SpeakerMode::SPEAKER_SURROUND_71:+ case AuSE::SpeakerMode::SPEAKER_SURROUND_71:speaker_mode_string = "Surround 7.1";break;}diff --git a/editor/import/audio_stream_import_settings.cpp b/editor/import/audio_stream_import_settings.cppindex 7891f965ec8..d2878eb474b 100644--- a/editor/import/audio_stream_import_settings.cpp+++ b/editor/import/audio_stream_import_settings.cpp@@ -36,6 +36,7 @@#include "editor/file_system/editor_file_system.h"#include "editor/themes/editor_scale.h"#include "scene/gui/check_box.h"+#include "servers/audio/audio_server.h"#include "servers/rendering/rendering_server.h"AudioStreamImportSettingsDialog *AudioStreamImportSettingsDialog::singleton = nullptr;diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cppindex 365dea1f42a..638de0be0a2 100644--- a/editor/import/resource_importer_wav.cpp+++ b/editor/import/resource_importer_wav.cpp@@ -31,7 +31,7 @@#include "resource_importer_wav.h"#include "core/io/resource_saver.h"-#include "scene/resources/audio_stream_wav.h"+#include "scene/resources/audio/audio_stream_wav.h"String ResourceImporterWAV::get_importer_name() const {return "wav";diff --git a/editor/inspector/editor_preview_plugins.cpp b/editor/inspector/editor_preview_plugins.cppindex 083e9d2a33f..1e54f6d4501 100644--- a/editor/inspector/editor_preview_plugins.cpp+++ b/editor/inspector/editor_preview_plugins.cpp@@ -39,13 +39,14 @@#include "editor/settings/editor_settings.h"#include "editor/themes/editor_scale.h"#include "scene/resources/atlas_texture.h"+#include "scene/resources/audio/audio_stream.h"#include "scene/resources/bit_map.h"#include "scene/resources/font.h"#include "scene/resources/gradient_texture.h"#include "scene/resources/image_texture.h"#include "scene/resources/material.h"#include "scene/resources/mesh.h"-#include "servers/audio/audio_stream.h"+#include "servers/audio/audio_server.h"#include "servers/rendering/rendering_server.h"void post_process_preview(Ref<Image> p_image) {diff --git a/editor/inspector/editor_resource_picker.cpp b/editor/inspector/editor_resource_picker.cppindex d10326e9abb..2dd275f14c3 100644--- a/editor/inspector/editor_resource_picker.cpp+++ b/editor/inspector/editor_resource_picker.cpp@@ -54,6 +54,7 @@#include "scene/property_utils.h"#include "scene/resources/gradient_texture.h"#include "scene/resources/image_texture.h"+#include "servers/audio/audio_server.h"#include "servers/rendering/rendering_server.h"static bool _has_sub_resources(const Ref<Resource> &p_res) {diff --git a/modules/interactive_music/audio_stream_interactive.cpp b/modules/interactive_music/audio_stream_interactive.cppindex 0ae9d2b66b5..77a81257d2b 100644--- a/modules/interactive_music/audio_stream_interactive.cpp+++ b/modules/interactive_music/audio_stream_interactive.cpp@@ -33,6 +33,8 @@#include "core/config/engine.h"#include "core/math/math_funcs.h"#include "core/object/class_db.h"+#include "servers/audio/audio_driver.h"+#include "servers/audio/audio_server.h"AudioStreamInteractive::AudioStreamInteractive() {}diff --git a/modules/interactive_music/audio_stream_interactive.h b/modules/interactive_music/audio_stream_interactive.hindex 2a8ae729ad3..d97234831ac 100644--- a/modules/interactive_music/audio_stream_interactive.h+++ b/modules/interactive_music/audio_stream_interactive.h@@ -30,7 +30,7 @@#pragma once-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"class AudioStreamPlaybackInteractive;diff --git a/modules/interactive_music/audio_stream_playlist.cpp b/modules/interactive_music/audio_stream_playlist.cppindex 2398bab3704..790d21fd1c4 100644--- a/modules/interactive_music/audio_stream_playlist.cpp+++ b/modules/interactive_music/audio_stream_playlist.cpp@@ -32,6 +32,7 @@#include "core/math/math_funcs.h"#include "core/object/class_db.h"+#include "servers/audio/audio_server.h"Ref<AudioStreamPlayback> AudioStreamPlaylist::instantiate_playback() {Ref<AudioStreamPlaybackPlaylist> playback_playlist;diff --git a/modules/interactive_music/audio_stream_playlist.h b/modules/interactive_music/audio_stream_playlist.hindex 6c87717b6bf..dcd4c1019db 100644--- a/modules/interactive_music/audio_stream_playlist.h+++ b/modules/interactive_music/audio_stream_playlist.h@@ -30,7 +30,7 @@#pragma once-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"class AudioStreamPlaybackPlaylist;diff --git a/modules/interactive_music/audio_stream_synchronized.cpp b/modules/interactive_music/audio_stream_synchronized.cppindex 827dbf3a810..5f5efd215ff 100644--- a/modules/interactive_music/audio_stream_synchronized.cpp+++ b/modules/interactive_music/audio_stream_synchronized.cpp@@ -32,6 +32,7 @@#include "core/math/math_funcs.h"#include "core/object/class_db.h"+#include "servers/audio/audio_server.h"AudioStreamSynchronized::AudioStreamSynchronized() {}diff --git a/modules/interactive_music/audio_stream_synchronized.h b/modules/interactive_music/audio_stream_synchronized.hindex be896f930c8..e248fbe64cb 100644--- a/modules/interactive_music/audio_stream_synchronized.h+++ b/modules/interactive_music/audio_stream_synchronized.h@@ -30,7 +30,7 @@#pragma once-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"class AudioStreamPlaybackSynchronized;diff --git a/modules/jpg/movie_writer_mjpeg.cpp b/modules/jpg/movie_writer_mjpeg.cppindex fdd90c03571..64ead442e49 100644--- a/modules/jpg/movie_writer_mjpeg.cpp+++ b/modules/jpg/movie_writer_mjpeg.cpp@@ -36,7 +36,7 @@uint32_t MovieWriterMJPEG::get_audio_mix_rate() const {return mix_rate;}-AudioServer::SpeakerMode MovieWriterMJPEG::get_audio_speaker_mode() const {+AuSE::SpeakerMode MovieWriterMJPEG::get_audio_speaker_mode() const {return speaker_mode;}@@ -138,16 +138,16 @@ Error MovieWriterMJPEG::write_begin(const Size2i &p_movie_size, uint32_t p_fps,const uint32_t bit_depth = audio_bit_depth;uint32_t channels = 2;switch (speaker_mode) {- case AudioServer::SPEAKER_MODE_STEREO:+ case AuSE::SPEAKER_MODE_STEREO:channels = 2;break;- case AudioServer::SPEAKER_SURROUND_31:+ case AuSE::SPEAKER_SURROUND_31:channels = 4;break;- case AudioServer::SPEAKER_SURROUND_51:+ case AuSE::SPEAKER_SURROUND_51:channels = 6;break;- case AudioServer::SPEAKER_SURROUND_71:+ case AuSE::SPEAKER_SURROUND_71:channels = 8;break;}@@ -271,7 +271,7 @@ void MovieWriterMJPEG::write_end() {MovieWriterMJPEG::MovieWriterMJPEG() {mix_rate = GLOBAL_GET("editor/movie_writer/mix_rate");- speaker_mode = AudioServer::SpeakerMode(int(GLOBAL_GET("editor/movie_writer/speaker_mode")));+ speaker_mode = AuSE::SpeakerMode(int(GLOBAL_GET("editor/movie_writer/speaker_mode")));quality = GLOBAL_GET("editor/movie_writer/video_quality");audio_bit_depth = GLOBAL_GET("editor/movie_writer/audio_bit_depth");}diff --git a/modules/jpg/movie_writer_mjpeg.h b/modules/jpg/movie_writer_mjpeg.hindex 5e6e31f31c3..84bdeb77831 100644--- a/modules/jpg/movie_writer_mjpeg.h+++ b/modules/jpg/movie_writer_mjpeg.h@@ -30,13 +30,14 @@#pragma once+#include "servers/audio/audio_server_enums.h"#include "servers/movie_writer/movie_writer.h"class MovieWriterMJPEG : public MovieWriter {GDCLASS(MovieWriterMJPEG, MovieWriter)uint32_t mix_rate = 48000;- AudioServer::SpeakerMode speaker_mode = AudioServer::SPEAKER_MODE_STEREO;+ AuSE::SpeakerMode speaker_mode = AuSE::SPEAKER_MODE_STEREO;uint32_t audio_bit_depth = 16;String base_path;uint32_t frame_count = 0;@@ -57,7 +58,7 @@ class MovieWriterMJPEG : public MovieWriter {protected:virtual uint32_t get_audio_mix_rate() const override;- virtual AudioServer::SpeakerMode get_audio_speaker_mode() const override;+ virtual AuSE::SpeakerMode get_audio_speaker_mode() const override;virtual void get_supported_extensions(List<String> *r_extensions) const override;virtual Error write_begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path) override;diff --git a/modules/mp3/audio_stream_mp3.h b/modules/mp3/audio_stream_mp3.hindex d6039459e67..20181c8a653 100644--- a/modules/mp3/audio_stream_mp3.h+++ b/modules/mp3/audio_stream_mp3.h@@ -30,7 +30,7 @@#pragma once-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"#include <thirdparty/dr_libs/dr_mp3.h>diff --git a/modules/theora/editor/movie_writer_ogv.cpp b/modules/theora/editor/movie_writer_ogv.cppindex 8c3276cc060..9902abe3491 100644--- a/modules/theora/editor/movie_writer_ogv.cpp+++ b/modules/theora/editor/movie_writer_ogv.cpp@@ -99,7 +99,7 @@ uint32_t MovieWriterOGV::get_audio_mix_rate() const {return mix_rate;}-AudioServer::SpeakerMode MovieWriterOGV::get_audio_speaker_mode() const {+AuSE::SpeakerMode MovieWriterOGV::get_audio_speaker_mode() const {return speaker_mode;}@@ -126,16 +126,16 @@ Error MovieWriterOGV::write_begin(const Size2i &p_movie_size, uint32_t p_fps, coaudio_ch = 2;switch (speaker_mode) {- case AudioServer::SPEAKER_MODE_STEREO:+ case AuSE::SPEAKER_MODE_STEREO:audio_ch = 2;break;- case AudioServer::SPEAKER_SURROUND_31:+ case AuSE::SPEAKER_SURROUND_31:audio_ch = 4;break;- case AudioServer::SPEAKER_SURROUND_51:+ case AuSE::SPEAKER_SURROUND_51:audio_ch = 6;break;- case AudioServer::SPEAKER_SURROUND_71:+ case AuSE::SPEAKER_SURROUND_71:audio_ch = 8;break;}@@ -427,7 +427,7 @@ void MovieWriterOGV::write_end() {MovieWriterOGV::MovieWriterOGV() {mix_rate = GLOBAL_GET("editor/movie_writer/mix_rate");- speaker_mode = AudioServer::SpeakerMode(int(GLOBAL_GET("editor/movie_writer/speaker_mode")));+ speaker_mode = AuSE::SpeakerMode(int(GLOBAL_GET("editor/movie_writer/speaker_mode")));video_quality = GLOBAL_GET("editor/movie_writer/video_quality");audio_quality = GLOBAL_GET("editor/movie_writer/ogv/audio_quality");speed = GLOBAL_GET("editor/movie_writer/ogv/encoding_speed");diff --git a/modules/theora/editor/movie_writer_ogv.h b/modules/theora/editor/movie_writer_ogv.hindex 55b6b4a7165..44fce6ab1d7 100644--- a/modules/theora/editor/movie_writer_ogv.h+++ b/modules/theora/editor/movie_writer_ogv.h@@ -30,7 +30,7 @@#pragma once-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_server_enums.h"#include "servers/movie_writer/movie_writer.h"#include <theora/theoraenc.h>@@ -41,7 +41,7 @@ class MovieWriterOGV : public MovieWriter {GDCLASS(MovieWriterOGV, MovieWriter)uint32_t mix_rate = 48000;- AudioServer::SpeakerMode speaker_mode = AudioServer::SPEAKER_MODE_STEREO;+ AuSE::SpeakerMode speaker_mode = AuSE::SPEAKER_MODE_STEREO;String base_path;uint32_t frame_count = 0;uint32_t fps = 0;@@ -125,7 +125,7 @@ class MovieWriterOGV : public MovieWriter {protected:virtual uint32_t get_audio_mix_rate() const override;- virtual AudioServer::SpeakerMode get_audio_speaker_mode() const override;+ virtual AuSE::SpeakerMode get_audio_speaker_mode() const override;virtual void get_supported_extensions(List<String> *r_extensions) const override;virtual Error write_begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path) override;diff --git a/modules/vorbis/audio_stream_ogg_vorbis.h b/modules/vorbis/audio_stream_ogg_vorbis.hindex acc39ebfee6..e9b657e4600 100644--- a/modules/vorbis/audio_stream_ogg_vorbis.h+++ b/modules/vorbis/audio_stream_ogg_vorbis.h@@ -31,7 +31,7 @@#pragma once#include "core/variant/variant.h"-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"#include "modules/ogg/ogg_packet_sequence.h"diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cppindex 654353bc0ce..19ae6699d98 100644--- a/platform/android/audio_driver_opensl.cpp+++ b/platform/android/audio_driver_opensl.cpp@@ -31,6 +31,7 @@#include "audio_driver_opensl.h"#include "core/os/os.h"+#include "servers/audio/audio_server.h"#define MAX_NUMBER_INTERFACES 3#define MAX_NUMBER_OUTPUT_DEVICES 6diff --git a/platform/android/audio_driver_opensl.h b/platform/android/audio_driver_opensl.hindex 5f4fa3a150c..b4ea0b28e88 100644--- a/platform/android/audio_driver_opensl.h+++ b/platform/android/audio_driver_opensl.h@@ -31,7 +31,7 @@#pragma once#include "core/os/mutex.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_driver.h"#include <SLES/OpenSLES.h>#include <SLES/OpenSLES_Android.h>diff --git a/platform/web/audio_driver_web.cpp b/platform/web/audio_driver_web.cppindex 2fd5004999d..68ba9593ed9 100644--- a/platform/web/audio_driver_web.cpp+++ b/platform/web/audio_driver_web.cpp@@ -35,7 +35,8 @@#include "core/config/engine.h"#include "core/math/math_funcs_binary.h"#include "core/object/object.h"-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"+#include "servers/audio/audio_server.h"#include <emscripten.h>@@ -275,7 +276,7 @@ void AudioDriverWeb::start_sample_playback(const Ref<AudioSamplePlayback> &p_plaERR_FAIL_COND_MSG(p_playback.is_null(), "Parameter p_playback is null.");ERR_FAIL_COND_MSG(p_playback->stream.is_null(), "Parameter p_playback->stream is null.");- constexpr int real_max_channels = AudioServer::MAX_CHANNELS_PER_BUS * 2;+ constexpr int real_max_channels = AuSC::MAX_CHANNELS_PER_BUS * 2;PackedFloat32Array volume;volume.resize(real_max_channels);float *volume_ptrw = volume.ptrw();@@ -328,19 +329,19 @@ void AudioDriverWeb::update_sample_playback_pitch_scale(const Ref<AudioSamplePlavoid AudioDriverWeb::set_sample_playback_bus_volumes_linear(const Ref<AudioSamplePlayback> &p_playback, const HashMap<StringName, Vector<AudioFrame>> &p_bus_volumes) {ERR_FAIL_COND_MSG(p_playback.is_null(), "Parameter p_playback is null.");- constexpr int real_max_channels = AudioServer::MAX_CHANNELS_PER_BUS * 2;+ constexpr int real_max_channels = AuSC::MAX_CHANNELS_PER_BUS * 2;PackedInt32Array buses;buses.resize(p_bus_volumes.size());int32_t *buses_ptrw = buses.ptrw();PackedFloat32Array values;- values.resize(p_bus_volumes.size() * AudioServer::MAX_CHANNELS_PER_BUS * 2);+ values.resize(p_bus_volumes.size() * AuSC::MAX_CHANNELS_PER_BUS * 2);float *values_ptrw = values.ptrw();int idx = 0;for (KeyValue<StringName, Vector<AudioFrame>> pair : p_bus_volumes) {int bus_index = AudioServer::get_singleton()->get_bus_index(pair.key);buses_ptrw[idx] = bus_index;- ERR_FAIL_COND(pair.value.size() != AudioServer::MAX_CHANNELS_PER_BUS);+ ERR_FAIL_COND(pair.value.size() != AuSC::MAX_CHANNELS_PER_BUS);for (int i = 0; i < real_max_channels; i += 2) {const AudioFrame &frame = pair.value[i / 2];values_ptrw[(idx * real_max_channels) + i] = frame.left;diff --git a/platform/web/audio_driver_web.h b/platform/web/audio_driver_web.hindex 49e107a8cf1..bc917646cb9 100644--- a/platform/web/audio_driver_web.h+++ b/platform/web/audio_driver_web.h@@ -34,7 +34,7 @@#include "core/os/mutex.h"#include "core/os/thread.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_driver.h"class AudioDriverWeb : public AudioDriver {private:diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cppindex 741ab00f191..26e25605466 100644--- a/platform/windows/os_windows.cpp+++ b/platform/windows/os_windows.cpp@@ -49,7 +49,6 @@#include "drivers/windows/net_socket_winsock.h"#include "drivers/windows/thread_windows.h"#include "main/main.h"-#include "servers/audio/audio_server.h"#include "servers/rendering/rendering_server.h"#include "servers/text/text_server.h"diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cppindex 11938cf3757..c69a3d54198 100644--- a/scene/2d/audio_stream_player_2d.cpp+++ b/scene/2d/audio_stream_player_2d.cpp@@ -37,9 +37,9 @@#include "scene/2d/audio_listener_2d.h"#include "scene/audio/audio_stream_player_internal.h"#include "scene/main/viewport.h"+#include "scene/resources/audio/audio_stream.h"#include "scene/resources/world_2d.h"#include "servers/audio/audio_server.h"-#include "servers/audio/audio_stream.h"#ifndef PHYSICS_2D_DISABLED#include "scene/2d/physics/area_2d.h"@@ -362,11 +362,11 @@ float AudioStreamPlayer2D::get_panning_strength() const {return panning_strength;}-AudioServer::PlaybackType AudioStreamPlayer2D::get_playback_type() const {+AuSE::PlaybackType AudioStreamPlayer2D::get_playback_type() const {return internal->get_playback_type();}-void AudioStreamPlayer2D::set_playback_type(AudioServer::PlaybackType p_playback_type) {+void AudioStreamPlayer2D::set_playback_type(AuSE::PlaybackType p_playback_type) {internal->set_playback_type(p_playback_type);}diff --git a/scene/2d/audio_stream_player_2d.h b/scene/2d/audio_stream_player_2d.hindex c54e1b59eb7..39aab1d97eb 100644--- a/scene/2d/audio_stream_player_2d.h+++ b/scene/2d/audio_stream_player_2d.h@@ -31,7 +31,7 @@#pragma once#include "scene/2d/node_2d.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_server_enums.h"struct AudioFrame;class AudioStream;@@ -58,7 +58,7 @@ private:uint64_t last_mix_count = -1;bool force_update_panning = false;- AudioServer::PlaybackType playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT;+ AuSE::PlaybackType playback_type = AuSE::PlaybackType::PLAYBACK_TYPE_DEFAULT;void _set_playing(bool p_enable);bool _is_active() const;@@ -136,8 +136,8 @@ public:bool has_stream_playback();Ref<AudioStreamPlayback> get_stream_playback();- AudioServer::PlaybackType get_playback_type() const;- void set_playback_type(AudioServer::PlaybackType p_playback_type);+ AuSE::PlaybackType get_playback_type() const;+ void set_playback_type(AuSE::PlaybackType p_playback_type);AudioStreamPlayer2D();~AudioStreamPlayer2D();diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cppindex 9cc5d93ccc2..a96f9479151 100644--- a/scene/3d/audio_stream_player_3d.cpp+++ b/scene/3d/audio_stream_player_3d.cpp@@ -39,7 +39,8 @@#include "scene/3d/velocity_tracker_3d.h"#include "scene/audio/audio_stream_player_internal.h"#include "scene/main/viewport.h"-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"+#include "servers/audio/audio_server.h"#ifndef PHYSICS_3D_DISABLED#include "scene/3d/physics/area_3d.h"@@ -111,16 +112,16 @@ static const Vector3 speaker_directions[7] = {void AudioStreamPlayer3D::_calc_output_vol(const Vector3 &source_dir, real_t tightness, FixedVector<AudioFrame, VOLUME_VECTOR_SIZE> &output) {unsigned int speaker_count = 0; // only main speakers (no LFE)switch (AudioServer::get_singleton()->get_speaker_mode()) {- case AudioServer::SPEAKER_MODE_STEREO:+ case AuSE::SPEAKER_MODE_STEREO:speaker_count = 2;break;- case AudioServer::SPEAKER_SURROUND_31:+ case AuSE::SPEAKER_SURROUND_31:speaker_count = 3;break;- case AudioServer::SPEAKER_SURROUND_51:+ case AuSE::SPEAKER_SURROUND_51:speaker_count = 5;break;- case AudioServer::SPEAKER_SURROUND_71:+ case AuSE::SPEAKER_SURROUND_71:speaker_count = 7;break;}@@ -130,19 +131,19 @@ void AudioStreamPlayer3D::_calc_output_vol(const Vector3 &source_dir, real_t tigspcap.calculate(source_dir, tightness, speaker_count, volumes);switch (AudioServer::get_singleton()->get_speaker_mode()) {- case AudioServer::SPEAKER_SURROUND_71:+ case AuSE::SPEAKER_SURROUND_71:output[3].left = volumes[5]; // side-leftoutput[3].right = volumes[6]; // side-right[[fallthrough]];- case AudioServer::SPEAKER_SURROUND_51:+ case AuSE::SPEAKER_SURROUND_51:output[2].left = volumes[3]; // rear-leftoutput[2].right = volumes[4]; // rear-right[[fallthrough]];- case AudioServer::SPEAKER_SURROUND_31:+ case AuSE::SPEAKER_SURROUND_31:output[1].right = 1.0; // LFE - always full poweroutput[1].left = volumes[2]; // center[[fallthrough]];- case AudioServer::SPEAKER_MODE_STEREO:+ case AuSE::SPEAKER_MODE_STEREO:output[0].right = volumes[1]; // front-rightoutput[0].left = volumes[0]; // front-leftbreak;@@ -360,7 +361,7 @@ StringName AudioStreamPlayer3D::_get_actual_bus() {return internal->bus;}-static void _apply_max_volume_from_vector(Vector<AudioFrame> &r_tgt_volume_vector, const FixedVector<AudioFrame, AudioServer::MAX_CHANNELS_PER_BUS> &p_src_volume_vector) {+static void _apply_max_volume_from_vector(Vector<AudioFrame> &r_tgt_volume_vector, const FixedVector<AudioFrame, AuSC::MAX_CHANNELS_PER_BUS> &p_src_volume_vector) {// note: indexed loops with Vector are slow, so we use raw pointers on purpose hereAudioFrame *tgt_ptr = r_tgt_volume_vector.ptrw();const AudioFrame *src_ptr = p_src_volume_vector.ptr();@@ -371,7 +372,7 @@ static void _apply_max_volume_from_vector(Vector<AudioFrame> &r_tgt_volume_vecto}}-static float _get_max_volume(const FixedVector<AudioFrame, AudioServer::MAX_CHANNELS_PER_BUS> &p_src_volume_vector) {+static float _get_max_volume(const FixedVector<AudioFrame, AuSC::MAX_CHANNELS_PER_BUS> &p_src_volume_vector) {float max_vol = 0.0;for (const AudioFrame &frame : p_src_volume_vector) {max_vol = MAX(max_vol, MAX(frame.left, frame.right));@@ -494,7 +495,7 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {frame = AudioFrame(0, 0);}- if (AudioServer::get_singleton()->get_speaker_mode() == AudioServer::SPEAKER_MODE_STEREO) {+ if (AudioServer::get_singleton()->get_speaker_mode() == AuSE::SPEAKER_MODE_STEREO) {listener_volume_vector[0] = _calc_output_vol_stereo(local_pos, cached_global_panning_strength * panning_strength);} else {// Bake in a constant factor here to allow the project setting defaults for 2d and 3d to be normalized to 1.0.@@ -838,11 +839,11 @@ float AudioStreamPlayer3D::get_panning_strength() const {return panning_strength;}-AudioServer::PlaybackType AudioStreamPlayer3D::get_playback_type() const {+AuSE::PlaybackType AudioStreamPlayer3D::get_playback_type() const {return internal->get_playback_type();}-void AudioStreamPlayer3D::set_playback_type(AudioServer::PlaybackType p_playback_type) {+void AudioStreamPlayer3D::set_playback_type(AuSE::PlaybackType p_playback_type) {internal->set_playback_type(p_playback_type);}diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.hindex 13435ea4b06..1c58bbe5e94 100644--- a/scene/3d/audio_stream_player_3d.h+++ b/scene/3d/audio_stream_player_3d.h@@ -32,7 +32,8 @@#include "core/templates/fixed_vector.h"#include "scene/3d/node_3d.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_server_constants.h"+#include "servers/audio/audio_server_enums.h"#ifndef PHYSICS_3D_DISABLEDclass Area3D;@@ -67,7 +68,7 @@ private:};- static constexpr int64_t VOLUME_VECTOR_SIZE = AudioServer::MAX_CHANNELS_PER_BUS;+ static constexpr int64_t VOLUME_VECTOR_SIZE = AuSC::MAX_CHANNELS_PER_BUS;AudioStreamPlayerInternal *internal = nullptr;@@ -102,7 +103,7 @@ private:uint32_t area_mask = 0;- AudioServer::PlaybackType playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT;+ AuSE::PlaybackType playback_type = AuSE::PlaybackType::PLAYBACK_TYPE_DEFAULT;bool emission_angle_enabled = false;float emission_angle = 45.0;@@ -212,8 +213,8 @@ public:bool has_stream_playback();Ref<AudioStreamPlayback> get_stream_playback();- AudioServer::PlaybackType get_playback_type() const;- void set_playback_type(AudioServer::PlaybackType p_playback_type);+ AuSE::PlaybackType get_playback_type() const;+ void set_playback_type(AuSE::PlaybackType p_playback_type);AudioStreamPlayer3D();~AudioStreamPlayer3D();diff --git a/scene/animation/animation_mixer.cpp b/scene/animation/animation_mixer.cppindex f2089689ec7..a5bab672051 100644--- a/scene/animation/animation_mixer.cpp+++ b/scene/animation/animation_mixer.cpp@@ -40,8 +40,8 @@#include "scene/animation/animation_player.h"#include "scene/audio/audio_stream_player.h"#include "scene/resources/animation.h"+#include "scene/resources/audio/audio_stream.h"#include "servers/audio/audio_server.h"-#include "servers/audio/audio_stream.h"#ifndef _3D_DISABLED#include "scene/3d/audio_stream_player_3d.h"@@ -916,7 +916,7 @@ bool AnimationMixer::_update_caches() {track_audio->object_id = child->get_instance_id();track_audio->audio_stream.instantiate();track_audio->audio_stream->set_polyphony(audio_max_polyphony);- track_audio->playback_type = (AudioServer::PlaybackType)(int)(child->call(SNAME("get_playback_type")));+ track_audio->playback_type = (AuSE::PlaybackType)(int)(child->call(SNAME("get_playback_type")));track_audio->bus = (StringName)(child->call(SNAME("get_bus")));track = track_audio;diff --git a/scene/animation/animation_mixer.h b/scene/animation/animation_mixer.hindex 3f8d7f880f1..a57ffe2527f 100644--- a/scene/animation/animation_mixer.h+++ b/scene/animation/animation_mixer.h@@ -35,7 +35,7 @@#include "scene/main/node.h"#include "scene/resources/animation.h"#include "scene/resources/animation_library.h"-#include "scene/resources/audio_stream_polyphonic.h"+#include "scene/resources/audio/audio_stream_polyphonic.h"class AnimatedValuesBackup;@@ -280,7 +280,7 @@ protected:Ref<AudioStreamPolyphonic> audio_stream;Ref<AudioStreamPlaybackPolyphonic> audio_stream_playback;HashMap<ObjectID, PlayingAudioTrackInfo> playing_streams; // Key is Animation resource ObjectID.- AudioServer::PlaybackType playback_type;+ AuSE::PlaybackType playback_type;StringName bus;TrackCacheAudio(const TrackCacheAudio &p_other) :@@ -318,7 +318,7 @@ protected:void _create_track_num_to_track_cache_for_animation(const Ref<Animation> &p_animation);/* ---- Audio ---- */- AudioServer::PlaybackType playback_type;+ AuSE::PlaybackType playback_type;/* ---- Blending processor ---- */LocalVector<AnimationInstance> animation_instances;diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cppindex bbbc1494f24..9ad76f3b545 100644--- a/scene/audio/audio_stream_player.cpp+++ b/scene/audio/audio_stream_player.cpp@@ -34,7 +34,8 @@#include "core/object/callable_mp.h"#include "core/object/class_db.h"#include "scene/audio/audio_stream_player_internal.h"-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"+#include "servers/audio/audio_server.h"#include "servers/display/accessibility_server.h"void AudioStreamPlayer::_notification(int p_what) {@@ -194,7 +195,7 @@ Vector<AudioFrame> AudioStreamPlayer::_get_volume_vector() {// Set the volume vector up according to the speaker mode and mix target.// TODO do we need to scale the volume down when we output to more channels?- if (AudioServer::get_singleton()->get_speaker_mode() == AudioServer::SPEAKER_MODE_STEREO) {+ if (AudioServer::get_singleton()->get_speaker_mode() == AuSE::SPEAKER_MODE_STEREO) {volume_vector.write[0] = AudioFrame(volume_linear, volume_linear);} else {switch (mix_target) {@@ -229,11 +230,11 @@ Ref<AudioStreamPlayback> AudioStreamPlayer::get_stream_playback() {return internal->get_stream_playback();}-AudioServer::PlaybackType AudioStreamPlayer::get_playback_type() const {+AuSE::PlaybackType AudioStreamPlayer::get_playback_type() const {return internal->get_playback_type();}-void AudioStreamPlayer::set_playback_type(AudioServer::PlaybackType p_playback_type) {+void AudioStreamPlayer::set_playback_type(AuSE::PlaybackType p_playback_type) {internal->set_playback_type(p_playback_type);}diff --git a/scene/audio/audio_stream_player.h b/scene/audio/audio_stream_player.hindex abaed688d1e..409a294e832 100644--- a/scene/audio/audio_stream_player.h+++ b/scene/audio/audio_stream_player.h@@ -31,7 +31,7 @@#pragma once#include "scene/main/node.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_server_enums.h"struct AudioFrame;class AudioStream;@@ -109,8 +109,8 @@ public:bool has_stream_playback();Ref<AudioStreamPlayback> get_stream_playback();- AudioServer::PlaybackType get_playback_type() const;- void set_playback_type(AudioServer::PlaybackType p_playback_type);+ AuSE::PlaybackType get_playback_type() const;+ void set_playback_type(AuSE::PlaybackType p_playback_type);AudioStreamPlayer();~AudioStreamPlayer();diff --git a/scene/audio/audio_stream_player_internal.cpp b/scene/audio/audio_stream_player_internal.cppindex 133d16c78b6..4470c93be83 100644--- a/scene/audio/audio_stream_player_internal.cpp+++ b/scene/audio/audio_stream_player_internal.cpp@@ -34,7 +34,8 @@#include "core/object/callable_mp.h"#include "scene/main/node.h"#include "scene/main/scene_tree.h"-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"+#include "servers/audio/audio_server.h"void AudioStreamPlayerInternal::_set_process(bool p_enabled) {if (physical) {@@ -63,6 +64,10 @@ void AudioStreamPlayerInternal::_update_stream_parameters() {}}+bool AudioStreamPlayerInternal::_is_sample() {+ return (AudioServer::get_singleton()->get_default_playback_type() == AuSE::PlaybackType::PLAYBACK_TYPE_SAMPLE && get_playback_type() == AuSE::PlaybackType::PLAYBACK_TYPE_DEFAULT) || get_playback_type() == AuSE::PlaybackType::PLAYBACK_TYPE_SAMPLE;+}+void AudioStreamPlayerInternal::process() {Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {@@ -337,11 +342,11 @@ Ref<AudioStreamPlayback> AudioStreamPlayerInternal::get_stream_playback() {return stream_playbacks[stream_playbacks.size() - 1];}-void AudioStreamPlayerInternal::set_playback_type(AudioServer::PlaybackType p_playback_type) {+void AudioStreamPlayerInternal::set_playback_type(AuSE::PlaybackType p_playback_type) {playback_type = p_playback_type;}-AudioServer::PlaybackType AudioStreamPlayerInternal::get_playback_type() const {+AuSE::PlaybackType AudioStreamPlayerInternal::get_playback_type() const {return playback_type;}diff --git a/scene/audio/audio_stream_player_internal.h b/scene/audio/audio_stream_player_internal.hindex bd7075d8514..6efe1af31fe 100644--- a/scene/audio/audio_stream_player_internal.h+++ b/scene/audio/audio_stream_player_internal.h@@ -32,7 +32,7 @@#include "core/object/ref_counted.h"#include "core/templates/safe_refcount.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_server_enums.h"class AudioStream;class AudioStreamPlayback;@@ -54,16 +54,14 @@ private:Callable play_callable;Callable stop_callable;bool physical = false;- AudioServer::PlaybackType playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT;+ AuSE::PlaybackType playback_type = AuSE::PlaybackType::PLAYBACK_TYPE_DEFAULT;HashMap<StringName, ParameterData> playback_parameters;void _set_process(bool p_enabled);void _update_stream_parameters();- _FORCE_INLINE_ bool _is_sample() {- return (AudioServer::get_singleton()->get_default_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_SAMPLE && get_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT) || get_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_SAMPLE;- }+ bool _is_sample();public:Vector<Ref<AudioStreamPlayback>> stream_playbacks;@@ -107,8 +105,8 @@ public:bool has_stream_playback();Ref<AudioStreamPlayback> get_stream_playback();- void set_playback_type(AudioServer::PlaybackType p_playback_type);- AudioServer::PlaybackType get_playback_type() const;+ void set_playback_type(AuSE::PlaybackType p_playback_type);+ AuSE::PlaybackType get_playback_type() const;AudioStreamPlayerInternal(Node *p_node, const Callable &p_play_callable, const Callable &p_stop_callable, bool p_physical);};diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cppindex ffd748c0462..f725e5cfbfb 100644--- a/scene/register_scene_types.cpp+++ b/scene/register_scene_types.cpp@@ -113,8 +113,11 @@#include "scene/main/window.h"#include "scene/resources/animation_library.h"#include "scene/resources/atlas_texture.h"-#include "scene/resources/audio_stream_polyphonic.h"-#include "scene/resources/audio_stream_wav.h"+#include "scene/resources/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream_microphone.h"+#include "scene/resources/audio/audio_stream_polyphonic.h"+#include "scene/resources/audio/audio_stream_randomizer.h"+#include "scene/resources/audio/audio_stream_wav.h"#include "scene/resources/bit_map.h"#include "scene/resources/blit_material.h"#include "scene/resources/bone_map.h"@@ -142,6 +145,7 @@#if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)#include "scene/resources/navigation_mesh.h"#endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)+#include "scene/resources/audio/audio_stream_generator.h"#include "scene/resources/dpi_texture.h"#include "scene/resources/packed_scene.h"#include "scene/resources/particle_process_material.h"@@ -1016,9 +1020,16 @@ void register_scene_types() {OS::get_singleton()->yield(); // may take time to init+ GDREGISTER_CLASS(AudioStream);+ GDREGISTER_CLASS(AudioStreamPlayback);+ GDREGISTER_VIRTUAL_CLASS(AudioStreamPlaybackResampled);GDREGISTER_CLASS(AudioStreamPlayer);GDREGISTER_CLASS(AudioStreamWAV);+ GDREGISTER_CLASS(AudioStreamMicrophone);GDREGISTER_CLASS(AudioStreamPolyphonic);+ GDREGISTER_CLASS(AudioStreamRandomizer);+ GDREGISTER_CLASS(AudioStreamGenerator);+ GDREGISTER_ABSTRACT_CLASS(AudioStreamGeneratorPlayback);GDREGISTER_ABSTRACT_CLASS(AudioStreamPlaybackPolyphonic);OS::get_singleton()->yield(); // may take time to initdiff --git a/scene/resources/SCsub b/scene/resources/SCsubindex 3b049700d7a..abbe049d976 100644--- a/scene/resources/SCsub+++ b/scene/resources/SCsub@@ -32,3 +32,4 @@ env.Depends(scene_obj, thirdparty_obj)SConscript("2d/SCsub")if not env["disable_3d"]:SConscript("3d/SCsub")+SConscript("audio/SCsub")diff --git a/scene/resources/audio/SCsub b/scene/resources/audio/SCsubnew file mode 100644index 00000000000..374dc2119dc--- /dev/null+++ b/scene/resources/audio/SCsub@@ -0,0 +1,6 @@+#!/usr/bin/env python+from misc.utility.scons_hints import *++Import("env")++env.add_source_files(env.scene_sources, "*.cpp")diff --git a/scene/resources/audio/audio_stream.cpp b/scene/resources/audio/audio_stream.cppnew file mode 100644index 00000000000..21fcba91bde--- /dev/null+++ b/scene/resources/audio/audio_stream.cpp@@ -0,0 +1,359 @@+/**************************************************************************/+/* audio_stream.cpp */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#include "audio_stream.h"++#include "core/config/project_settings.h"+#include "core/object/class_db.h"+#include "servers/audio/audio_driver.h"+#include "servers/audio/audio_server.h"++void AudioStreamPlayback::start(double p_from_pos) {+ GDVIRTUAL_CALL(_start, p_from_pos);+}++void AudioStreamPlayback::stop() {+ GDVIRTUAL_CALL(_stop);+}++bool AudioStreamPlayback::is_playing() const {+ bool ret = false;+ GDVIRTUAL_CALL(_is_playing, ret);+ return ret;+}++int AudioStreamPlayback::get_loop_count() const {+ int ret = 0;+ GDVIRTUAL_CALL(_get_loop_count, ret);+ return ret;+}++double AudioStreamPlayback::get_playback_position() const {+ double ret = 0.0;+ GDVIRTUAL_CALL(_get_playback_position, ret);+ return ret;+}++void AudioStreamPlayback::seek(double p_time) {+ GDVIRTUAL_CALL(_seek, p_time);+}++int AudioStreamPlayback::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {+ int ret = 0;+ GDVIRTUAL_CALL(_mix, p_buffer, p_rate_scale, p_frames, ret);+ return ret;+}++PackedVector2Array AudioStreamPlayback::_mix_audio_bind(float p_rate_scale, int p_frames) {+ Vector<AudioFrame> frames = mix_audio(p_rate_scale, p_frames);++ PackedVector2Array res;+ res.resize(frames.size());++ Vector2 *res_ptrw = res.ptrw();+ for (int i = 0; i < frames.size(); i++) {+ res_ptrw[i] = Vector2(frames[i].left, frames[i].right);+ }++ return res;+}++Vector<AudioFrame> AudioStreamPlayback::mix_audio(float p_rate_scale, int p_frames) {+ Vector<AudioFrame> res;+ res.resize(p_frames);++ int frames = mix(res.ptrw(), p_rate_scale, p_frames);+ res.resize(frames);++ return res;+}++void AudioStreamPlayback::start_playback(double p_from_pos) {+ start(p_from_pos);+}++void AudioStreamPlayback::stop_playback() {+ stop();+}++void AudioStreamPlayback::seek_playback(double p_time) {+ seek(p_time);+}++void AudioStreamPlayback::tag_used_streams() {+ GDVIRTUAL_CALL(_tag_used_streams);+}++void AudioStreamPlayback::set_parameter(const StringName &p_name, const Variant &p_value) {+ GDVIRTUAL_CALL(_set_parameter, p_name, p_value);+}++Variant AudioStreamPlayback::get_parameter(const StringName &p_name) const {+ Variant ret;+ GDVIRTUAL_CALL(_get_parameter, p_name, ret);+ return ret;+}++Ref<AudioSamplePlayback> AudioStreamPlayback::get_sample_playback() const {+ return nullptr;+}++void AudioStreamPlayback::_bind_methods() {+ GDVIRTUAL_BIND(_start, "from_pos")+ GDVIRTUAL_BIND(_stop)+ GDVIRTUAL_BIND(_is_playing)+ GDVIRTUAL_BIND(_get_loop_count)+ GDVIRTUAL_BIND(_get_playback_position)+ GDVIRTUAL_BIND(_seek, "position")+ GDVIRTUAL_BIND(_mix, "buffer", "rate_scale", "frames");+ GDVIRTUAL_BIND(_tag_used_streams);+ GDVIRTUAL_BIND(_set_parameter, "name", "value");+ GDVIRTUAL_BIND(_get_parameter, "name");++ ClassDB::bind_method(D_METHOD("set_sample_playback", "playback_sample"), &AudioStreamPlayback::set_sample_playback);+ ClassDB::bind_method(D_METHOD("get_sample_playback"), &AudioStreamPlayback::get_sample_playback);+ ClassDB::bind_method(D_METHOD("mix_audio", "rate_scale", "frames"), &AudioStreamPlayback::_mix_audio_bind);+ ClassDB::bind_method(D_METHOD("start", "from_pos"), &AudioStreamPlayback::start_playback, DEFVAL(0.0));+ ClassDB::bind_method(D_METHOD("seek", "time"), &AudioStreamPlayback::seek_playback, DEFVAL(0.0));+ ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayback::stop_playback);+ ClassDB::bind_method(D_METHOD("get_loop_count"), &AudioStreamPlayback::get_loop_count);+ ClassDB::bind_method(D_METHOD("get_playback_position"), &AudioStreamPlayback::get_playback_position);+ ClassDB::bind_method(D_METHOD("is_playing"), &AudioStreamPlayback::is_playing);+}++AudioStreamPlayback::AudioStreamPlayback() {}++AudioStreamPlayback::~AudioStreamPlayback() {+ if (get_sample_playback().is_valid() && likely(AudioServer::get_singleton() != nullptr)) {+ AudioServer::get_singleton()->stop_sample_playback(get_sample_playback());+ }+}++//////////////////////////////++void AudioStreamPlaybackResampled::begin_resample() {+ //clear cubic interpolation history+ internal_buffer[0] = AudioFrame(0.0, 0.0);+ internal_buffer[1] = AudioFrame(0.0, 0.0);+ internal_buffer[2] = AudioFrame(0.0, 0.0);+ internal_buffer[3] = AudioFrame(0.0, 0.0);+ //mix buffer+ _mix_internal(internal_buffer + 4, INTERNAL_BUFFER_LEN);+ mix_offset = 0;+}++int AudioStreamPlaybackResampled::_mix_internal(AudioFrame *p_buffer, int p_frames) {+ int ret = 0;+ GDVIRTUAL_CALL(_mix_resampled, p_buffer, p_frames, ret);+ return ret;+}+float AudioStreamPlaybackResampled::get_stream_sampling_rate() {+ float ret = 0;+ GDVIRTUAL_CALL(_get_stream_sampling_rate, ret);+ return ret;+}++void AudioStreamPlaybackResampled::_bind_methods() {+ ClassDB::bind_method(D_METHOD("begin_resample"), &AudioStreamPlaybackResampled::begin_resample);++ GDVIRTUAL_BIND(_mix_resampled, "dst_buffer", "frame_count");+ GDVIRTUAL_BIND(_get_stream_sampling_rate);+}++int AudioStreamPlaybackResampled::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {+ float target_rate = AudioServer::get_singleton()->get_mix_rate();+ float playback_speed_scale = AudioServer::get_singleton()->get_playback_speed_scale();++ uint64_t mix_increment = uint64_t(((get_stream_sampling_rate() * p_rate_scale * playback_speed_scale) / double(target_rate)) * double(FP_LEN));++ int mixed_frames_total = -1;++ int i;+ for (i = 0; i < p_frames; i++) {+ uint32_t idx = CUBIC_INTERP_HISTORY + uint32_t(mix_offset >> FP_BITS);+ //standard cubic interpolation (great quality/performance ratio)+ //this used to be moved to a LUT for greater performance, but nowadays CPU speed is generally faster than memory.+ float mu = (mix_offset & FP_MASK) / float(FP_LEN);+ AudioFrame y0 = internal_buffer[idx - 3];+ AudioFrame y1 = internal_buffer[idx - 2];+ AudioFrame y2 = internal_buffer[idx - 1];+ AudioFrame y3 = internal_buffer[idx - 0];++ if (idx >= internal_buffer_end && mixed_frames_total == -1) {+ // The internal buffer ends somewhere in this range, and we haven't yet recorded the number of good frames we have.+ mixed_frames_total = i;+ }++ float mu2 = mu * mu;+ float h11 = mu2 * (mu - 1);+ float z = mu2 - h11;+ float h01 = z - h11;+ float h10 = mu - z;++ p_buffer[i] = y1 + (y2 - y1) * h01 + ((y2 - y0) * h10 + (y3 - y1) * h11) * 0.5;++ mix_offset += mix_increment;++ while ((mix_offset >> FP_BITS) >= INTERNAL_BUFFER_LEN) {+ internal_buffer[0] = internal_buffer[INTERNAL_BUFFER_LEN + 0];+ internal_buffer[1] = internal_buffer[INTERNAL_BUFFER_LEN + 1];+ internal_buffer[2] = internal_buffer[INTERNAL_BUFFER_LEN + 2];+ internal_buffer[3] = internal_buffer[INTERNAL_BUFFER_LEN + 3];+ int mixed_frames = _mix_internal(internal_buffer + 4, INTERNAL_BUFFER_LEN);+ if (mixed_frames != INTERNAL_BUFFER_LEN) {+ // internal_buffer[mixed_frames] is the first frame of silence.+ internal_buffer_end = mixed_frames;+ } else {+ // The internal buffer does not contain the first frame of silence.+ internal_buffer_end = -1;+ }+ mix_offset -= (INTERNAL_BUFFER_LEN << FP_BITS);+ }+ }+ if (mixed_frames_total == -1 && i == p_frames) {+ mixed_frames_total = p_frames;+ }+ return mixed_frames_total;+}++////////////////////////////////++Ref<AudioStreamPlayback> AudioStream::instantiate_playback() {+ Ref<AudioStreamPlayback> ret;+ GDVIRTUAL_CALL(_instantiate_playback, ret);+ return ret;+}++double AudioStream::get_length() const {+ double ret = 0;+ GDVIRTUAL_CALL(_get_length, ret);+ return ret;+}++bool AudioStream::is_monophonic() const {+ bool ret = true;+ GDVIRTUAL_CALL(_is_monophonic, ret);+ return ret;+}++double AudioStream::get_bpm() const {+ double ret = 0;+ GDVIRTUAL_CALL(_get_bpm, ret);+ return ret;+}++bool AudioStream::has_loop() const {+ bool ret = false;+ GDVIRTUAL_CALL(_has_loop, ret);+ return ret;+}++int AudioStream::get_bar_beats() const {+ int ret = 0;+ GDVIRTUAL_CALL(_get_bar_beats, ret);+ return ret;+}++int AudioStream::get_beat_count() const {+ int ret = 0;+ GDVIRTUAL_CALL(_get_beat_count, ret);+ return ret;+}++Dictionary AudioStream::get_tags() const {+ Dictionary ret;+ GDVIRTUAL_CALL(_get_tags, ret);+ return ret;+}++void AudioStream::tag_used(float p_offset) {+ if (tagged_frame != AudioServer::get_singleton()->get_mixed_frames()) {+ offset_count = 0;+ tagged_frame = AudioServer::get_singleton()->get_mixed_frames();+ }+ if (offset_count < MAX_TAGGED_OFFSETS) {+ tagged_offsets[offset_count++] = p_offset;+ }+}++uint64_t AudioStream::get_tagged_frame() const {+ return tagged_frame;+}++uint32_t AudioStream::get_tagged_frame_count() const {+ return offset_count;+}++float AudioStream::get_tagged_frame_offset(int p_index) const {+ ERR_FAIL_INDEX_V(p_index, MAX_TAGGED_OFFSETS, 0);+ return tagged_offsets[p_index];+}++void AudioStream::get_parameter_list(List<Parameter> *r_parameters) {+ TypedArray<Dictionary> ret;+ GDVIRTUAL_CALL(_get_parameter_list, ret);+ for (int i = 0; i < ret.size(); i++) {+ Dictionary d = ret[i];+ ERR_CONTINUE(!d.has("default_value"));+ r_parameters->push_back(Parameter(PropertyInfo::from_dict(d), d["default_value"]));+ }+}++Ref<AudioSample> AudioStream::generate_sample() const {+ ERR_FAIL_COND_V_MSG(!can_be_sampled(), nullptr, "Cannot generate a sample for a stream that cannot be sampled.");+ Ref<AudioSample> sample;+ sample.instantiate();+ sample->stream = this;+ return sample;+}++void AudioStream::_bind_methods() {+ ClassDB::bind_method(D_METHOD("get_length"), &AudioStream::get_length);+ ClassDB::bind_method(D_METHOD("is_monophonic"), &AudioStream::is_monophonic);+ ClassDB::bind_method(D_METHOD("instantiate_playback"), &AudioStream::instantiate_playback);+ ClassDB::bind_method(D_METHOD("can_be_sampled"), &AudioStream::can_be_sampled);+ ClassDB::bind_method(D_METHOD("generate_sample"), &AudioStream::generate_sample);+ ClassDB::bind_method(D_METHOD("is_meta_stream"), &AudioStream::is_meta_stream);++ GDVIRTUAL_BIND(_instantiate_playback);+#ifndef DISABLE_DEPRECATED+ GDVIRTUAL_BIND(_get_stream_name);+#endif+ GDVIRTUAL_BIND(_get_length);+ GDVIRTUAL_BIND(_is_monophonic);+ GDVIRTUAL_BIND(_get_bpm)+ GDVIRTUAL_BIND(_get_beat_count)+ GDVIRTUAL_BIND(_get_tags);+ GDVIRTUAL_BIND(_get_parameter_list)+ GDVIRTUAL_BIND(_has_loop);+ GDVIRTUAL_BIND(_get_bar_beats);++ ADD_SIGNAL(MethodInfo("parameter_list_changed"));+}diff --git a/servers/audio/audio_stream.h b/scene/resources/audio/audio_stream.hsimilarity index 59%rename from servers/audio/audio_stream.hrename to scene/resources/audio/audio_stream.hindex d9ec96fefa3..c2a3ac674cb 100644--- a/servers/audio/audio_stream.h+++ b/scene/resources/audio/audio_stream.h@@ -34,10 +34,10 @@#include "core/object/gdvirtual.gen.h"#include "core/variant/native_ptr.h"#include "core/variant/typed_array.h"-#include "scene/property_list_helper.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_frame.h"class AudioStream;+class AudioStreamPlayback;class AudioSamplePlayback : public RefCounted {GDCLASS(AudioSamplePlayback, RefCounted);@@ -215,163 +215,3 @@ public:virtual bool is_meta_stream() const { return false; }};--// Microphone--class AudioStreamPlaybackMicrophone;--class AudioStreamMicrophone : public AudioStream {- GDCLASS(AudioStreamMicrophone, AudioStream);- friend class AudioStreamPlaybackMicrophone;-- HashSet<AudioStreamPlaybackMicrophone *> playbacks;--public:- virtual Ref<AudioStreamPlayback> instantiate_playback() override;-- virtual double get_length() const override; //if supported, otherwise return 0-- virtual bool is_monophonic() const override;-};--class AudioStreamPlaybackMicrophone : public AudioStreamPlaybackResampled {- GDCLASS(AudioStreamPlaybackMicrophone, AudioStreamPlaybackResampled);- friend class AudioStreamMicrophone;-- bool active = false;- unsigned int input_ofs = 0;-- Ref<AudioStreamMicrophone> microphone;--protected:- virtual int _mix_internal(AudioFrame *p_buffer, int p_frames) override;- virtual float get_stream_sampling_rate() override;- virtual double get_playback_position() const override;--public:- virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override;-- virtual void start(double p_from_pos = 0.0) override;- virtual void stop() override;- virtual bool is_playing() const override;-- virtual int get_loop_count() const override; //times it looped-- virtual void seek(double p_time) override;-- virtual void tag_used_streams() override;-- ~AudioStreamPlaybackMicrophone();- AudioStreamPlaybackMicrophone();-};--//--class AudioStreamPlaybackRandomizer;--class AudioStreamRandomizer : public AudioStream {- GDCLASS(AudioStreamRandomizer, AudioStream);--public:- enum PlaybackMode {- PLAYBACK_RANDOM_NO_REPEATS,- PLAYBACK_RANDOM,- PLAYBACK_SEQUENTIAL,- };--private:- friend class AudioStreamPlaybackRandomizer;-- struct PoolEntry {- Ref<AudioStream> stream;- float weight = 1.0;- };-- static inline PropertyListHelper base_property_helper;- PropertyListHelper property_helper;-- HashSet<AudioStreamPlaybackRandomizer *> playbacks;- Vector<PoolEntry> audio_stream_pool;- float random_pitch_scale = 1.0f;- float random_volume_offset_db = 0.0f;-- Ref<AudioStreamPlayback> instance_playback_random();- Ref<AudioStreamPlayback> instance_playback_no_repeats();- Ref<AudioStreamPlayback> instance_playback_sequential();-- Ref<AudioStream> last_playback = nullptr;- PlaybackMode playback_mode = PLAYBACK_RANDOM_NO_REPEATS;--protected:- static void _bind_methods();-- bool _set(const StringName &p_name, const Variant &p_value) { return property_helper.property_set_value(p_name, p_value); }- bool _get(const StringName &p_name, Variant &r_ret) const { return property_helper.property_get_value(p_name, r_ret); }- void _get_property_list(List<PropertyInfo> *p_list) const { property_helper.get_property_list(p_list); }- bool _property_can_revert(const StringName &p_name) const { return property_helper.property_can_revert(p_name); }- bool _property_get_revert(const StringName &p_name, Variant &r_property) const { return property_helper.property_get_revert(p_name, r_property); }--public:- void add_stream(int p_index, Ref<AudioStream> p_stream, float p_weight = 1.0);- void move_stream(int p_index_from, int p_index_to);- void remove_stream(int p_index);-- void set_stream(int p_index, Ref<AudioStream> p_stream);- Ref<AudioStream> get_stream(int p_index) const;- void set_stream_probability_weight(int p_index, float p_weight);- float get_stream_probability_weight(int p_index) const;-- void set_streams_count(int p_count);- int get_streams_count() const;-- void set_random_pitch_semitones(float p_pitch_semitones);- float get_random_pitch_semitones() const;-- void set_random_pitch(float p_pitch_scale);- float get_random_pitch() const;-- void set_random_volume_offset_db(float p_volume_offset_db);- float get_random_volume_offset_db() const;-- void set_playback_mode(PlaybackMode p_playback_mode);- PlaybackMode get_playback_mode() const;-- virtual Ref<AudioStreamPlayback> instantiate_playback() override;-- virtual double get_length() const override; //if supported, otherwise return 0- virtual bool is_monophonic() const override;-- virtual bool is_meta_stream() const override { return true; }-- AudioStreamRandomizer();-};--class AudioStreamPlaybackRandomizer : public AudioStreamPlayback {- GDCLASS(AudioStreamPlaybackRandomizer, AudioStreamPlayback);- friend class AudioStreamRandomizer;-- Ref<AudioStreamRandomizer> randomizer;- Ref<AudioStreamPlayback> playback;- Ref<AudioStreamPlayback> playing;-- float pitch_scale;- float volume_scale;--public:- virtual void start(double p_from_pos = 0.0) override;- virtual void stop() override;- virtual bool is_playing() const override;-- virtual int get_loop_count() const override; //times it looped-- virtual double get_playback_position() const override;- virtual void seek(double p_time) override;-- virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override;-- virtual void tag_used_streams() override;-- ~AudioStreamPlaybackRandomizer();-};--VARIANT_ENUM_CAST(AudioStreamRandomizer::PlaybackMode);diff --git a/servers/audio/effects/audio_stream_generator.cpp b/scene/resources/audio/audio_stream_generator.cppsimilarity index 99%rename from servers/audio/effects/audio_stream_generator.cpprename to scene/resources/audio/audio_stream_generator.cppindex b282cc3138f..de3cceaf0d0 100644--- a/servers/audio/effects/audio_stream_generator.cpp+++ b/scene/resources/audio/audio_stream_generator.cpp@@ -31,6 +31,7 @@#include "audio_stream_generator.h"#include "core/object/class_db.h"+#include "servers/audio/audio_server.h"void AudioStreamGenerator::set_mix_rate(float p_mix_rate) {mix_rate = p_mix_rate;diff --git a/servers/audio/effects/audio_stream_generator.h b/scene/resources/audio/audio_stream_generator.hsimilarity index 98%rename from servers/audio/effects/audio_stream_generator.hrename to scene/resources/audio/audio_stream_generator.hindex 724e518bd49..36e4705de3c 100644--- a/servers/audio/effects/audio_stream_generator.h+++ b/scene/resources/audio/audio_stream_generator.h@@ -31,7 +31,7 @@#pragma once#include "core/templates/ring_buffer.h"-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"class AudioStreamGenerator : public AudioStream {GDCLASS(AudioStreamGenerator, AudioStream);diff --git a/scene/resources/audio/audio_stream_microphone.cpp b/scene/resources/audio/audio_stream_microphone.cppnew file mode 100644index 00000000000..ae15e8947ff--- /dev/null+++ b/scene/resources/audio/audio_stream_microphone.cpp@@ -0,0 +1,158 @@+/**************************************************************************/+/* audio_stream_microphone.cpp */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#include "audio_stream_microphone.h"++#include "servers/audio/audio_driver.h"+#include "servers/audio/audio_server.h"++Ref<AudioStreamPlayback> AudioStreamMicrophone::instantiate_playback() {+ Ref<AudioStreamPlaybackMicrophone> playback;+ playback.instantiate();++ playbacks.insert(playback.ptr());++ playback->microphone = Ref<AudioStreamMicrophone>((AudioStreamMicrophone *)this);+ playback->active = false;++ return playback;+}++double AudioStreamMicrophone::get_length() const {+ return 0;+}++bool AudioStreamMicrophone::is_monophonic() const {+ return true;+}++int AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_frames) {+ AudioDriver::get_singleton()->lock();++ Vector<int32_t> buf = AudioDriver::get_singleton()->get_input_buffer();+ unsigned int input_size = AudioDriver::get_singleton()->get_input_size();+ int mix_rate = AudioDriver::get_singleton()->get_input_mix_rate();+ unsigned int playback_delay = MIN(((50 * mix_rate) / 1000) * 2, buf.size() >> 1);+#ifdef DEBUG_ENABLED+ unsigned int input_position = AudioDriver::get_singleton()->get_input_position();+#endif++ int mixed_frames = p_frames;++ if (playback_delay > input_size) {+ for (int i = 0; i < p_frames; i++) {+ p_buffer[i] = AudioFrame(0.0f, 0.0f);+ }+ input_ofs = 0;+ } else {+ for (int i = 0; i < p_frames; i++) {+ if (input_size > input_ofs && (int)input_ofs < buf.size()) {+ float l = (buf[input_ofs++] >> 16) / 32768.f;+ if ((int)input_ofs >= buf.size()) {+ input_ofs = 0;+ }+ float r = (buf[input_ofs++] >> 16) / 32768.f;+ if ((int)input_ofs >= buf.size()) {+ input_ofs = 0;+ }++ p_buffer[i] = AudioFrame(l, r);+ } else {+ p_buffer[i] = AudioFrame(0.0f, 0.0f);+ }+ }+ }++#ifdef DEBUG_ENABLED+ if (input_ofs > input_position && (int)(input_ofs - input_position) < (p_frames * 2)) {+ print_verbose(String(get_class_name()) + " buffer underrun: input_position=" + itos(input_position) + " input_ofs=" + itos(input_ofs) + " input_size=" + itos(input_size));+ }+#endif++ AudioDriver::get_singleton()->unlock();++ return mixed_frames;+}++int AudioStreamPlaybackMicrophone::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {+ return AudioStreamPlaybackResampled::mix(p_buffer, p_rate_scale, p_frames);+}++float AudioStreamPlaybackMicrophone::get_stream_sampling_rate() {+ return AudioDriver::get_singleton()->get_input_mix_rate();+}++void AudioStreamPlaybackMicrophone::start(double p_from_pos) {+ if (active) {+ return;+ }++ input_ofs = 0;++ if (AudioServer::get_singleton()->set_input_device_active(true) == OK) {+ active = true;+ begin_resample();+ }+}++void AudioStreamPlaybackMicrophone::stop() {+ if (active) {+ AudioServer::get_singleton()->set_input_device_active(false);+ active = false;+ }+}++bool AudioStreamPlaybackMicrophone::is_playing() const {+ return active;+}++int AudioStreamPlaybackMicrophone::get_loop_count() const {+ return 0;+}++double AudioStreamPlaybackMicrophone::get_playback_position() const {+ return 0;+}++void AudioStreamPlaybackMicrophone::seek(double p_time) {+ // Can't seek a microphone input+}++void AudioStreamPlaybackMicrophone::tag_used_streams() {+ microphone->tag_used(0);+}++AudioStreamPlaybackMicrophone::~AudioStreamPlaybackMicrophone() {+ microphone->playbacks.erase(this);+ stop();+}++AudioStreamPlaybackMicrophone::AudioStreamPlaybackMicrophone() {+}diff --git a/scene/resources/audio/audio_stream_microphone.h b/scene/resources/audio/audio_stream_microphone.hnew file mode 100644index 00000000000..cc35d48641d--- /dev/null+++ b/scene/resources/audio/audio_stream_microphone.h@@ -0,0 +1,80 @@+/**************************************************************************/+/* audio_stream_microphone.h */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#pragma once++#include "scene/resources/audio/audio_stream.h"++class AudioStreamPlaybackMicrophone;++class AudioStreamMicrophone : public AudioStream {+ GDCLASS(AudioStreamMicrophone, AudioStream);+ friend class AudioStreamPlaybackMicrophone;++ HashSet<AudioStreamPlaybackMicrophone *> playbacks;++public:+ virtual Ref<AudioStreamPlayback> instantiate_playback() override;++ virtual double get_length() const override; //if supported, otherwise return 0++ virtual bool is_monophonic() const override;+};++class AudioStreamPlaybackMicrophone : public AudioStreamPlaybackResampled {+ GDCLASS(AudioStreamPlaybackMicrophone, AudioStreamPlaybackResampled);+ friend class AudioStreamMicrophone;++ bool active = false;+ unsigned int input_ofs = 0;++ Ref<AudioStreamMicrophone> microphone;++protected:+ virtual int _mix_internal(AudioFrame *p_buffer, int p_frames) override;+ virtual float get_stream_sampling_rate() override;+ virtual double get_playback_position() const override;++public:+ virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override;++ virtual void start(double p_from_pos = 0.0) override;+ virtual void stop() override;+ virtual bool is_playing() const override;++ virtual int get_loop_count() const override; //times it looped++ virtual void seek(double p_time) override;++ virtual void tag_used_streams() override;++ ~AudioStreamPlaybackMicrophone();+ AudioStreamPlaybackMicrophone();+};diff --git a/scene/resources/audio_stream_polyphonic.compat.inc b/scene/resources/audio/audio_stream_polyphonic.compat.incsimilarity index 96%rename from scene/resources/audio_stream_polyphonic.compat.increname to scene/resources/audio/audio_stream_polyphonic.compat.incindex ab4ec1917ca..be19ec59535 100644--- a/scene/resources/audio_stream_polyphonic.compat.inc+++ b/scene/resources/audio/audio_stream_polyphonic.compat.inc@@ -35,7 +35,7 @@#include "core/object/class_db.h"AudioStreamPlaybackPolyphonic::ID AudioStreamPlaybackPolyphonic::_play_stream_bind_compat_91382(const Ref<AudioStream> &p_stream, float p_from_offset, float p_volume_db, float p_pitch_scale) {- return play_stream(p_stream, p_from_offset, p_volume_db, p_pitch_scale, AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT, SceneStringName(Master));+ return play_stream(p_stream, p_from_offset, p_volume_db, p_pitch_scale, AudioServerEnums::PlaybackType::PLAYBACK_TYPE_DEFAULT, SceneStringName(Master));}void AudioStreamPlaybackPolyphonic::_bind_compatibility_methods() {diff --git a/scene/resources/audio_stream_polyphonic.cpp b/scene/resources/audio/audio_stream_polyphonic.cppsimilarity index 97%rename from scene/resources/audio_stream_polyphonic.cpprename to scene/resources/audio/audio_stream_polyphonic.cppindex e0916de21a8..e355ea55897 100644--- a/scene/resources/audio_stream_polyphonic.cpp+++ b/scene/resources/audio/audio_stream_polyphonic.cpp@@ -205,10 +205,10 @@ int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale,return p_frames;}-AudioStreamPlaybackPolyphonic::ID AudioStreamPlaybackPolyphonic::play_stream(const Ref<AudioStream> &p_stream, float p_from_offset, float p_volume_db, float p_pitch_scale, AudioServer::PlaybackType p_playback_type, const StringName &p_bus) {+AudioStreamPlaybackPolyphonic::ID AudioStreamPlaybackPolyphonic::play_stream(const Ref<AudioStream> &p_stream, float p_from_offset, float p_volume_db, float p_pitch_scale, AuSE::PlaybackType p_playback_type, const StringName &p_bus) {ERR_FAIL_COND_V(p_stream.is_null(), INVALID_ID);- AudioServer::PlaybackType playback_type = p_playback_type == AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT+ AuSE::PlaybackType playback_type = p_playback_type == AuSE::PlaybackType::PLAYBACK_TYPE_DEFAULT? AudioServer::get_singleton()->get_default_playback_type(): p_playback_type;@@ -234,7 +234,7 @@ AudioStreamPlaybackPolyphonic::ID AudioStreamPlaybackPolyphonic::play_stream(constreams[i].active.set();// Sample playback.- if (playback_type == AudioServer::PlaybackType::PLAYBACK_TYPE_SAMPLE && p_stream->can_be_sampled()) {+ if (playback_type == AuSE::PlaybackType::PLAYBACK_TYPE_SAMPLE && p_stream->can_be_sampled()) {streams[i].stream_playback->set_is_sample(true);if (!AudioServer::get_singleton()->is_stream_registered_as_sample(p_stream)) {AudioServer::get_singleton()->register_stream_as_sample(p_stream);diff --git a/scene/resources/audio_stream_polyphonic.h b/scene/resources/audio/audio_stream_polyphonic.hsimilarity index 93%rename from scene/resources/audio_stream_polyphonic.hrename to scene/resources/audio/audio_stream_polyphonic.hindex bff9c20b33e..34e5e2d40c2 100644--- a/scene/resources/audio_stream_polyphonic.h+++ b/scene/resources/audio/audio_stream_polyphonic.h@@ -31,15 +31,15 @@#pragma once#include "core/templates/local_vector.h"+#include "scene/resources/audio/audio_stream.h"#include "scene/scene_string_names.h"-#include "servers/audio/audio_server.h"-#include "servers/audio/audio_stream.h"+#include "servers/audio/audio_server_enums.h"class AudioStreamPolyphonic : public AudioStream {GDCLASS(AudioStreamPolyphonic, AudioStream)int polyphony = 32;- AudioServer::PlaybackType playback_type;+ AuSE::PlaybackType playback_type;static void _bind_methods();@@ -112,7 +112,7 @@ public:virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override;- ID play_stream(const Ref<AudioStream> &p_stream, float p_from_offset = 0, float p_volume_db = 0, float p_pitch_scale = 1.0, AudioServer::PlaybackType p_playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT, const StringName &p_bus = SceneStringName(Master));+ ID play_stream(const Ref<AudioStream> &p_stream, float p_from_offset = 0, float p_volume_db = 0, float p_pitch_scale = 1.0, AuSE::PlaybackType p_playback_type = AuSE::PlaybackType::PLAYBACK_TYPE_DEFAULT, const StringName &p_bus = SceneStringName(Master));void set_stream_volume(ID p_stream_id, float p_volume_db);void set_stream_pitch_scale(ID p_stream_id, float p_pitch_scale);bool is_stream_playing(ID p_stream_id) const;diff --git a/servers/audio/audio_stream.cpp b/scene/resources/audio/audio_stream_randomizer.cppsimilarity index 54%rename from servers/audio/audio_stream.cpprename to scene/resources/audio/audio_stream_randomizer.cppindex 3e2566e77b4..4ddfba7dc0a 100644--- a/servers/audio/audio_stream.cpp+++ b/scene/resources/audio/audio_stream_randomizer.cpp@@ -1,5 +1,5 @@/**************************************************************************/-/* audio_stream.cpp */+/* audio_stream_randomizer.cpp *//**************************************************************************//* This file is part of: *//* GODOT ENGINE */@@ -28,456 +28,10 @@/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//**************************************************************************/-#include "audio_stream.h"+#include "audio_stream_randomizer.h"-#include "core/config/project_settings.h"#include "core/object/class_db.h"-void AudioStreamPlayback::start(double p_from_pos) {- GDVIRTUAL_CALL(_start, p_from_pos);-}-void AudioStreamPlayback::stop() {- GDVIRTUAL_CALL(_stop);-}-bool AudioStreamPlayback::is_playing() const {- bool ret = false;- GDVIRTUAL_CALL(_is_playing, ret);- return ret;-}--int AudioStreamPlayback::get_loop_count() const {- int ret = 0;- GDVIRTUAL_CALL(_get_loop_count, ret);- return ret;-}--double AudioStreamPlayback::get_playback_position() const {- double ret = 0.0;- GDVIRTUAL_CALL(_get_playback_position, ret);- return ret;-}-void AudioStreamPlayback::seek(double p_time) {- GDVIRTUAL_CALL(_seek, p_time);-}--int AudioStreamPlayback::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {- int ret = 0;- GDVIRTUAL_CALL(_mix, p_buffer, p_rate_scale, p_frames, ret);- return ret;-}--PackedVector2Array AudioStreamPlayback::_mix_audio_bind(float p_rate_scale, int p_frames) {- Vector<AudioFrame> frames = mix_audio(p_rate_scale, p_frames);-- PackedVector2Array res;- res.resize(frames.size());-- Vector2 *res_ptrw = res.ptrw();- for (int i = 0; i < frames.size(); i++) {- res_ptrw[i] = Vector2(frames[i].left, frames[i].right);- }-- return res;-}--Vector<AudioFrame> AudioStreamPlayback::mix_audio(float p_rate_scale, int p_frames) {- Vector<AudioFrame> res;- res.resize(p_frames);-- int frames = mix(res.ptrw(), p_rate_scale, p_frames);- res.resize(frames);-- return res;-}--void AudioStreamPlayback::start_playback(double p_from_pos) {- start(p_from_pos);-}--void AudioStreamPlayback::stop_playback() {- stop();-}--void AudioStreamPlayback::seek_playback(double p_time) {- seek(p_time);-}--void AudioStreamPlayback::tag_used_streams() {- GDVIRTUAL_CALL(_tag_used_streams);-}--void AudioStreamPlayback::set_parameter(const StringName &p_name, const Variant &p_value) {- GDVIRTUAL_CALL(_set_parameter, p_name, p_value);-}--Variant AudioStreamPlayback::get_parameter(const StringName &p_name) const {- Variant ret;- GDVIRTUAL_CALL(_get_parameter, p_name, ret);- return ret;-}--Ref<AudioSamplePlayback> AudioStreamPlayback::get_sample_playback() const {- return nullptr;-}--void AudioStreamPlayback::_bind_methods() {- GDVIRTUAL_BIND(_start, "from_pos")- GDVIRTUAL_BIND(_stop)- GDVIRTUAL_BIND(_is_playing)- GDVIRTUAL_BIND(_get_loop_count)- GDVIRTUAL_BIND(_get_playback_position)- GDVIRTUAL_BIND(_seek, "position")- GDVIRTUAL_BIND(_mix, "buffer", "rate_scale", "frames");- GDVIRTUAL_BIND(_tag_used_streams);- GDVIRTUAL_BIND(_set_parameter, "name", "value");- GDVIRTUAL_BIND(_get_parameter, "name");-- ClassDB::bind_method(D_METHOD("set_sample_playback", "playback_sample"), &AudioStreamPlayback::set_sample_playback);- ClassDB::bind_method(D_METHOD("get_sample_playback"), &AudioStreamPlayback::get_sample_playback);- ClassDB::bind_method(D_METHOD("mix_audio", "rate_scale", "frames"), &AudioStreamPlayback::_mix_audio_bind);- ClassDB::bind_method(D_METHOD("start", "from_pos"), &AudioStreamPlayback::start_playback, DEFVAL(0.0));- ClassDB::bind_method(D_METHOD("seek", "time"), &AudioStreamPlayback::seek_playback, DEFVAL(0.0));- ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayback::stop_playback);- ClassDB::bind_method(D_METHOD("get_loop_count"), &AudioStreamPlayback::get_loop_count);- ClassDB::bind_method(D_METHOD("get_playback_position"), &AudioStreamPlayback::get_playback_position);- ClassDB::bind_method(D_METHOD("is_playing"), &AudioStreamPlayback::is_playing);-}--AudioStreamPlayback::AudioStreamPlayback() {}--AudioStreamPlayback::~AudioStreamPlayback() {- if (get_sample_playback().is_valid() && likely(AudioServer::get_singleton() != nullptr)) {- AudioServer::get_singleton()->stop_sample_playback(get_sample_playback());- }-}-//////////////////////////////--void AudioStreamPlaybackResampled::begin_resample() {- //clear cubic interpolation history- internal_buffer[0] = AudioFrame(0.0, 0.0);- internal_buffer[1] = AudioFrame(0.0, 0.0);- internal_buffer[2] = AudioFrame(0.0, 0.0);- internal_buffer[3] = AudioFrame(0.0, 0.0);- //mix buffer- _mix_internal(internal_buffer + 4, INTERNAL_BUFFER_LEN);- mix_offset = 0;-}--int AudioStreamPlaybackResampled::_mix_internal(AudioFrame *p_buffer, int p_frames) {- int ret = 0;- GDVIRTUAL_CALL(_mix_resampled, p_buffer, p_frames, ret);- return ret;-}-float AudioStreamPlaybackResampled::get_stream_sampling_rate() {- float ret = 0;- GDVIRTUAL_CALL(_get_stream_sampling_rate, ret);- return ret;-}--void AudioStreamPlaybackResampled::_bind_methods() {- ClassDB::bind_method(D_METHOD("begin_resample"), &AudioStreamPlaybackResampled::begin_resample);-- GDVIRTUAL_BIND(_mix_resampled, "dst_buffer", "frame_count");- GDVIRTUAL_BIND(_get_stream_sampling_rate);-}--int AudioStreamPlaybackResampled::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {- float target_rate = AudioServer::get_singleton()->get_mix_rate();- float playback_speed_scale = AudioServer::get_singleton()->get_playback_speed_scale();-- uint64_t mix_increment = uint64_t(((get_stream_sampling_rate() * p_rate_scale * playback_speed_scale) / double(target_rate)) * double(FP_LEN));-- int mixed_frames_total = -1;-- int i;- for (i = 0; i < p_frames; i++) {- uint32_t idx = CUBIC_INTERP_HISTORY + uint32_t(mix_offset >> FP_BITS);- //standard cubic interpolation (great quality/performance ratio)- //this used to be moved to a LUT for greater performance, but nowadays CPU speed is generally faster than memory.- float mu = (mix_offset & FP_MASK) / float(FP_LEN);- AudioFrame y0 = internal_buffer[idx - 3];- AudioFrame y1 = internal_buffer[idx - 2];- AudioFrame y2 = internal_buffer[idx - 1];- AudioFrame y3 = internal_buffer[idx - 0];-- if (idx >= internal_buffer_end && mixed_frames_total == -1) {- // The internal buffer ends somewhere in this range, and we haven't yet recorded the number of good frames we have.- mixed_frames_total = i;- }-- float mu2 = mu * mu;- float h11 = mu2 * (mu - 1);- float z = mu2 - h11;- float h01 = z - h11;- float h10 = mu - z;-- p_buffer[i] = y1 + (y2 - y1) * h01 + ((y2 - y0) * h10 + (y3 - y1) * h11) * 0.5;-- mix_offset += mix_increment;-- while ((mix_offset >> FP_BITS) >= INTERNAL_BUFFER_LEN) {- internal_buffer[0] = internal_buffer[INTERNAL_BUFFER_LEN + 0];- internal_buffer[1] = internal_buffer[INTERNAL_BUFFER_LEN + 1];- internal_buffer[2] = internal_buffer[INTERNAL_BUFFER_LEN + 2];- internal_buffer[3] = internal_buffer[INTERNAL_BUFFER_LEN + 3];- int mixed_frames = _mix_internal(internal_buffer + 4, INTERNAL_BUFFER_LEN);- if (mixed_frames != INTERNAL_BUFFER_LEN) {- // internal_buffer[mixed_frames] is the first frame of silence.- internal_buffer_end = mixed_frames;- } else {- // The internal buffer does not contain the first frame of silence.- internal_buffer_end = -1;- }- mix_offset -= (INTERNAL_BUFFER_LEN << FP_BITS);- }- }- if (mixed_frames_total == -1 && i == p_frames) {- mixed_frames_total = p_frames;- }- return mixed_frames_total;-}--////////////////////////////////--Ref<AudioStreamPlayback> AudioStream::instantiate_playback() {- Ref<AudioStreamPlayback> ret;- GDVIRTUAL_CALL(_instantiate_playback, ret);- return ret;-}--double AudioStream::get_length() const {- double ret = 0;- GDVIRTUAL_CALL(_get_length, ret);- return ret;-}--bool AudioStream::is_monophonic() const {- bool ret = true;- GDVIRTUAL_CALL(_is_monophonic, ret);- return ret;-}--double AudioStream::get_bpm() const {- double ret = 0;- GDVIRTUAL_CALL(_get_bpm, ret);- return ret;-}--bool AudioStream::has_loop() const {- bool ret = false;- GDVIRTUAL_CALL(_has_loop, ret);- return ret;-}--int AudioStream::get_bar_beats() const {- int ret = 0;- GDVIRTUAL_CALL(_get_bar_beats, ret);- return ret;-}--int AudioStream::get_beat_count() const {- int ret = 0;- GDVIRTUAL_CALL(_get_beat_count, ret);- return ret;-}--Dictionary AudioStream::get_tags() const {- Dictionary ret;- GDVIRTUAL_CALL(_get_tags, ret);- return ret;-}--void AudioStream::tag_used(float p_offset) {- if (tagged_frame != AudioServer::get_singleton()->get_mixed_frames()) {- offset_count = 0;- tagged_frame = AudioServer::get_singleton()->get_mixed_frames();- }- if (offset_count < MAX_TAGGED_OFFSETS) {- tagged_offsets[offset_count++] = p_offset;- }-}--uint64_t AudioStream::get_tagged_frame() const {- return tagged_frame;-}-uint32_t AudioStream::get_tagged_frame_count() const {- return offset_count;-}-float AudioStream::get_tagged_frame_offset(int p_index) const {- ERR_FAIL_INDEX_V(p_index, MAX_TAGGED_OFFSETS, 0);- return tagged_offsets[p_index];-}--void AudioStream::get_parameter_list(List<Parameter> *r_parameters) {- TypedArray<Dictionary> ret;- GDVIRTUAL_CALL(_get_parameter_list, ret);- for (int i = 0; i < ret.size(); i++) {- Dictionary d = ret[i];- ERR_CONTINUE(!d.has("default_value"));- r_parameters->push_back(Parameter(PropertyInfo::from_dict(d), d["default_value"]));- }-}--Ref<AudioSample> AudioStream::generate_sample() const {- ERR_FAIL_COND_V_MSG(!can_be_sampled(), nullptr, "Cannot generate a sample for a stream that cannot be sampled.");- Ref<AudioSample> sample;- sample.instantiate();- sample->stream = this;- return sample;-}--void AudioStream::_bind_methods() {- ClassDB::bind_method(D_METHOD("get_length"), &AudioStream::get_length);- ClassDB::bind_method(D_METHOD("is_monophonic"), &AudioStream::is_monophonic);- ClassDB::bind_method(D_METHOD("instantiate_playback"), &AudioStream::instantiate_playback);- ClassDB::bind_method(D_METHOD("can_be_sampled"), &AudioStream::can_be_sampled);- ClassDB::bind_method(D_METHOD("generate_sample"), &AudioStream::generate_sample);- ClassDB::bind_method(D_METHOD("is_meta_stream"), &AudioStream::is_meta_stream);-- GDVIRTUAL_BIND(_instantiate_playback);-#ifndef DISABLE_DEPRECATED- GDVIRTUAL_BIND(_get_stream_name);-#endif- GDVIRTUAL_BIND(_get_length);- GDVIRTUAL_BIND(_is_monophonic);- GDVIRTUAL_BIND(_get_bpm)- GDVIRTUAL_BIND(_get_beat_count)- GDVIRTUAL_BIND(_get_tags);- GDVIRTUAL_BIND(_get_parameter_list)- GDVIRTUAL_BIND(_has_loop);- GDVIRTUAL_BIND(_get_bar_beats);-- ADD_SIGNAL(MethodInfo("parameter_list_changed"));-}--////////////////////////////////--Ref<AudioStreamPlayback> AudioStreamMicrophone::instantiate_playback() {- Ref<AudioStreamPlaybackMicrophone> playback;- playback.instantiate();-- playbacks.insert(playback.ptr());-- playback->microphone = Ref<AudioStreamMicrophone>((AudioStreamMicrophone *)this);- playback->active = false;-- return playback;-}--double AudioStreamMicrophone::get_length() const {- return 0;-}--bool AudioStreamMicrophone::is_monophonic() const {- return true;-}--int AudioStreamPlaybackMicrophone::_mix_internal(AudioFrame *p_buffer, int p_frames) {- AudioDriver::get_singleton()->lock();-- Vector<int32_t> buf = AudioDriver::get_singleton()->get_input_buffer();- unsigned int input_size = AudioDriver::get_singleton()->get_input_size();- int mix_rate = AudioDriver::get_singleton()->get_input_mix_rate();- unsigned int playback_delay = MIN(((50 * mix_rate) / 1000) * 2, buf.size() >> 1);-#ifdef DEBUG_ENABLED- unsigned int input_position = AudioDriver::get_singleton()->get_input_position();-#endif-- int mixed_frames = p_frames;-- if (playback_delay > input_size) {- for (int i = 0; i < p_frames; i++) {- p_buffer[i] = AudioFrame(0.0f, 0.0f);- }- input_ofs = 0;- } else {- for (int i = 0; i < p_frames; i++) {- if (input_size > input_ofs && (int)input_ofs < buf.size()) {- float l = (buf[input_ofs++] >> 16) / 32768.f;- if ((int)input_ofs >= buf.size()) {- input_ofs = 0;- }- float r = (buf[input_ofs++] >> 16) / 32768.f;- if ((int)input_ofs >= buf.size()) {- input_ofs = 0;- }-- p_buffer[i] = AudioFrame(l, r);- } else {- p_buffer[i] = AudioFrame(0.0f, 0.0f);- }- }- }--#ifdef DEBUG_ENABLED- if (input_ofs > input_position && (int)(input_ofs - input_position) < (p_frames * 2)) {- print_verbose(String(get_class_name()) + " buffer underrun: input_position=" + itos(input_position) + " input_ofs=" + itos(input_ofs) + " input_size=" + itos(input_size));- }-#endif-- AudioDriver::get_singleton()->unlock();-- return mixed_frames;-}--int AudioStreamPlaybackMicrophone::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {- return AudioStreamPlaybackResampled::mix(p_buffer, p_rate_scale, p_frames);-}--float AudioStreamPlaybackMicrophone::get_stream_sampling_rate() {- return AudioDriver::get_singleton()->get_input_mix_rate();-}--void AudioStreamPlaybackMicrophone::start(double p_from_pos) {- if (active) {- return;- }-- input_ofs = 0;-- if (AudioServer::get_singleton()->set_input_device_active(true) == OK) {- active = true;- begin_resample();- }-}--void AudioStreamPlaybackMicrophone::stop() {- if (active) {- AudioServer::get_singleton()->set_input_device_active(false);- active = false;- }-}--bool AudioStreamPlaybackMicrophone::is_playing() const {- return active;-}--int AudioStreamPlaybackMicrophone::get_loop_count() const {- return 0;-}--double AudioStreamPlaybackMicrophone::get_playback_position() const {- return 0;-}--void AudioStreamPlaybackMicrophone::seek(double p_time) {- // Can't seek a microphone input-}--void AudioStreamPlaybackMicrophone::tag_used_streams() {- microphone->tag_used(0);-}--AudioStreamPlaybackMicrophone::~AudioStreamPlaybackMicrophone() {- microphone->playbacks.erase(this);- stop();-}--AudioStreamPlaybackMicrophone::AudioStreamPlaybackMicrophone() {-}--////////////////////////////////-void AudioStreamRandomizer::add_stream(int p_index, Ref<AudioStream> p_stream, float p_weight) {if (p_index < 0) {p_index = audio_stream_pool.size();@@ -861,4 +415,3 @@ int AudioStreamPlaybackRandomizer::mix(AudioFrame *p_buffer, float p_rate_scale,AudioStreamPlaybackRandomizer::~AudioStreamPlaybackRandomizer() {randomizer->playbacks.erase(this);}-/////////////////////////////////////////////diff --git a/scene/resources/audio/audio_stream_randomizer.h b/scene/resources/audio/audio_stream_randomizer.hnew file mode 100644index 00000000000..6e1fdcf7e37--- /dev/null+++ b/scene/resources/audio/audio_stream_randomizer.h@@ -0,0 +1,143 @@+/**************************************************************************/+/* audio_stream_randomizer.h */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#pragma once++#include "scene/property_list_helper.h"+#include "scene/resources/audio/audio_stream.h"++class AudioStreamPlaybackRandomizer;++class AudioStreamRandomizer : public AudioStream {+ GDCLASS(AudioStreamRandomizer, AudioStream);++public:+ enum PlaybackMode {+ PLAYBACK_RANDOM_NO_REPEATS,+ PLAYBACK_RANDOM,+ PLAYBACK_SEQUENTIAL,+ };++private:+ friend class AudioStreamPlaybackRandomizer;++ struct PoolEntry {+ Ref<AudioStream> stream;+ float weight = 1.0;+ };++ static inline PropertyListHelper base_property_helper;+ PropertyListHelper property_helper;++ HashSet<AudioStreamPlaybackRandomizer *> playbacks;+ Vector<PoolEntry> audio_stream_pool;+ float random_pitch_scale = 1.0f;+ float random_volume_offset_db = 0.0f;++ Ref<AudioStreamPlayback> instance_playback_random();+ Ref<AudioStreamPlayback> instance_playback_no_repeats();+ Ref<AudioStreamPlayback> instance_playback_sequential();++ Ref<AudioStream> last_playback = nullptr;+ PlaybackMode playback_mode = PLAYBACK_RANDOM_NO_REPEATS;++protected:+ static void _bind_methods();++ bool _set(const StringName &p_name, const Variant &p_value) { return property_helper.property_set_value(p_name, p_value); }+ bool _get(const StringName &p_name, Variant &r_ret) const { return property_helper.property_get_value(p_name, r_ret); }+ void _get_property_list(List<PropertyInfo> *p_list) const { property_helper.get_property_list(p_list); }+ bool _property_can_revert(const StringName &p_name) const { return property_helper.property_can_revert(p_name); }+ bool _property_get_revert(const StringName &p_name, Variant &r_property) const { return property_helper.property_get_revert(p_name, r_property); }++public:+ void add_stream(int p_index, Ref<AudioStream> p_stream, float p_weight = 1.0);+ void move_stream(int p_index_from, int p_index_to);+ void remove_stream(int p_index);++ void set_stream(int p_index, Ref<AudioStream> p_stream);+ Ref<AudioStream> get_stream(int p_index) const;+ void set_stream_probability_weight(int p_index, float p_weight);+ float get_stream_probability_weight(int p_index) const;++ void set_streams_count(int p_count);+ int get_streams_count() const;++ void set_random_pitch_semitones(float p_pitch_semitones);+ float get_random_pitch_semitones() const;++ void set_random_pitch(float p_pitch_scale);+ float get_random_pitch() const;++ void set_random_volume_offset_db(float p_volume_offset_db);+ float get_random_volume_offset_db() const;++ void set_playback_mode(PlaybackMode p_playback_mode);+ PlaybackMode get_playback_mode() const;++ virtual Ref<AudioStreamPlayback> instantiate_playback() override;++ virtual double get_length() const override; //if supported, otherwise return 0+ virtual bool is_monophonic() const override;++ virtual bool is_meta_stream() const override { return true; }++ AudioStreamRandomizer();+};++class AudioStreamPlaybackRandomizer : public AudioStreamPlayback {+ GDCLASS(AudioStreamPlaybackRandomizer, AudioStreamPlayback);+ friend class AudioStreamRandomizer;++ Ref<AudioStreamRandomizer> randomizer;+ Ref<AudioStreamPlayback> playback;+ Ref<AudioStreamPlayback> playing;++ float pitch_scale;+ float volume_scale;++public:+ virtual void start(double p_from_pos = 0.0) override;+ virtual void stop() override;+ virtual bool is_playing() const override;++ virtual int get_loop_count() const override; //times it looped++ virtual double get_playback_position() const override;+ virtual void seek(double p_time) override;++ virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override;++ virtual void tag_used_streams() override;++ ~AudioStreamPlaybackRandomizer();+};++VARIANT_ENUM_CAST(AudioStreamRandomizer::PlaybackMode);diff --git a/scene/resources/audio_stream_wav.cpp b/scene/resources/audio/audio_stream_wav.cppsimilarity index 99%rename from scene/resources/audio_stream_wav.cpprename to scene/resources/audio/audio_stream_wav.cppindex 8ecc5378fbc..7517e4b853f 100644--- a/scene/resources/audio_stream_wav.cpp+++ b/scene/resources/audio/audio_stream_wav.cpp@@ -33,6 +33,7 @@#include "core/io/file_access_memory.h"#include "core/io/marshalls.h"#include "core/object/class_db.h"+#include "servers/audio/audio_server.h"const float TRIM_DB_LIMIT = -50;const int TRIM_FADE_OUT_FRAMES = 500;diff --git a/scene/resources/audio_stream_wav.h b/scene/resources/audio/audio_stream_wav.hsimilarity index 99%rename from scene/resources/audio_stream_wav.hrename to scene/resources/audio/audio_stream_wav.hindex b121a25fe60..f683f076bef 100644--- a/scene/resources/audio_stream_wav.h+++ b/scene/resources/audio/audio_stream_wav.h@@ -30,7 +30,7 @@#pragma once-#include "servers/audio/audio_stream.h"+#include "scene/resources/audio/audio_stream.h"#include <thirdparty/misc/qoa.h>diff --git a/servers/audio/audio_bus_layout.cpp b/servers/audio/audio_bus_layout.cppnew file mode 100644index 00000000000..cd9d690614c--- /dev/null+++ b/servers/audio/audio_bus_layout.cpp@@ -0,0 +1,159 @@+/**************************************************************************/+/* audio_bus_layout.cpp */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#include "audio_bus_layout.h"++#include "scene/scene_string_names.h"+#include "servers/audio/audio_effect.h" // IWYU pragma: keep. For Bus::Effect.++bool AudioBusLayout::_set(const StringName &p_name, const Variant &p_value) {+ String s = p_name;+ if (s.begins_with("bus/")) {+ int index = s.get_slicec('/', 1).to_int();+ if (buses.size() <= index) {+ buses.resize(index + 1);+ }++ Bus &bus = buses.write[index];++ String what = s.get_slicec('/', 2);++ if (what == "name") {+ bus.name = p_value;+ } else if (what == "solo") {+ bus.solo = p_value;+ } else if (what == "mute") {+ bus.mute = p_value;+ } else if (what == "bypass_fx") {+ bus.bypass = p_value;+ } else if (what == "volume_db") {+ bus.volume_db = p_value;+ } else if (what == "send") {+ bus.send = p_value;+ } else if (what == "effect") {+ int which = s.get_slicec('/', 3).to_int();+ if (bus.effects.size() <= which) {+ bus.effects.resize(which + 1);+ }++ Bus::Effect &fx = bus.effects.write[which];++ String fxwhat = s.get_slicec('/', 4);+ if (fxwhat == "effect") {+ fx.effect = p_value;+ } else if (fxwhat == "enabled") {+ fx.enabled = p_value;+ } else {+ return false;+ }++ return true;+ } else {+ return false;+ }++ return true;+ }++ return false;+}++bool AudioBusLayout::_get(const StringName &p_name, Variant &r_ret) const {+ String s = p_name;+ if (s.begins_with("bus/")) {+ int index = s.get_slicec('/', 1).to_int();+ if (index < 0 || index >= buses.size()) {+ return false;+ }++ const Bus &bus = buses[index];++ String what = s.get_slicec('/', 2);++ if (what == "name") {+ r_ret = bus.name;+ } else if (what == "solo") {+ r_ret = bus.solo;+ } else if (what == "mute") {+ r_ret = bus.mute;+ } else if (what == "bypass_fx") {+ r_ret = bus.bypass;+ } else if (what == "volume_db") {+ r_ret = bus.volume_db;+ } else if (what == "send") {+ r_ret = bus.send;+ } else if (what == "effect") {+ int which = s.get_slicec('/', 3).to_int();+ if (which < 0 || which >= bus.effects.size()) {+ return false;+ }++ const Bus::Effect &fx = bus.effects[which];++ String fxwhat = s.get_slicec('/', 4);+ if (fxwhat == "effect") {+ r_ret = fx.effect;+ } else if (fxwhat == "enabled") {+ r_ret = fx.enabled;+ } else {+ return false;+ }++ return true;+ } else {+ return false;+ }++ return true;+ }++ return false;+}++void AudioBusLayout::_get_property_list(List<PropertyInfo> *p_list) const {+ for (int i = 0; i < buses.size(); i++) {+ p_list->push_back(PropertyInfo(Variant::STRING, "bus/" + itos(i) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));+ p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/solo", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));+ p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/mute", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));+ p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/bypass_fx", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));+ p_list->push_back(PropertyInfo(Variant::FLOAT, "bus/" + itos(i) + "/volume_db", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));+ p_list->push_back(PropertyInfo(Variant::FLOAT, "bus/" + itos(i) + "/send", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));++ for (int j = 0; j < buses[i].effects.size(); j++) {+ p_list->push_back(PropertyInfo(Variant::OBJECT, "bus/" + itos(i) + "/effect/" + itos(j) + "/effect", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));+ p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/effect/" + itos(j) + "/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));+ }+ }+}++AudioBusLayout::AudioBusLayout() {+ buses.resize(1);+ buses.write[0].name = SceneStringName(Master);+}diff --git a/servers/audio/audio_bus_layout.h b/servers/audio/audio_bus_layout.hnew file mode 100644index 00000000000..72688867183--- /dev/null+++ b/servers/audio/audio_bus_layout.h@@ -0,0 +1,70 @@+/**************************************************************************/+/* audio_bus_layout.h */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#pragma once++#include "core/io/resource.h"++class AudioEffect;++class AudioBusLayout : public Resource {+ GDCLASS(AudioBusLayout, Resource);++ friend class AudioServer;++ struct Bus {+ StringName name;+ bool solo = false;+ bool mute = false;+ bool bypass = false;++ struct Effect {+ Ref<AudioEffect> effect;+ bool enabled = false;+ };++ Vector<Effect> effects;++ float volume_db = 0.0f;+ StringName send;++ Bus() {}+ };++ Vector<Bus> buses;++protected:+ bool _set(const StringName &p_name, const Variant &p_value);+ bool _get(const StringName &p_name, Variant &r_ret) const;+ void _get_property_list(List<PropertyInfo> *p_list) const;++public:+ AudioBusLayout();+};diff --git a/servers/audio/audio_driver.cpp b/servers/audio/audio_driver.cppnew file mode 100644index 00000000000..463d64c4ec2--- /dev/null+++ b/servers/audio/audio_driver.cpp@@ -0,0 +1,251 @@+/**************************************************************************/+/* audio_driver.cpp */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#include "audio_driver.h"++#include "core/config/project_settings.h"+#include "core/os/os.h"+#include "scene/resources/audio/audio_stream.h"+#include "servers/audio/audio_driver_dummy.h"+#include "servers/audio/audio_server.h"++AudioDriver *AudioDriver::singleton = nullptr;+AudioDriver *AudioDriver::get_singleton() {+ return singleton;+}++void AudioDriver::set_singleton() {+ singleton = this;+}++#ifdef DEBUG_ENABLED+void AudioDriver::start_counting_ticks() {+ prof_ticks.set(OS::get_singleton()->get_ticks_usec());+}++void AudioDriver::stop_counting_ticks() {+ prof_time.add(OS::get_singleton()->get_ticks_usec() - prof_ticks.get());+}+#endif // DEBUG_ENABLED++void AudioDriver::audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time) {+ if (p_update_mix_time) {+ update_mix_time(p_frames);+ }++ if (AudioServer::get_singleton()) {+ AudioServer::get_singleton()->_driver_process(p_frames, p_buffer);+ }+}++void AudioDriver::update_mix_time(int p_frames) {+ _last_mix_frames = p_frames;+ if (OS::get_singleton()) {+ _last_mix_time = OS::get_singleton()->get_ticks_usec();+ }+}++double AudioDriver::get_time_since_last_mix() {+ lock();+ uint64_t last_mix_time = _last_mix_time;+ unlock();+ return (OS::get_singleton()->get_ticks_usec() - last_mix_time) / 1000000.0;+}++double AudioDriver::get_time_to_next_mix() {+ lock();+ uint64_t last_mix_time = _last_mix_time;+ uint64_t last_mix_frames = _last_mix_frames;+ unlock();+ double total = (OS::get_singleton()->get_ticks_usec() - last_mix_time) / 1000000.0;+ double mix_buffer = last_mix_frames / (double)get_mix_rate();+ return mix_buffer - total;+}++void AudioDriver::input_buffer_init(int driver_buffer_frames) {+ const int input_buffer_channels = 2;+ input_buffer.resize(driver_buffer_frames * input_buffer_channels * 4);+ input_position = 0;+ input_size = 0;+}++void AudioDriver::input_buffer_write(int32_t sample) {+ if ((int)input_position < input_buffer.size()) {+ input_buffer.write[input_position++] = sample;+ if ((int)input_position >= input_buffer.size()) {+ input_position = 0;+ }+ if ((int)input_size < input_buffer.size()) {+ input_size++;+ }+ } else {+ // This protection was added in GH-26505 due to a "possible crash".+ // This cannot have happened unless two non-locked threads entered function simultaneously, which was possible when multiple calls to+ // `AudioDriver::input_start()` did not raise an error condition.+ WARN_PRINT("input_buffer_write: Invalid input_position=" + itos(input_position) + " input_buffer.size()=" + itos(input_buffer.size()));+ }+}++int AudioDriver::_get_configured_mix_rate() {+ StringName audio_driver_setting = "audio/driver/mix_rate";+ int mix_rate = GLOBAL_GET(audio_driver_setting);++#ifdef WEB_ENABLED+ // `0` is an acceptable value (resorts to the browser's default).+ return MAX(0, mix_rate);+#else // !WEB_ENABLED+ // In the case of invalid mix rate, let's default to a sensible value..+ if (mix_rate <= 0) {+ WARN_PRINT(vformat("Invalid mix rate of %d, consider reassigning setting \'%s\'. \nDefaulting mix rate to value %d.",+ mix_rate, audio_driver_setting, AudioDriverManager::DEFAULT_MIX_RATE));+ mix_rate = AudioDriverManager::DEFAULT_MIX_RATE;+ }+ return mix_rate;+#endif+}++AudioDriver::SpeakerMode AudioDriver::get_speaker_mode_by_total_channels(int p_channels) const {+ switch (p_channels) {+ case 4:+ return SPEAKER_SURROUND_31;+ case 6:+ return SPEAKER_SURROUND_51;+ case 8:+ return SPEAKER_SURROUND_71;+ }++ // Default to STEREO+ return SPEAKER_MODE_STEREO;+}++int AudioDriver::get_total_channels_by_speaker_mode(AudioDriver::SpeakerMode p_mode) const {+ switch (p_mode) {+ case SPEAKER_MODE_STEREO:+ return 2;+ case SPEAKER_SURROUND_31:+ return 4;+ case SPEAKER_SURROUND_51:+ return 6;+ case SPEAKER_SURROUND_71:+ return 8;+ }++ ERR_FAIL_V(2);+}++PackedStringArray AudioDriver::get_output_device_list() {+ PackedStringArray list;++ list.push_back("Default");++ return list;+}++String AudioDriver::get_output_device() {+ return "Default";+}++PackedStringArray AudioDriver::get_input_device_list() {+ PackedStringArray list;++ list.push_back("Default");++ return list;+}++void AudioDriver::start_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {+ if (p_playback.is_valid()) {+ if (p_playback->stream.is_valid()) {+ WARN_PRINT_ED(vformat(R"(Trying to play stream (%s) as a sample (%s), but the driver doesn't support sample playback.)", p_playback->get_instance_id(), p_playback->stream->get_instance_id()));+ } else {+ WARN_PRINT_ED(vformat(R"(Trying to play stream (%s) as a null sample, but the driver doesn't support sample playback.)", p_playback->get_instance_id()));+ }+ } else {+ WARN_PRINT_ED("Trying to play a null sample playback from a driver that doesn't support sample playback.");+ }+}++AudioDriverDummy AudioDriverManager::dummy_driver;+AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS] = {+ &AudioDriverManager::dummy_driver,+};+int AudioDriverManager::driver_count = 1;++void AudioDriverManager::add_driver(AudioDriver *p_driver) {+ ERR_FAIL_COND(driver_count >= MAX_DRIVERS);+ drivers[driver_count - 1] = p_driver;++ // Last driver is always our dummy driver+ drivers[driver_count++] = &AudioDriverManager::dummy_driver;+}++int AudioDriverManager::get_driver_count() {+ return driver_count;+}++void AudioDriverManager::initialize(int p_driver) {+ GLOBAL_DEF_RST("audio/driver/enable_input", false);+ GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "audio/driver/mix_rate", PROPERTY_HINT_RANGE, "11025,192000,1,or_greater,suffix:Hz"), DEFAULT_MIX_RATE);+ GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "audio/driver/mix_rate.web", PROPERTY_HINT_RANGE, "0,192000,1,or_greater,suffix:Hz"), 0); // Safer default output_latency for web (use browser default).++ int failed_driver = -1;++ // Check if there is a selected driver+ if (p_driver >= 0 && p_driver < driver_count) {+ if (drivers[p_driver]->init() == OK) {+ drivers[p_driver]->set_singleton();+ return;+ } else {+ failed_driver = p_driver;+ }+ }++ // No selected driver, try them all in order+ for (int i = 0; i < driver_count; i++) {+ // Don't re-init the driver if it failed above+ if (i == failed_driver) {+ continue;+ }++ if (drivers[i]->init() == OK) {+ drivers[i]->set_singleton();+ break;+ }+ }++ if (driver_count > 1 && String(AudioDriver::get_singleton()->get_name()) == "Dummy") {+ WARN_PRINT("All audio drivers failed, falling back to the dummy driver.");+ }+}++AudioDriver *AudioDriverManager::get_driver(int p_driver) {+ ERR_FAIL_INDEX_V(p_driver, driver_count, nullptr);+ return drivers[p_driver];+}diff --git a/servers/audio/audio_driver.h b/servers/audio/audio_driver.hnew file mode 100644index 00000000000..74f0cbfec34--- /dev/null+++ b/servers/audio/audio_driver.h@@ -0,0 +1,171 @@+/**************************************************************************/+/* audio_driver.h */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#pragma once++#include "core/templates/vector.h"+#include "core/variant/variant.h"+#include "servers/audio/audio_server_enums.h"++struct AudioFrame;+class AudioDriverDummy;+class AudioSample;+class AudioStream;+class AudioSamplePlayback;++class AudioDriver {+ static AudioDriver *singleton;+ uint64_t _last_mix_time = 0;+ uint64_t _last_mix_frames = 0;++#ifdef DEBUG_ENABLED+ SafeNumeric<uint64_t> prof_ticks;+ SafeNumeric<uint64_t> prof_time;+#endif++protected:+ Vector<int32_t> input_buffer;+ unsigned int input_position = 0;+ unsigned int input_size = 0;++ void audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time = true);+ void update_mix_time(int p_frames);+ void input_buffer_init(int driver_buffer_frames);+ void input_buffer_write(int32_t sample);++ int _get_configured_mix_rate();++#ifdef DEBUG_ENABLED+ void start_counting_ticks();+ void stop_counting_ticks();+#else+ _FORCE_INLINE_ void start_counting_ticks() {}+ _FORCE_INLINE_ void stop_counting_ticks() {}+#endif++public:+ double get_time_since_last_mix(); //useful for video -> audio sync+ double get_time_to_next_mix();++ enum SpeakerMode {+ SPEAKER_MODE_STEREO = AuSE::SPEAKER_MODE_STEREO,+ SPEAKER_SURROUND_31 = AuSE::SPEAKER_SURROUND_31,+ SPEAKER_SURROUND_51 = AuSE::SPEAKER_SURROUND_51,+ SPEAKER_SURROUND_71 = AuSE::SPEAKER_SURROUND_71,+ };++ static AudioDriver *get_singleton();+ void set_singleton();++ // Virtual API to implement.++ virtual const char *get_name() const = 0;++ virtual Error init() = 0;+ virtual void start() = 0;+ virtual int get_mix_rate() const = 0;+ virtual int get_input_mix_rate() const { return get_mix_rate(); }+ virtual SpeakerMode get_speaker_mode() const = 0;+ virtual float get_latency() { return 0; }++ virtual void lock() = 0;+ virtual void unlock() = 0;+ virtual void finish() = 0;++ virtual PackedStringArray get_output_device_list();+ virtual String get_output_device();+ virtual void set_output_device(const String &p_name) {}++ virtual Error input_start() { return FAILED; }+ virtual Error input_stop() { return FAILED; }++ virtual PackedStringArray get_input_device_list();+ virtual String get_input_device() { return "Default"; }+ virtual void set_input_device(const String &p_name) {}++ //++ SpeakerMode get_speaker_mode_by_total_channels(int p_channels) const;+ int get_total_channels_by_speaker_mode(SpeakerMode) const;++ Vector<int32_t> get_input_buffer() { return input_buffer; }+ unsigned int get_input_position() { return input_position; }+ unsigned int get_input_size() { return input_size; }++#ifdef DEBUG_ENABLED+ uint64_t get_profiling_time() const { return prof_time.get(); }+ void reset_profiling_time() { prof_time.set(0); }+#endif++ // Samples handling.+ virtual bool is_stream_registered_as_sample(const Ref<AudioStream> &p_stream) const {+ return false;+ }+ virtual void register_sample(const Ref<AudioSample> &p_sample) {}+ virtual void unregister_sample(const Ref<AudioSample> &p_sample) {}+ virtual void start_sample_playback(const Ref<AudioSamplePlayback> &p_playback);+ virtual void stop_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {}+ virtual void set_sample_playback_pause(const Ref<AudioSamplePlayback> &p_playback, bool p_paused) {}+ virtual bool is_sample_playback_active(const Ref<AudioSamplePlayback> &p_playback) { return false; }+ virtual double get_sample_playback_position(const Ref<AudioSamplePlayback> &p_playback) { return false; }+ virtual void update_sample_playback_pitch_scale(const Ref<AudioSamplePlayback> &p_playback, float p_pitch_scale = 0.0f) {}+ virtual void set_sample_playback_bus_volumes_linear(const Ref<AudioSamplePlayback> &p_playback, const HashMap<StringName, Vector<AudioFrame>> &p_bus_volumes) {}++ virtual void set_sample_bus_count(int p_count) {}+ virtual void remove_sample_bus(int p_bus) {}+ virtual void add_sample_bus(int p_at_pos = -1) {}+ virtual void move_sample_bus(int p_bus, int p_to_pos) {}+ virtual void set_sample_bus_send(int p_bus, const StringName &p_send) {}+ virtual void set_sample_bus_volume_db(int p_bus, float p_volume_db) {}+ virtual void set_sample_bus_solo(int p_bus, bool p_enable) {}+ virtual void set_sample_bus_mute(int p_bus, bool p_enable) {}++ AudioDriver() {}+ virtual ~AudioDriver() {}+};++class AudioDriverManager {+ enum {+ MAX_DRIVERS = 10+ };++ static AudioDriver *drivers[MAX_DRIVERS];+ static int driver_count;++ static AudioDriverDummy dummy_driver;++public:+ static const int DEFAULT_MIX_RATE = 44100;++ static void add_driver(AudioDriver *p_driver);+ static void initialize(int p_driver);+ static int get_driver_count();+ static AudioDriver *get_driver(int p_driver);+};diff --git a/servers/audio/audio_driver_dummy.h b/servers/audio/audio_driver_dummy.hindex fe292c8d0f3..48c0896e823 100644--- a/servers/audio/audio_driver_dummy.h+++ b/servers/audio/audio_driver_dummy.h@@ -33,7 +33,7 @@#include "core/os/mutex.h"#include "core/os/thread.h"#include "core/templates/safe_refcount.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_driver.h"class AudioDriverDummy : public AudioDriver {Thread thread;diff --git a/servers/audio/audio_effect.h b/servers/audio/audio_effect.hindex 47baecd6748..3eb7280893f 100644--- a/servers/audio/audio_effect.h+++ b/servers/audio/audio_effect.h@@ -31,9 +31,9 @@#pragma once#include "core/io/resource.h"-#include "core/math/audio_frame.h"#include "core/object/gdvirtual.gen.h"#include "core/variant/native_ptr.h"+#include "servers/audio/audio_frame.h"class AudioEffectInstance : public RefCounted {GDCLASS(AudioEffectInstance, RefCounted);diff --git a/core/math/audio_frame.h b/servers/audio/audio_frame.hsimilarity index 97%rename from core/math/audio_frame.hrename to servers/audio/audio_frame.hindex b90f2cd307b..e5fcd9b1eee 100644--- a/core/math/audio_frame.h+++ b/servers/audio/audio_frame.h@@ -46,9 +46,6 @@ static _FORCE_INLINE_ float undenormalize(float p_value) {return (v.i & 0x7f800000) < 0x08000000 ? 0.0f : p_value;}-static const float AUDIO_PEAK_OFFSET = 0.0000000001f;-static const float AUDIO_MIN_PEAK_DB = -200.0f; // linear_to_db(AUDIO_PEAK_OFFSET)-struct AudioFrame {// Left and right samples.float left = 0.0f;diff --git a/servers/audio/audio_rb_resampler.cpp b/servers/audio/audio_rb_resampler.cppindex bd50e34bfe7..f1e600014b1 100644--- a/servers/audio/audio_rb_resampler.cpp+++ b/servers/audio/audio_rb_resampler.cpp@@ -30,9 +30,9 @@#include "audio_rb_resampler.h"-#include "core/math/audio_frame.h"#include "core/math/math_funcs_binary.h"#include "core/os/memory.h"+#include "servers/audio/audio_frame.h"int AudioRBResampler::get_channel_count() const {if (!rb) {diff --git a/servers/audio/audio_rb_resampler.h b/servers/audio/audio_rb_resampler.hindex f67addafbd2..8d40c0e256f 100644--- a/servers/audio/audio_rb_resampler.h+++ b/servers/audio/audio_rb_resampler.h@@ -30,9 +30,9 @@#pragma once-#include "core/math/audio_frame.h"#include "core/templates/safe_refcount.h"#include "core/typedefs.h"+#include "servers/audio/audio_frame.h"struct AudioRBResampler {uint32_t rb_bits;diff --git a/servers/audio/audio_server.cpp b/servers/audio/audio_server.cppindex 98bb2cebd94..e95b1f1c28a 100644--- a/servers/audio/audio_server.cpp+++ b/servers/audio/audio_server.cpp@@ -32,16 +32,14 @@#include "core/config/project_settings.h"#include "core/debugger/engine_debugger.h"-#include "core/error/error_macros.h"#include "core/io/resource_loader.h"-#include "core/math/audio_frame.h"#include "core/object/class_db.h"#include "core/os/os.h"-#include "core/string/string_name.h"-#include "core/templates/pair.h"+#include "scene/resources/audio/audio_stream.h"#include "scene/scene_string_names.h"-#include "servers/audio/audio_driver_dummy.h"-#include "servers/audio/audio_stream.h"+#include "servers/audio/audio_bus_layout.h"+#include "servers/audio/audio_driver.h"+#include "servers/audio/audio_frame.h"#include "servers/audio/effects/audio_effect_compressor.h"#ifdef TOOLS_ENABLED@@ -50,225 +48,6 @@#define MARK_EDITED#endif-AudioDriver *AudioDriver::singleton = nullptr;-AudioDriver *AudioDriver::get_singleton() {- return singleton;-}--void AudioDriver::set_singleton() {- singleton = this;-}--#ifdef DEBUG_ENABLED-void AudioDriver::start_counting_ticks() {- prof_ticks.set(OS::get_singleton()->get_ticks_usec());-}--void AudioDriver::stop_counting_ticks() {- prof_time.add(OS::get_singleton()->get_ticks_usec() - prof_ticks.get());-}-#endif // DEBUG_ENABLED--void AudioDriver::audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time) {- if (p_update_mix_time) {- update_mix_time(p_frames);- }-- if (AudioServer::get_singleton()) {- AudioServer::get_singleton()->_driver_process(p_frames, p_buffer);- }-}--void AudioDriver::update_mix_time(int p_frames) {- _last_mix_frames = p_frames;- if (OS::get_singleton()) {- _last_mix_time = OS::get_singleton()->get_ticks_usec();- }-}--double AudioDriver::get_time_since_last_mix() {- lock();- uint64_t last_mix_time = _last_mix_time;- unlock();- return (OS::get_singleton()->get_ticks_usec() - last_mix_time) / 1000000.0;-}--double AudioDriver::get_time_to_next_mix() {- lock();- uint64_t last_mix_time = _last_mix_time;- uint64_t last_mix_frames = _last_mix_frames;- unlock();- double total = (OS::get_singleton()->get_ticks_usec() - last_mix_time) / 1000000.0;- double mix_buffer = last_mix_frames / (double)get_mix_rate();- return mix_buffer - total;-}--void AudioDriver::input_buffer_init(int driver_buffer_frames) {- const int input_buffer_channels = 2;- input_buffer.resize(driver_buffer_frames * input_buffer_channels * 4);- input_position = 0;- input_size = 0;-}--void AudioDriver::input_buffer_write(int32_t sample) {- if ((int)input_position < input_buffer.size()) {- input_buffer.write[input_position++] = sample;- if ((int)input_position >= input_buffer.size()) {- input_position = 0;- }- if ((int)input_size < input_buffer.size()) {- input_size++;- }- } else {- // This protection was added in GH-26505 due to a "possible crash".- // This cannot have happened unless two non-locked threads entered function simultaneously, which was possible when multiple calls to- // `AudioDriver::input_start()` did not raise an error condition.- WARN_PRINT("input_buffer_write: Invalid input_position=" + itos(input_position) + " input_buffer.size()=" + itos(input_buffer.size()));- }-}--int AudioDriver::_get_configured_mix_rate() {- StringName audio_driver_setting = "audio/driver/mix_rate";- int mix_rate = GLOBAL_GET(audio_driver_setting);--#ifdef WEB_ENABLED- // `0` is an acceptable value (resorts to the browser's default).- return MAX(0, mix_rate);-#else // !WEB_ENABLED- // In the case of invalid mix rate, let's default to a sensible value..- if (mix_rate <= 0) {- WARN_PRINT(vformat("Invalid mix rate of %d, consider reassigning setting \'%s\'. \nDefaulting mix rate to value %d.",- mix_rate, audio_driver_setting, AudioDriverManager::DEFAULT_MIX_RATE));- mix_rate = AudioDriverManager::DEFAULT_MIX_RATE;- }- return mix_rate;-#endif-}--AudioDriver::SpeakerMode AudioDriver::get_speaker_mode_by_total_channels(int p_channels) const {- switch (p_channels) {- case 4:- return SPEAKER_SURROUND_31;- case 6:- return SPEAKER_SURROUND_51;- case 8:- return SPEAKER_SURROUND_71;- }-- // Default to STEREO- return SPEAKER_MODE_STEREO;-}--int AudioDriver::get_total_channels_by_speaker_mode(AudioDriver::SpeakerMode p_mode) const {- switch (p_mode) {- case SPEAKER_MODE_STEREO:- return 2;- case SPEAKER_SURROUND_31:- return 4;- case SPEAKER_SURROUND_51:- return 6;- case SPEAKER_SURROUND_71:- return 8;- }-- ERR_FAIL_V(2);-}--PackedStringArray AudioDriver::get_output_device_list() {- PackedStringArray list;-- list.push_back("Default");-- return list;-}--String AudioDriver::get_output_device() {- return "Default";-}--PackedStringArray AudioDriver::get_input_device_list() {- PackedStringArray list;-- list.push_back("Default");-- return list;-}--void AudioDriver::start_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {- if (p_playback.is_valid()) {- if (p_playback->stream.is_valid()) {- WARN_PRINT_ED(vformat(R"(Trying to play stream (%s) as a sample (%s), but the driver doesn't support sample playback.)", p_playback->get_instance_id(), p_playback->stream->get_instance_id()));- } else {- WARN_PRINT_ED(vformat(R"(Trying to play stream (%s) as a null sample, but the driver doesn't support sample playback.)", p_playback->get_instance_id()));- }- } else {- WARN_PRINT_ED("Trying to play a null sample playback from a driver that don't support sample playback.");- }-}--AudioDriverDummy AudioDriverManager::dummy_driver;-AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS] = {- &AudioDriverManager::dummy_driver,-};-int AudioDriverManager::driver_count = 1;--void AudioDriverManager::add_driver(AudioDriver *p_driver) {- ERR_FAIL_COND(driver_count >= MAX_DRIVERS);- drivers[driver_count - 1] = p_driver;-- // Last driver is always our dummy driver- drivers[driver_count++] = &AudioDriverManager::dummy_driver;-}--int AudioDriverManager::get_driver_count() {- return driver_count;-}--void AudioDriverManager::initialize(int p_driver) {- GLOBAL_DEF_RST("audio/driver/enable_input", false);- GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "audio/driver/mix_rate", PROPERTY_HINT_RANGE, "11025,192000,1,or_greater,suffix:Hz"), DEFAULT_MIX_RATE);- GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "audio/driver/mix_rate.web", PROPERTY_HINT_RANGE, "0,192000,1,or_greater,suffix:Hz"), 0); // Safer default output_latency for web (use browser default).-- int failed_driver = -1;-- // Check if there is a selected driver- if (p_driver >= 0 && p_driver < driver_count) {- if (drivers[p_driver]->init() == OK) {- drivers[p_driver]->set_singleton();- return;- } else {- failed_driver = p_driver;- }- }-- // No selected driver, try them all in order- for (int i = 0; i < driver_count; i++) {- // Don't re-init the driver if it failed above- if (i == failed_driver) {- continue;- }-- if (drivers[i]->init() == OK) {- drivers[i]->set_singleton();- break;- }- }-- if (driver_count > 1 && String(AudioDriver::get_singleton()->get_name()) == "Dummy") {- WARN_PRINT("All audio drivers failed, falling back to the dummy driver.");- }-}--AudioDriver *AudioDriverManager::get_driver(int p_driver) {- ERR_FAIL_INDEX_V(p_driver, driver_count, nullptr);- return drivers[p_driver];-}--//////////////////////////////////////////////-//////////////////////////////////////////////-//////////////////////////////////////////////-//////////////////////////////////////////////-void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) {mix_count++;int todo = p_frames;@@ -393,7 +172,7 @@ void AudioServer::_mix_step() {// Main mixing loop for audio streams.// The basic idea here is to copy the samples returned by the AudioStreamPlayback's mix function into the audio buffers,- // while always maintaining a lookahead buffer of size LOOKAHEAD_BUFFER_SIZE to allow fade-outs for sudden stoppages.+ // while always maintaining a lookahead buffer of size AuSC::LOOKAHEAD_BUFFER_SIZE to allow fade-outs for sudden stoppages.for (AudioStreamPlaybackListNode *playback : playback_list) {// Paused streams are no-ops. Don't even mix audio from the stream playback.if (playback->state.load() == AudioStreamPlaybackListNode::PAUSED) {@@ -412,12 +191,12 @@ void AudioServer::_mix_step() {AudioFrame *buf = mix_buffer.ptrw();// Copy the old contents of the lookahead buffer into the beginning of the mix buffer.- for (int i = 0; i < LOOKAHEAD_BUFFER_SIZE; i++) {+ for (int i = 0; i < AuSC::LOOKAHEAD_BUFFER_SIZE; i++) {buf[i] = playback->lookahead[i];}// Mix the audio stream.- unsigned int mixed_frames = playback->stream_playback->mix(&buf[LOOKAHEAD_BUFFER_SIZE], playback->pitch_scale.get(), buffer_size);+ unsigned int mixed_frames = playback->stream_playback->mix(&buf[AuSC::LOOKAHEAD_BUFFER_SIZE], playback->pitch_scale.get(), buffer_size);if (tag_used_audio_streams && playback->stream_playback->is_playing()) {playback->stream_playback->tag_used_streams();@@ -429,7 +208,7 @@ void AudioServer::_mix_step() {float fadeout_base = 0.94;float fadeout_coefficient = 1;- static_assert(LOOKAHEAD_BUFFER_SIZE == 64, "Update fadeout_base and comment here if you change LOOKAHEAD_BUFFER_SIZE.");+ static_assert(AuSC::LOOKAHEAD_BUFFER_SIZE == 64, "Update fadeout_base and comment here if you change AuSC::LOOKAHEAD_BUFFER_SIZE.");// 0.94 ^ 64 = 0.01906. There might still be a pop but it'll be way better than if we didn't do this.for (unsigned int idx = mixed_frames; idx < buffer_size; idx++) {fadeout_coefficient *= fadeout_base;@@ -440,7 +219,7 @@ void AudioServer::_mix_step() {playback->state.store(new_state);} else {// Move the last little bit of what we just mixed into our lookahead buffer for the next call to _mix_step.- for (int i = 0; i < LOOKAHEAD_BUFFER_SIZE; i++) {+ for (int i = 0; i < AuSC::LOOKAHEAD_BUFFER_SIZE; i++) {playback->lookahead[i] = buf[buffer_size + i];}}@@ -452,7 +231,7 @@ void AudioServer::_mix_step() {AudioStreamPlaybackBusDetails bus_details = *bus_details_ptr;// Mix to any active buses.- for (int idx = 0; idx < MAX_BUSES_PER_PLAYBACK; idx++) {+ for (int idx = 0; idx < AuSC::MAX_BUSES_PER_PLAYBACK; idx++) {if (!bus_details.bus_active[idx]) {continue;}@@ -461,7 +240,7 @@ void AudioServer::_mix_step() {// It's important to know whether or not this bus was active in the previous mix step of this stream. If it was, we need to perform volume interpolation to avoid pops.int prev_bus_idx = -1;- for (int search_idx = 0; search_idx < MAX_BUSES_PER_PLAYBACK; search_idx++) {+ for (int search_idx = 0; search_idx < AuSC::MAX_BUSES_PER_PLAYBACK; search_idx++) {if (!playback->prev_bus_details->bus_active[search_idx]) {continue;}@@ -493,14 +272,14 @@ void AudioServer::_mix_step() {}// Now go through and fade-out any buses that were being played to previously that we missed by going through current data.- for (int idx = 0; idx < MAX_BUSES_PER_PLAYBACK; idx++) {+ for (int idx = 0; idx < AuSC::MAX_BUSES_PER_PLAYBACK; idx++) {if (!playback->prev_bus_details->bus_active[idx]) {continue;}int bus_idx = thread_find_bus_index(playback->prev_bus_details->bus[idx]);int current_bus_idx = -1;- for (int search_idx = 0; search_idx < MAX_BUSES_PER_PLAYBACK; search_idx++) {+ for (int search_idx = 0; search_idx < AuSC::MAX_BUSES_PER_PLAYBACK; search_idx++) {if (bus_details.bus[search_idx] == playback->prev_bus_details->bus[idx]) {current_bus_idx = search_idx;}@@ -519,14 +298,14 @@ void AudioServer::_mix_step() {}// Copy the bus details we mixed with to the previous bus details to maintain volume ramps.- for (int i = 0; i < MAX_BUSES_PER_PLAYBACK; i++) {+ for (int i = 0; i < AuSC::MAX_BUSES_PER_PLAYBACK; i++) {playback->prev_bus_details->bus_active[i] = bus_details.bus_active[i];}- for (int i = 0; i < MAX_BUSES_PER_PLAYBACK; i++) {+ for (int i = 0; i < AuSC::MAX_BUSES_PER_PLAYBACK; i++) {playback->prev_bus_details->bus[i] = bus_details.bus[i];}- for (int i = 0; i < MAX_BUSES_PER_PLAYBACK; i++) {- for (int j = 0; j < MAX_CHANNELS_PER_BUS; j++) {+ for (int i = 0; i < AuSC::MAX_BUSES_PER_PLAYBACK; i++) {+ for (int j = 0; j < AuSC::MAX_CHANNELS_PER_BUS; j++) {playback->prev_bus_details->volume[i][j] = bus_details.volume[i][j];}}@@ -613,7 +392,7 @@ void AudioServer::_mix_step() {for (int k = 0; k < bus->channels.size(); k++) {if (!bus->channels[k].active) {- bus->channels.write[k].peak_volume = AudioFrame(AUDIO_MIN_PEAK_DB, AUDIO_MIN_PEAK_DB);+ bus->channels.write[k].peak_volume = AudioFrame(AuSC::AUDIO_MIN_PEAK_DB, AuSC::AUDIO_MIN_PEAK_DB);continue;}@@ -647,7 +426,7 @@ void AudioServer::_mix_step() {}}- bus->channels.write[k].peak_volume = AudioFrame(Math::linear_to_db(peak.left + AUDIO_PEAK_OFFSET), Math::linear_to_db(peak.right + AUDIO_PEAK_OFFSET));+ bus->channels.write[k].peak_volume = AudioFrame(Math::linear_to_db(peak.left + AuSC::AUDIO_PEAK_OFFSET), Math::linear_to_db(peak.right + AuSC::AUDIO_PEAK_OFFSET));if (!bus->channels[k].used) {// See if any audio is contained, because channel was not used.@@ -1255,7 +1034,7 @@ void AudioServer::start_playback_stream(Ref<AudioStreamPlayback> p_playback, conAudioStreamPlaybackBusDetails *new_bus_details = new AudioStreamPlaybackBusDetails();int idx = 0;for (KeyValue<StringName, Vector<AudioFrame>> pair : p_bus_volumes) {- if (pair.value.size() < channel_count || pair.value.size() != MAX_CHANNELS_PER_BUS) {+ if (pair.value.size() < channel_count || pair.value.size() != AuSC::MAX_CHANNELS_PER_BUS) {delete playback_node;delete new_bus_details;ERR_FAIL();@@ -1263,7 +1042,7 @@ void AudioServer::start_playback_stream(Ref<AudioStreamPlayback> p_playback, connew_bus_details->bus_active[idx] = true;new_bus_details->bus[idx] = pair.key;- for (int channel_idx = 0; channel_idx < MAX_CHANNELS_PER_BUS; channel_idx++) {+ for (int channel_idx = 0; channel_idx < AuSC::MAX_CHANNELS_PER_BUS; channel_idx++) {new_bus_details->volume[idx][channel_idx] = pair.value[channel_idx];}idx++;@@ -1320,7 +1099,7 @@ void AudioServer::stop_playback_stream(Ref<AudioStreamPlayback> p_playback) {}void AudioServer::set_playback_bus_exclusive(Ref<AudioStreamPlayback> p_playback, const StringName &p_bus, Vector<AudioFrame> p_volumes) {- ERR_FAIL_COND(p_volumes.size() != MAX_CHANNELS_PER_BUS);+ ERR_FAIL_COND(p_volumes.size() != AuSC::MAX_CHANNELS_PER_BUS);HashMap<StringName, Vector<AudioFrame>> map;map[p_bus] = p_volumes;@@ -1329,7 +1108,7 @@ void AudioServer::set_playback_bus_exclusive(Ref<AudioStreamPlayback> p_playback}void AudioServer::set_playback_bus_volumes_linear(Ref<AudioStreamPlayback> p_playback, const HashMap<StringName, Vector<AudioFrame>> &p_bus_volumes) {- ERR_FAIL_COND(p_bus_volumes.size() > MAX_BUSES_PER_PLAYBACK);+ ERR_FAIL_COND(p_bus_volumes.size() > AuSC::MAX_BUSES_PER_PLAYBACK);// Samples.if (p_playback->get_is_sample() && p_playback->get_sample_playback().is_valid()) {@@ -1346,17 +1125,17 @@ void AudioServer::set_playback_bus_volumes_linear(Ref<AudioStreamPlayback> p_plaint idx = 0;for (KeyValue<StringName, Vector<AudioFrame>> pair : p_bus_volumes) {- if (idx >= MAX_BUSES_PER_PLAYBACK) {+ if (idx >= AuSC::MAX_BUSES_PER_PLAYBACK) {break;}- if (pair.value.size() < channel_count || pair.value.size() != MAX_CHANNELS_PER_BUS) {+ if (pair.value.size() < channel_count || pair.value.size() != AuSC::MAX_CHANNELS_PER_BUS) {delete new_bus_details;ERR_FAIL();}new_bus_details->bus_active[idx] = true;new_bus_details->bus[idx] = pair.key;- for (int channel_idx = 0; channel_idx < MAX_CHANNELS_PER_BUS; channel_idx++) {+ for (int channel_idx = 0; channel_idx < AuSC::MAX_CHANNELS_PER_BUS; channel_idx++) {new_bus_details->volume[idx][channel_idx] = pair.value[channel_idx];}idx++;@@ -1371,7 +1150,7 @@ void AudioServer::set_playback_bus_volumes_linear(Ref<AudioStreamPlayback> p_plavoid AudioServer::set_playback_all_bus_volumes_linear(Ref<AudioStreamPlayback> p_playback, Vector<AudioFrame> p_volumes) {ERR_FAIL_COND(p_playback.is_null());- ERR_FAIL_COND(p_volumes.size() != MAX_CHANNELS_PER_BUS);+ ERR_FAIL_COND(p_volumes.size() != AuSC::MAX_CHANNELS_PER_BUS);HashMap<StringName, Vector<AudioFrame>> map;@@ -1379,7 +1158,7 @@ void AudioServer::set_playback_all_bus_volumes_linear(Ref<AudioStreamPlayback> pif (!playback_node) {return;}- for (int bus_idx = 0; bus_idx < MAX_BUSES_PER_PLAYBACK; bus_idx++) {+ for (int bus_idx = 0; bus_idx < AuSC::MAX_BUSES_PER_PLAYBACK; bus_idx++) {if (playback_node->bus_details.load()->bus_active[bus_idx]) {map[playback_node->bus_details.load()->bus[bus_idx]] = p_volumes;}@@ -1508,7 +1287,7 @@ void AudioServer::notify_listener_changed() {void AudioServer::init_channels_and_buffers() {channel_count = get_channel_count();temp_buffer.resize(channel_count);- mix_buffer.resize(buffer_size + LOOKAHEAD_BUFFER_SIZE);+ mix_buffer.resize(buffer_size + AuSC::LOOKAHEAD_BUFFER_SIZE);for (int i = 0; i < temp_buffer.size(); i++) {temp_buffer.write[i].resize(buffer_size);@@ -1672,8 +1451,8 @@ void AudioServer::unlock() {AudioDriver::get_singleton()->unlock();}-AudioServer::SpeakerMode AudioServer::get_speaker_mode() const {- return (AudioServer::SpeakerMode)AudioDriver::get_singleton()->get_speaker_mode();+AuSE::SpeakerMode AudioServer::get_speaker_mode() const {+ return (AuSE::SpeakerMode)AudioDriver::get_singleton()->get_speaker_mode();}float AudioServer::get_mix_rate() const {@@ -1943,21 +1722,21 @@ void AudioServer::get_argument_options(const StringName &p_function, int p_idx,}#endif-AudioServer::PlaybackType AudioServer::get_default_playback_type() const {+AuSE::PlaybackType AudioServer::get_default_playback_type() const {int playback_type = GLOBAL_GET_CACHED(int, "audio/general/default_playback_type");ERR_FAIL_COND_V_MSG(- playback_type < 0 || playback_type >= PlaybackType::PLAYBACK_TYPE_MAX,- PlaybackType::PLAYBACK_TYPE_STREAM,+ playback_type < 0 || playback_type >= AuSE::PlaybackType::PLAYBACK_TYPE_MAX,+ AuSE::PlaybackType::PLAYBACK_TYPE_STREAM,vformat(R"(Project settings value (%s) for "audio/general/default_playback_type" is not supported)", playback_type));switch (playback_type) {case 1: {- return PlaybackType::PLAYBACK_TYPE_SAMPLE;+ return AuSE::PlaybackType::PLAYBACK_TYPE_SAMPLE;} break;case 0:default: {- return PlaybackType::PLAYBACK_TYPE_STREAM;+ return AuSE::PlaybackType::PLAYBACK_TYPE_STREAM;} break;}}@@ -2124,15 +1903,15 @@ void AudioServer::_bind_methods() {ADD_SIGNAL(MethodInfo("bus_layout_changed"));ADD_SIGNAL(MethodInfo("bus_renamed", PropertyInfo(Variant::INT, "bus_index"), PropertyInfo(Variant::STRING_NAME, "old_name"), PropertyInfo(Variant::STRING_NAME, "new_name")));- BIND_ENUM_CONSTANT(SPEAKER_MODE_STEREO);- BIND_ENUM_CONSTANT(SPEAKER_SURROUND_31);- BIND_ENUM_CONSTANT(SPEAKER_SURROUND_51);- BIND_ENUM_CONSTANT(SPEAKER_SURROUND_71);+ BIND_ENUM_CONSTANT(AuSE::SPEAKER_MODE_STEREO);+ BIND_ENUM_CONSTANT(AuSE::SPEAKER_SURROUND_31);+ BIND_ENUM_CONSTANT(AuSE::SPEAKER_SURROUND_51);+ BIND_ENUM_CONSTANT(AuSE::SPEAKER_SURROUND_71);- BIND_ENUM_CONSTANT(PLAYBACK_TYPE_DEFAULT);- BIND_ENUM_CONSTANT(PLAYBACK_TYPE_STREAM);- BIND_ENUM_CONSTANT(PLAYBACK_TYPE_SAMPLE);- BIND_ENUM_CONSTANT(PLAYBACK_TYPE_MAX);+ BIND_ENUM_CONSTANT(AuSE::PLAYBACK_TYPE_DEFAULT);+ BIND_ENUM_CONSTANT(AuSE::PLAYBACK_TYPE_STREAM);+ BIND_ENUM_CONSTANT(AuSE::PLAYBACK_TYPE_SAMPLE);+ BIND_ENUM_CONSTANT(AuSE::PLAYBACK_TYPE_MAX);}AudioServer::AudioServer() {@@ -2146,130 +1925,3 @@ AudioServer::~AudioServer() {singleton = nullptr;}--/////////////////////////////////--bool AudioBusLayout::_set(const StringName &p_name, const Variant &p_value) {- String s = p_name;- if (s.begins_with("bus/")) {- int index = s.get_slicec('/', 1).to_int();- if (buses.size() <= index) {- buses.resize(index + 1);- }-- Bus &bus = buses.write[index];-- String what = s.get_slicec('/', 2);-- if (what == "name") {- bus.name = p_value;- } else if (what == "solo") {- bus.solo = p_value;- } else if (what == "mute") {- bus.mute = p_value;- } else if (what == "bypass_fx") {- bus.bypass = p_value;- } else if (what == "volume_db") {- bus.volume_db = p_value;- } else if (what == "send") {- bus.send = p_value;- } else if (what == "effect") {- int which = s.get_slicec('/', 3).to_int();- if (bus.effects.size() <= which) {- bus.effects.resize(which + 1);- }-- Bus::Effect &fx = bus.effects.write[which];-- String fxwhat = s.get_slicec('/', 4);- if (fxwhat == "effect") {- fx.effect = p_value;- } else if (fxwhat == "enabled") {- fx.enabled = p_value;- } else {- return false;- }-- return true;- } else {- return false;- }-- return true;- }-- return false;-}--bool AudioBusLayout::_get(const StringName &p_name, Variant &r_ret) const {- String s = p_name;- if (s.begins_with("bus/")) {- int index = s.get_slicec('/', 1).to_int();- if (index < 0 || index >= buses.size()) {- return false;- }-- const Bus &bus = buses[index];-- String what = s.get_slicec('/', 2);-- if (what == "name") {- r_ret = bus.name;- } else if (what == "solo") {- r_ret = bus.solo;- } else if (what == "mute") {- r_ret = bus.mute;- } else if (what == "bypass_fx") {- r_ret = bus.bypass;- } else if (what == "volume_db") {- r_ret = bus.volume_db;- } else if (what == "send") {- r_ret = bus.send;- } else if (what == "effect") {- int which = s.get_slicec('/', 3).to_int();- if (which < 0 || which >= bus.effects.size()) {- return false;- }-- const Bus::Effect &fx = bus.effects[which];-- String fxwhat = s.get_slicec('/', 4);- if (fxwhat == "effect") {- r_ret = fx.effect;- } else if (fxwhat == "enabled") {- r_ret = fx.enabled;- } else {- return false;- }-- return true;- } else {- return false;- }-- return true;- }-- return false;-}--void AudioBusLayout::_get_property_list(List<PropertyInfo> *p_list) const {- for (int i = 0; i < buses.size(); i++) {- p_list->push_back(PropertyInfo(Variant::STRING, "bus/" + itos(i) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));- p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/solo", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));- p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/mute", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));- p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/bypass_fx", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));- p_list->push_back(PropertyInfo(Variant::FLOAT, "bus/" + itos(i) + "/volume_db", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));- p_list->push_back(PropertyInfo(Variant::FLOAT, "bus/" + itos(i) + "/send", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));-- for (int j = 0; j < buses[i].effects.size(); j++) {- p_list->push_back(PropertyInfo(Variant::OBJECT, "bus/" + itos(i) + "/effect/" + itos(j) + "/effect", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));- p_list->push_back(PropertyInfo(Variant::BOOL, "bus/" + itos(i) + "/effect/" + itos(j) + "/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));- }- }-}--AudioBusLayout::AudioBusLayout() {- buses.resize(1);- buses.write[0].name = SceneStringName(Master);-}diff --git a/servers/audio/audio_server.h b/servers/audio/audio_server.hindex efb0a58e1cc..484a3f0b83b 100644--- a/servers/audio/audio_server.h+++ b/servers/audio/audio_server.h@@ -30,179 +30,26 @@#pragma once-#include "core/math/audio_frame.h"#include "core/templates/safe_list.h"#include "core/variant/variant.h"+#include "servers/audio/audio_bus_layout.h"#include "servers/audio/audio_effect.h"#include "servers/audio/audio_filter_sw.h"+#include "servers/audio/audio_frame.h"+#include "servers/audio/audio_server_constants.h"+#include "servers/audio/audio_server_enums.h"+#include "servers/audio/audio_server_types.h" // IWYU pragma: keep. Included to have a dedicated file to move stuff over.-#include <atomic>--class AudioDriverDummy;class AudioSample;class AudioStream;-class AudioStreamWAV;class AudioStreamPlayback;class AudioSamplePlayback;--class AudioDriver {- static AudioDriver *singleton;- uint64_t _last_mix_time = 0;- uint64_t _last_mix_frames = 0;--#ifdef DEBUG_ENABLED- SafeNumeric<uint64_t> prof_ticks;- SafeNumeric<uint64_t> prof_time;-#endif--protected:- Vector<int32_t> input_buffer;- unsigned int input_position = 0;- unsigned int input_size = 0;-- void audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time = true);- void update_mix_time(int p_frames);- void input_buffer_init(int driver_buffer_frames);- void input_buffer_write(int32_t sample);-- int _get_configured_mix_rate();--#ifdef DEBUG_ENABLED- void start_counting_ticks();- void stop_counting_ticks();-#else- _FORCE_INLINE_ void start_counting_ticks() {}- _FORCE_INLINE_ void stop_counting_ticks() {}-#endif--public:- double get_time_since_last_mix(); //useful for video -> audio sync- double get_time_to_next_mix();-- enum SpeakerMode {- SPEAKER_MODE_STEREO,- SPEAKER_SURROUND_31,- SPEAKER_SURROUND_51,- SPEAKER_SURROUND_71,- };-- static AudioDriver *get_singleton();- void set_singleton();-- // Virtual API to implement.-- virtual const char *get_name() const = 0;-- virtual Error init() = 0;- virtual void start() = 0;- virtual int get_mix_rate() const = 0;- virtual int get_input_mix_rate() const { return get_mix_rate(); }- virtual SpeakerMode get_speaker_mode() const = 0;- virtual float get_latency() { return 0; }-- virtual void lock() = 0;- virtual void unlock() = 0;- virtual void finish() = 0;-- virtual PackedStringArray get_output_device_list();- virtual String get_output_device();- virtual void set_output_device(const String &p_name) {}-- virtual Error input_start() { return FAILED; }- virtual Error input_stop() { return FAILED; }-- virtual PackedStringArray get_input_device_list();- virtual String get_input_device() { return "Default"; }- virtual void set_input_device(const String &p_name) {}-- //-- SpeakerMode get_speaker_mode_by_total_channels(int p_channels) const;- int get_total_channels_by_speaker_mode(SpeakerMode) const;-- Vector<int32_t> get_input_buffer() { return input_buffer; }- unsigned int get_input_position() { return input_position; }- unsigned int get_input_size() { return input_size; }--#ifdef DEBUG_ENABLED- uint64_t get_profiling_time() const { return prof_time.get(); }- void reset_profiling_time() { prof_time.set(0); }-#endif-- // Samples handling.- virtual bool is_stream_registered_as_sample(const Ref<AudioStream> &p_stream) const {- return false;- }- virtual void register_sample(const Ref<AudioSample> &p_sample) {}- virtual void unregister_sample(const Ref<AudioSample> &p_sample) {}- virtual void start_sample_playback(const Ref<AudioSamplePlayback> &p_playback);- virtual void stop_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {}- virtual void set_sample_playback_pause(const Ref<AudioSamplePlayback> &p_playback, bool p_paused) {}- virtual bool is_sample_playback_active(const Ref<AudioSamplePlayback> &p_playback) { return false; }- virtual double get_sample_playback_position(const Ref<AudioSamplePlayback> &p_playback) { return false; }- virtual void update_sample_playback_pitch_scale(const Ref<AudioSamplePlayback> &p_playback, float p_pitch_scale = 0.0f) {}- virtual void set_sample_playback_bus_volumes_linear(const Ref<AudioSamplePlayback> &p_playback, const HashMap<StringName, Vector<AudioFrame>> &p_bus_volumes) {}-- virtual void set_sample_bus_count(int p_count) {}- virtual void remove_sample_bus(int p_bus) {}- virtual void add_sample_bus(int p_at_pos = -1) {}- virtual void move_sample_bus(int p_bus, int p_to_pos) {}- virtual void set_sample_bus_send(int p_bus, const StringName &p_send) {}- virtual void set_sample_bus_volume_db(int p_bus, float p_volume_db) {}- virtual void set_sample_bus_solo(int p_bus, bool p_enable) {}- virtual void set_sample_bus_mute(int p_bus, bool p_enable) {}-- AudioDriver() {}- virtual ~AudioDriver() {}-};--class AudioDriverManager {- enum {- MAX_DRIVERS = 10- };-- static AudioDriver *drivers[MAX_DRIVERS];- static int driver_count;-- static AudioDriverDummy dummy_driver;--public:- static const int DEFAULT_MIX_RATE = 44100;-- static void add_driver(AudioDriver *p_driver);- static void initialize(int p_driver);- static int get_driver_count();- static AudioDriver *get_driver(int p_driver);-};-class AudioBusLayout;class AudioServer : public Object {GDCLASS(AudioServer, Object);public:- //re-expose this here, as AudioDriver is not exposed to script- enum SpeakerMode {- SPEAKER_MODE_STEREO,- SPEAKER_SURROUND_31,- SPEAKER_SURROUND_51,- SPEAKER_SURROUND_71,- };-- enum PlaybackType {- PLAYBACK_TYPE_DEFAULT,- PLAYBACK_TYPE_STREAM,- PLAYBACK_TYPE_SAMPLE,- PLAYBACK_TYPE_MAX- };-- enum {- AUDIO_DATA_INVALID_ID = -1,- MAX_CHANNELS_PER_BUS = 4,- MAX_BUSES_PER_PLAYBACK = 6,- LOOKAHEAD_BUFFER_SIZE = 64,- };-typedef void (*AudioCallback)(void *p_userdata);private:@@ -245,7 +92,7 @@ private:struct Channel {bool used = false;bool active = false;- AudioFrame peak_volume = AudioFrame(AUDIO_MIN_PEAK_DB, AUDIO_MIN_PEAK_DB);+ AudioFrame peak_volume = AudioFrame(AuSC::AUDIO_MIN_PEAK_DB, AuSC::AUDIO_MIN_PEAK_DB);Vector<AudioFrame> buffer;Vector<Ref<AudioEffectInstance>> effect_instances;uint64_t last_mix_with_audio = 0;@@ -269,9 +116,9 @@ private:};struct AudioStreamPlaybackBusDetails {- bool bus_active[MAX_BUSES_PER_PLAYBACK] = {};- StringName bus[MAX_BUSES_PER_PLAYBACK];- AudioFrame volume[MAX_BUSES_PER_PLAYBACK][MAX_CHANNELS_PER_BUS];+ bool bus_active[AuSC::MAX_BUSES_PER_PLAYBACK] = {};+ StringName bus[AuSC::MAX_BUSES_PER_PLAYBACK];+ AudioFrame volume[AuSC::MAX_BUSES_PER_PLAYBACK][AuSC::MAX_CHANNELS_PER_BUS];};struct AudioStreamPlaybackListNode {@@ -305,7 +152,7 @@ private:// Previous bus details should only be accessed on the audio thread.AudioStreamPlaybackBusDetails *prev_bus_details = nullptr;// The next few samples are stored here so we have some time to fade audio out if it ends abruptly at the beginning of the next mix.- AudioFrame lookahead[LOOKAHEAD_BUFFER_SIZE];+ AudioFrame lookahead[AuSC::LOOKAHEAD_BUFFER_SIZE];};SafeList<AudioStreamPlaybackListNode *> playback_list;@@ -355,13 +202,13 @@ protected:public:_FORCE_INLINE_ int get_channel_count() const {switch (get_speaker_mode()) {- case SPEAKER_MODE_STEREO:+ case AuSE::SPEAKER_MODE_STEREO:return 1;- case SPEAKER_SURROUND_31:+ case AuSE::SPEAKER_SURROUND_31:return 2;- case SPEAKER_SURROUND_51:+ case AuSE::SPEAKER_SURROUND_51:return 3;- case SPEAKER_SURROUND_71:+ case AuSE::SPEAKER_SURROUND_71:return 4;}ERR_FAIL_V(1);@@ -464,7 +311,7 @@ public:virtual void lock();virtual void unlock();- virtual SpeakerMode get_speaker_mode() const;+ virtual AuSE::SpeakerMode get_speaker_mode() const;virtual float get_mix_rate() const;virtual float get_input_mix_rate() const;@@ -506,7 +353,7 @@ public:virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;#endif- PlaybackType get_default_playback_type() const;+ AuSE::PlaybackType get_default_playback_type() const;bool is_stream_registered_as_sample(const Ref<AudioStream> &p_stream);void register_stream_as_sample(const Ref<AudioStream> &p_stream);@@ -524,40 +371,5 @@ public:virtual ~AudioServer();};-VARIANT_ENUM_CAST(AudioServer::SpeakerMode)-VARIANT_ENUM_CAST(AudioServer::PlaybackType)--class AudioBusLayout : public Resource {- GDCLASS(AudioBusLayout, Resource);-- friend class AudioServer;-- struct Bus {- StringName name;- bool solo = false;- bool mute = false;- bool bypass = false;-- struct Effect {- Ref<AudioEffect> effect;- bool enabled = false;- };-- Vector<Effect> effects;-- float volume_db = 0.0f;- StringName send;-- Bus() {}- };-- Vector<Bus> buses;--protected:- bool _set(const StringName &p_name, const Variant &p_value);- bool _get(const StringName &p_name, Variant &r_ret) const;- void _get_property_list(List<PropertyInfo> *p_list) const;--public:- AudioBusLayout();-};+VARIANT_ENUM_CAST_EXT(AuSE::SpeakerMode, AudioServer::SpeakerMode);+VARIANT_ENUM_CAST_EXT(AuSE::PlaybackType, AudioServer::PlaybackType);diff --git a/servers/audio/audio_server_constants.h b/servers/audio/audio_server_constants.hnew file mode 100644index 00000000000..c373b1810b6--- /dev/null+++ b/servers/audio/audio_server_constants.h@@ -0,0 +1,46 @@+/**************************************************************************/+/* audio_server_constants.h */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#pragma once++namespace AudioServerConstants {++constexpr int AUDIO_DATA_INVALID_ID = -1;+constexpr int MAX_CHANNELS_PER_BUS = 4;+constexpr int MAX_BUSES_PER_PLAYBACK = 6;+constexpr int LOOKAHEAD_BUFFER_SIZE = 64;++constexpr const float AUDIO_PEAK_OFFSET = 0.0000000001f;+constexpr const float AUDIO_MIN_PEAK_DB = -200.0f; // linear_to_db(AUDIO_PEAK_OFFSET)++} // namespace AudioServerConstants++// Alias to make it easier to use.+#define AuSC AudioServerConstantsdiff --git a/servers/audio/audio_server_enums.h b/servers/audio/audio_server_enums.hnew file mode 100644index 00000000000..760e805d7b6--- /dev/null+++ b/servers/audio/audio_server_enums.h@@ -0,0 +1,57 @@+/**************************************************************************/+/* audio_server_enums.h */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#pragma once++namespace AudioServerEnums {++//re-expose this here, as AudioDriver is not exposed to script+enum SpeakerMode {+ SPEAKER_MODE_STEREO,+ SPEAKER_SURROUND_31,+ SPEAKER_SURROUND_51,+ SPEAKER_SURROUND_71,+};++enum PlaybackType {+ PLAYBACK_TYPE_DEFAULT,+ PLAYBACK_TYPE_STREAM,+ PLAYBACK_TYPE_SAMPLE,+ PLAYBACK_TYPE_MAX+};++#ifndef DISABLE_DEPRECATED+// Graveyard.+#endif++} // namespace AudioServerEnums++// Alias to make it easier to use.+#define AuSE AudioServerEnumsdiff --git a/servers/audio/audio_server_types.h b/servers/audio/audio_server_types.hnew file mode 100644index 00000000000..43d8c6e8cbe--- /dev/null+++ b/servers/audio/audio_server_types.h@@ -0,0 +1,44 @@+/**************************************************************************/+/* audio_server_types.h */+/**************************************************************************/+/* This file is part of: */+/* GODOT ENGINE */+/* https://godotengine.org */+/**************************************************************************/+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */+/* */+/* Permission is hereby granted, free of charge, to any person obtaining */+/* a copy of this software and associated documentation files (the */+/* "Software"), to deal in the Software without restriction, including */+/* without limitation the rights to use, copy, modify, merge, publish, */+/* distribute, sublicense, and/or sell copies of the Software, and to */+/* permit persons to whom the Software is furnished to do so, subject to */+/* the following conditions: */+/* */+/* The above copyright notice and this permission notice shall be */+/* included in all copies or substantial portions of the Software. */+/* */+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */+/**************************************************************************/++#pragma once++namespace AudioServerTypes {++//struct Stuff {};++#ifndef DISABLE_DEPRECATED+// Graveyard.+#endif++} // namespace AudioServerTypes++// Alias to make it easier to use.+#define AuST AudioServerTypesdiff --git a/servers/audio/effects/audio_effect_capture.h b/servers/audio/effects/audio_effect_capture.hindex 46ec40abc23..dcebb45d065 100644--- a/servers/audio/effects/audio_effect_capture.h+++ b/servers/audio/effects/audio_effect_capture.h@@ -30,10 +30,10 @@#pragma once-#include "core/math/audio_frame.h"#include "core/object/ref_counted.h"#include "core/templates/ring_buffer.h"#include "servers/audio/audio_effect.h"+#include "servers/audio/audio_frame.h"class AudioEffectCapture;diff --git a/servers/audio/effects/audio_effect_record.cpp b/servers/audio/effects/audio_effect_record.cppindex 8919e8613dd..9d11e3d2011 100644--- a/servers/audio/effects/audio_effect_record.cpp+++ b/servers/audio/effects/audio_effect_record.cpp@@ -33,6 +33,7 @@#include "core/io/marshalls.h"#include "core/object/class_db.h"#include "core/os/os.h"+#include "servers/audio/audio_server.h"void AudioEffectRecordInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) {if (!is_recording) {diff --git a/servers/audio/effects/audio_effect_record.h b/servers/audio/effects/audio_effect_record.hindex 088c03bce6a..facd6df04d0 100644--- a/servers/audio/effects/audio_effect_record.h+++ b/servers/audio/effects/audio_effect_record.h@@ -31,9 +31,8 @@#pragma once#include "core/os/thread.h"-#include "scene/resources/audio_stream_wav.h"+#include "scene/resources/audio/audio_stream_wav.h"#include "servers/audio/audio_effect.h"-#include "servers/audio/audio_server.h"class AudioEffectRecord;diff --git a/servers/audio/effects/reverb_filter.cpp b/servers/audio/effects/reverb_filter.cppindex 90a350b347f..98ace50da87 100644--- a/servers/audio/effects/reverb_filter.cpp+++ b/servers/audio/effects/reverb_filter.cpp@@ -30,8 +30,8 @@#include "reverb_filter.h"-#include "core/math/audio_frame.h"#include "core/os/memory.h"+#include "servers/audio/audio_frame.h"const float Reverb::comb_tunings[MAX_COMBS] = {//freeverb comb tuningsdiff --git a/servers/movie_writer/movie_writer.cpp b/servers/movie_writer/movie_writer.cppindex 8a1efb47674..0b992993dff 100644--- a/servers/movie_writer/movie_writer.cpp+++ b/servers/movie_writer/movie_writer.cpp@@ -63,8 +63,9 @@ uint32_t MovieWriter::get_audio_mix_rate() const {GDVIRTUAL_CALL(_get_audio_mix_rate, ret);return ret;}-AudioServer::SpeakerMode MovieWriter::get_audio_speaker_mode() const {- AudioServer::SpeakerMode ret = AudioServer::SPEAKER_MODE_STEREO;++AuSE::SpeakerMode MovieWriter::get_audio_speaker_mode() const {+ AuSE::SpeakerMode ret = AuSE::SPEAKER_MODE_STEREO;GDVIRTUAL_CALL(_get_audio_speaker_mode, ret);return ret;}diff --git a/servers/movie_writer/movie_writer.h b/servers/movie_writer/movie_writer.hindex 14ffd07033c..7f917d84c67 100644--- a/servers/movie_writer/movie_writer.h+++ b/servers/movie_writer/movie_writer.h@@ -32,7 +32,8 @@#include "core/io/image.h"#include "core/templates/local_vector.h"-#include "servers/audio/audio_server.h"+#include "servers/audio/audio_server.h" // IWYU pragma: keep. Bind GDVIRTUAL0RC_REQUIRED.+#include "servers/audio/audio_server_enums.h"class MovieWriter : public Object {GDCLASS(MovieWriter, Object);@@ -61,14 +62,14 @@ class MovieWriter : public Object {protected:virtual uint32_t get_audio_mix_rate() const;- virtual AudioServer::SpeakerMode get_audio_speaker_mode() const;+ virtual AuSE::SpeakerMode get_audio_speaker_mode() const;virtual Error write_begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path);virtual Error write_frame(const Ref<Image> &p_image, const int32_t *p_audio_data);virtual void write_end();GDVIRTUAL0RC_REQUIRED(uint32_t, _get_audio_mix_rate)- GDVIRTUAL0RC_REQUIRED(AudioServer::SpeakerMode, _get_audio_speaker_mode)+ GDVIRTUAL0RC_REQUIRED(AuSE::SpeakerMode, _get_audio_speaker_mode)GDVIRTUAL1RC_REQUIRED(bool, _handles_file, const String &)GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_supported_extensions)diff --git a/servers/movie_writer/movie_writer_pngwav.cpp b/servers/movie_writer/movie_writer_pngwav.cppindex c6593cbcb37..c76f66f776f 100644--- a/servers/movie_writer/movie_writer_pngwav.cpp+++ b/servers/movie_writer/movie_writer_pngwav.cpp@@ -37,7 +37,7 @@uint32_t MovieWriterPNGWAV::get_audio_mix_rate() const {return mix_rate;}-AudioServer::SpeakerMode MovieWriterPNGWAV::get_audio_speaker_mode() const {+AuSE::SpeakerMode MovieWriterPNGWAV::get_audio_speaker_mode() const {return speaker_mode;}@@ -99,16 +99,16 @@ Error MovieWriterPNGWAV::write_begin(const Size2i &p_movie_size, uint32_t p_fps,uint32_t channels = 2;switch (speaker_mode) {- case AudioServer::SPEAKER_MODE_STEREO:+ case AuSE::SPEAKER_MODE_STEREO:channels = 2;break;- case AudioServer::SPEAKER_SURROUND_31:+ case AuSE::SPEAKER_SURROUND_31:channels = 4;break;- case AudioServer::SPEAKER_SURROUND_51:+ case AuSE::SPEAKER_SURROUND_51:channels = 6;break;- case AudioServer::SPEAKER_SURROUND_71:+ case AuSE::SPEAKER_SURROUND_71:channels = 8;break;}@@ -168,5 +168,5 @@ void MovieWriterPNGWAV::write_end() {MovieWriterPNGWAV::MovieWriterPNGWAV() {mix_rate = GLOBAL_GET("editor/movie_writer/mix_rate");- speaker_mode = AudioServer::SpeakerMode(int(GLOBAL_GET("editor/movie_writer/speaker_mode")));+ speaker_mode = AuSE::SpeakerMode(int(GLOBAL_GET("editor/movie_writer/speaker_mode")));}diff --git a/servers/movie_writer/movie_writer_pngwav.h b/servers/movie_writer/movie_writer_pngwav.hindex b2744b0e02c..b2a1ba01ce4 100644--- a/servers/movie_writer/movie_writer_pngwav.h+++ b/servers/movie_writer/movie_writer_pngwav.h@@ -40,7 +40,7 @@ class MovieWriterPNGWAV : public MovieWriter {};uint32_t mix_rate = 48000;- AudioServer::SpeakerMode speaker_mode = AudioServer::SPEAKER_MODE_STEREO;+ AuSE::SpeakerMode speaker_mode = AuSE::SPEAKER_MODE_STEREO;String base_path;uint32_t frame_count = 0;uint32_t fps = 0;@@ -54,7 +54,7 @@ class MovieWriterPNGWAV : public MovieWriter {protected:virtual uint32_t get_audio_mix_rate() const override;- virtual AudioServer::SpeakerMode get_audio_speaker_mode() const override;+ virtual AuSE::SpeakerMode get_audio_speaker_mode() const override;virtual void get_supported_extensions(List<String> *r_extensions) const override;virtual Error write_begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path) override;diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cppindex 5d954638853..7371567f07a 100644--- a/servers/register_server_types.cpp+++ b/servers/register_server_types.cpp@@ -35,8 +35,8 @@#include "core/object/callable_mp.h"#include "core/os/os.h"#include "servers/audio/audio_effect.h"+#include "servers/audio/audio_frame.h"#include "servers/audio/audio_server.h"-#include "servers/audio/audio_stream.h"#include "servers/audio/effects/audio_effect_amplify.h"#include "servers/audio/effects/audio_effect_capture.h"#include "servers/audio/effects/audio_effect_chorus.h"@@ -53,7 +53,6 @@#include "servers/audio/effects/audio_effect_reverb.h"#include "servers/audio/effects/audio_effect_spectrum_analyzer.h"#include "servers/audio/effects/audio_effect_stereo_enhance.h"-#include "servers/audio/effects/audio_stream_generator.h"#include "servers/camera/camera_feed.h"#include "servers/camera/camera_server.h"#include "servers/debugger/servers_debugger.h"@@ -171,7 +170,9 @@ void register_server_types() {GDREGISTER_ABSTRACT_CLASS(AccessibilityServer);GDREGISTER_ABSTRACT_CLASS(DisplayServer);GDREGISTER_ABSTRACT_CLASS(RenderingServer);+GDREGISTER_CLASS(AudioServer);+ GDREGISTER_NATIVE_STRUCT(AudioFrame, "float left;float right");GDREGISTER_CLASS(NativeMenu);@@ -179,11 +180,6 @@ void register_server_types() {GDREGISTER_ABSTRACT_CLASS(RenderingDevice);- GDREGISTER_CLASS(AudioStream);- GDREGISTER_CLASS(AudioStreamPlayback);- GDREGISTER_VIRTUAL_CLASS(AudioStreamPlaybackResampled);- GDREGISTER_CLASS(AudioStreamMicrophone);- GDREGISTER_CLASS(AudioStreamRandomizer);GDREGISTER_CLASS(AudioSample);GDREGISTER_CLASS(AudioSamplePlayback);GDREGISTER_VIRTUAL_CLASS(AudioEffect);@@ -192,9 +188,6 @@ void register_server_types() {GDREGISTER_CLASS(AudioEffectFilter);GDREGISTER_CLASS(AudioBusLayout);- GDREGISTER_CLASS(AudioStreamGenerator);- GDREGISTER_ABSTRACT_CLASS(AudioStreamGeneratorPlayback);-{//audio effectsGDREGISTER_CLASS(AudioEffectAmplify);diff --git a/tests/scene/test_audio_stream_wav.cpp b/tests/scene/test_audio_stream_wav.cppindex 03ac7c27f41..ab3e261f15a 100644--- a/tests/scene/test_audio_stream_wav.cpp+++ b/tests/scene/test_audio_stream_wav.cpp@@ -36,7 +36,7 @@ TEST_FORCE_LINK(test_audio_stream_wav)#include "core/io/marshalls.h"#include "core/math/math_defs.h"#include "core/math/math_funcs.h"-#include "scene/resources/audio_stream_wav.h"+#include "scene/resources/audio/audio_stream_wav.h"#include "tests/test_utils.h"namespace TestAudioStreamWAV {diff --git a/tests/test_main.cpp b/tests/test_main.cppindex 935fab78fac..53260d8971d 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -40,6 +40,7 @@#include "scene/main/scene_tree.h"#include "scene/main/window.h"#include "scene/theme/theme_db.h"+#include "servers/audio/audio_driver.h"#include "servers/audio/audio_server.h"#include "servers/display/accessibility_server.h"#include "servers/rendering/rendering_server.h"