summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/rtaudio/audio_driver_rtaudio.cpp2
-rw-r--r--platform/android/os_android.cpp7
-rw-r--r--platform/haiku/os_haiku.cpp6
-rw-r--r--platform/javascript/os_javascript.cpp6
-rw-r--r--platform/osx/os_osx.mm7
-rw-r--r--platform/server/os_server.cpp8
-rw-r--r--platform/server/os_server.h2
-rw-r--r--platform/uwp/os_uwp.cpp7
-rw-r--r--platform/windows/os_windows.cpp7
-rw-r--r--platform/x11/os_x11.cpp33
-rw-r--r--platform/x11/os_x11.h7
-rw-r--r--servers/audio_server.cpp39
-rw-r--r--servers/audio_server.h5
13 files changed, 53 insertions, 83 deletions
diff --git a/drivers/rtaudio/audio_driver_rtaudio.cpp b/drivers/rtaudio/audio_driver_rtaudio.cpp
index ae5fdd28b6..a184c9e9cf 100644
--- a/drivers/rtaudio/audio_driver_rtaudio.cpp
+++ b/drivers/rtaudio/audio_driver_rtaudio.cpp
@@ -143,7 +143,7 @@ Error AudioDriverRtAudio::init() {
}
}
- return OK;
+ return active ? OK : ERR_UNAVAILABLE;
}
int AudioDriverRtAudio::get_mix_rate() const {
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp
index 1de2608b9e..dbea2d7531 100644
--- a/platform/android/os_android.cpp
+++ b/platform/android/os_android.cpp
@@ -137,12 +137,7 @@ void OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int
visual_server->init();
// visual_server->cursor_set_visible(false, 0);
- AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
-
- if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
-
- ERR_PRINT("Initializing audio failed.");
- }
+ AudioDriverManager::initialize(p_audio_driver);
physics_server = memnew(PhysicsServerSW);
physics_server->init();
diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp
index de2f79a0ac..9f2f88bb4e 100644
--- a/platform/haiku/os_haiku.cpp
+++ b/platform/haiku/os_haiku.cpp
@@ -137,11 +137,7 @@ void OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_
//physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
physics_2d_server->init();
- AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
-
- if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
- ERR_PRINT("Initializing audio failed.");
- }
+ AudioDriverManager::initialize(p_audio_driver);
power_manager = memnew(PowerHaiku);
}
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index ac8d367366..c7484b593f 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -464,11 +464,7 @@ void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, i
print_line("Init Audio");
AudioDriverManager::add_driver(&audio_driver_javascript);
- audio_driver_javascript.set_singleton();
- if (audio_driver_javascript.init() != OK) {
-
- ERR_PRINT("Initializing audio failed.");
- }
+ AudioDriverManager::initialize(p_audio_driver);
RasterizerGLES3::register_config();
RasterizerGLES3::make_current();
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index beda6f4c38..96ab743be5 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -1088,12 +1088,7 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
visual_server->init();
// visual_server->cursor_set_visible(false, 0);
- AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
-
- if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
-
- ERR_PRINT("Initializing audio failed.");
- }
+ AudioDriverManager::initialize(p_audio_driver);
//
physics_server = memnew(PhysicsServerSW);
diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp
index 44034e815d..f3ed9a582f 100644
--- a/platform/server/os_server.cpp
+++ b/platform/server/os_server.cpp
@@ -62,12 +62,7 @@ void OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p
//visual_server = memnew( VisualServerRaster(rasterizer) );
- AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
-
- if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
-
- ERR_PRINT("Initializing audio failed.");
- }
+ AudioDriverManager::initialize(p_audio_driver);
sample_manager = memnew(SampleManagerMallocSW);
audio_server = memnew(AudioServerSW(sample_manager));
@@ -232,7 +227,6 @@ void OS_Server::run() {
OS_Server::OS_Server() {
- AudioDriverManager::add_driver(&driver_dummy);
//adriver here
grab = false;
};
diff --git a/platform/server/os_server.h b/platform/server/os_server.h
index f3db053be3..314167604c 100644
--- a/platform/server/os_server.h
+++ b/platform/server/os_server.h
@@ -34,7 +34,6 @@
#include "drivers/rtaudio/audio_driver_rtaudio.h"
#include "drivers/unix/os_unix.h"
#include "main/input_default.h"
-#include "servers/audio/audio_driver_dummy.h"
#include "servers/audio_server.h"
#include "servers/physics_2d/physics_2d_server_sw.h"
#include "servers/physics_server.h"
@@ -55,7 +54,6 @@ class OS_Server : public OS_Unix {
List<String> args;
MainLoop *main_loop;
- AudioDriverDummy driver_dummy;
bool grab;
PhysicsServer *physics_server;
diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp
index 3a8932aae2..920bc9fe36 100644
--- a/platform/uwp/os_uwp.cpp
+++ b/platform/uwp/os_uwp.cpp
@@ -268,12 +268,7 @@ void OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_aud
joypad = ref new JoypadUWP(input);
joypad->register_events();
- AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
-
- if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
-
- ERR_PRINT("Initializing audio failed.");
- }
+ AudioDriverManager::initialize(p_audio_driver);
power_manager = memnew(PowerUWP);
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 530072db6e..75ffc3153b 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -1081,12 +1081,7 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
power_manager = memnew(PowerWindows);
- AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
-
- if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
-
- ERR_PRINT("Initializing audio failed.");
- }
+ AudioDriverManager::initialize(p_audio_driver);
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(TRACKMOUSEEVENT);
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index f61ccacb98..2b317e7e97 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -313,29 +313,7 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
XFree(xsh);
}
- AudioDriverManager::get_driver(p_audio_driver)->set_singleton();
-
- audio_driver_index = p_audio_driver;
- if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) {
-
- bool success = false;
- audio_driver_index = -1;
- for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
- if (i == p_audio_driver)
- continue;
- AudioDriverManager::get_driver(i)->set_singleton();
- if (AudioDriverManager::get_driver(i)->init() == OK) {
- success = true;
- print_line("Audio Driver Failed: " + String(AudioDriverManager::get_driver(p_audio_driver)->get_name()));
- print_line("Using alternate audio driver: " + String(AudioDriverManager::get_driver(i)->get_name()));
- audio_driver_index = i;
- break;
- }
- }
- if (!success) {
- ERR_PRINT("Initializing audio failed.");
- }
- }
+ AudioDriverManager::initialize(p_audio_driver);
ERR_FAIL_COND(!visual_server);
ERR_FAIL_COND(x11_window == 0);
@@ -2189,10 +2167,6 @@ bool OS_X11::is_disable_crash_handler() const {
OS_X11::OS_X11() {
-#ifdef RTAUDIO_ENABLED
- AudioDriverManager::add_driver(&driver_rtaudio);
-#endif
-
#ifdef PULSEAUDIO_ENABLED
AudioDriverManager::add_driver(&driver_pulseaudio);
#endif
@@ -2201,11 +2175,6 @@ OS_X11::OS_X11() {
AudioDriverManager::add_driver(&driver_alsa);
#endif
- if (AudioDriverManager::get_driver_count() == 0) {
- WARN_PRINT("No sound driver found... Defaulting to dummy driver");
- AudioDriverManager::add_driver(&driver_dummy);
- }
-
minimized = false;
xim_style = 0L;
mouse_mode = MOUSE_MODE_VISIBLE;
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 14c737d45e..1373212e37 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -38,11 +38,9 @@
//#include "servers/visual/visual_server_wrap_mt.h"
#include "drivers/alsa/audio_driver_alsa.h"
#include "drivers/pulseaudio/audio_driver_pulseaudio.h"
-#include "drivers/rtaudio/audio_driver_rtaudio.h"
#include "joypad_linux.h"
#include "main/input_default.h"
#include "power_x11.h"
-#include "servers/audio/audio_driver_dummy.h"
#include "servers/audio_server.h"
#include "servers/physics_2d/physics_2d_server_sw.h"
#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
@@ -154,10 +152,6 @@ class OS_X11 : public OS_Unix {
JoypadLinux *joypad;
#endif
-#ifdef RTAUDIO_ENABLED
- AudioDriverRtAudio driver_rtaudio;
-#endif
-
#ifdef ALSA_ENABLED
AudioDriverALSA driver_alsa;
#endif
@@ -165,7 +159,6 @@ class OS_X11 : public OS_Unix {
#ifdef PULSEAUDIO_ENABLED
AudioDriverPulseAudio driver_pulseaudio;
#endif
- AudioDriverDummy driver_dummy;
Atom net_wm_icon;
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index ed62e65846..a18ad327c5 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -32,6 +32,7 @@
#include "os/file_access.h"
#include "os/os.h"
#include "project_settings.h"
+#include "servers/audio/audio_driver_dummy.h"
#include "servers/audio/effects/audio_effect_compressor.h"
#ifdef TOOLS_ENABLED
@@ -107,6 +108,7 @@ AudioDriver::AudioDriver() {
AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS];
int AudioDriverManager::driver_count = 0;
+AudioDriverDummy AudioDriverManager::dummy_driver;
void AudioDriverManager::add_driver(AudioDriver *p_driver) {
@@ -118,6 +120,43 @@ int AudioDriverManager::get_driver_count() {
return driver_count;
}
+
+void AudioDriverManager::initialize(int p_driver) {
+ AudioDriver *driver;
+ 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();
+ return;
+ }
+ }
+
+ // Fallback to our dummy driver
+ if (dummy_driver.init() == OK) {
+ ERR_PRINT("AudioDriverManager: all drivers failed, falling back to dummy driver");
+ dummy_driver.set_singleton();
+ } else {
+ ERR_PRINT("AudioDriverManager: dummy driver faild to init()");
+ }
+}
+
AudioDriver *AudioDriverManager::get_driver(int p_driver) {
ERR_FAIL_INDEX_V(p_driver, driver_count, NULL);
diff --git a/servers/audio_server.h b/servers/audio_server.h
index c479d09a3c..55e9367308 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -35,6 +35,8 @@
#include "servers/audio/audio_effect.h"
#include "variant.h"
+class AudioDriverDummy;
+
class AudioDriver {
static AudioDriver *singleton;
@@ -90,8 +92,11 @@ class AudioDriverManager {
static AudioDriver *drivers[MAX_DRIVERS];
static int driver_count;
+ static AudioDriverDummy dummy_driver;
+
public:
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);
};