summaryrefslogtreecommitdiff
path: root/Runtime/Audio/AudioManager.Callbacks.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Audio/AudioManager.Callbacks.cpp
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/Audio/AudioManager.Callbacks.cpp')
-rw-r--r--Runtime/Audio/AudioManager.Callbacks.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/Runtime/Audio/AudioManager.Callbacks.cpp b/Runtime/Audio/AudioManager.Callbacks.cpp
new file mode 100644
index 0000000..6db2b9c
--- /dev/null
+++ b/Runtime/Audio/AudioManager.Callbacks.cpp
@@ -0,0 +1,37 @@
+#include "UnityPrefix.h"
+#if ENABLE_AUDIO_FMOD
+#include "AudioManager.h"
+#include "Runtime/Audio/correct_fmod_includer.h"
+
+FMOD_RESULT F_CALLBACK AudioManager::systemCallback(FMOD_SYSTEM* c_system, FMOD_SYSTEM_CALLBACKTYPE type, void* data1, void* data2)
+{
+ FMOD::System* system = (FMOD::System*)c_system;
+ FMOD_RESULT result = FMOD_OK;
+
+ switch (type)
+ {
+ case FMOD_SYSTEM_CALLBACKTYPE_DEVICELISTCHANGED:
+ // Get available sound cards
+ // If no device is found fall back on the NOSOUND driver
+ // @TODO Enable user to choose driver
+ int numDrivers;
+ result = system->getNumDrivers(&numDrivers);
+
+ if ((result == FMOD_OK) && (numDrivers != 0))
+ {
+ // set driver to the new default driver
+ // and autodetect output
+ result = system->setDriver(0);
+ if (result != FMOD_OK)
+ {
+ ErrorString(Format("Default audio device was changed, but the audio system failed to initialize it (%s). This may be because the audio device that Unity was started on and the device switched to have different sampling rates or speaker configurations. To get sound back you can either adjust the sampling rate on the new device (on Windows using the control panel, on Mac via the Audio MIDI Setup application), switch back to the old device or restart Unity.",FMOD_ErrorString(result)));
+ return result;
+ }
+ }
+ break;
+ default: break;
+ }
+
+ return result;
+}
+#endif //ENABLE_AUDIO \ No newline at end of file