Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/application/StarMainApplication_sdl.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-07-20 15:00:59 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-07-20 15:00:59 +1000
commitc1ae23808677028ef6ac1b7f0b19b298d78affc2 (patch)
tree0310c9d5e4673ea49add9791713fdd83b81ed87f /source/application/StarMainApplication_sdl.cpp
parent9d66acde2ae6896607da953e20ba5bbfc23948f6 (diff)
parent043db1841ee46ace0f6919bfdf6ac20a539faaca (diff)
Merge branch 'voice'
Diffstat (limited to 'source/application/StarMainApplication_sdl.cpp')
-rw-r--r--source/application/StarMainApplication_sdl.cpp73
1 files changed, 64 insertions, 9 deletions
diff --git a/source/application/StarMainApplication_sdl.cpp b/source/application/StarMainApplication_sdl.cpp
index a7dc50f..8b8c702 100644
--- a/source/application/StarMainApplication_sdl.cpp
+++ b/source/application/StarMainApplication_sdl.cpp
@@ -248,9 +248,15 @@ public:
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER))
throw ApplicationException(strf("Couldn't initialize SDL Controller: {}", SDL_GetError()));
- Logger::info("Application: Initializing SDL Sound");
+#ifdef STAR_SYSTEM_WINDOWS // Newer SDL is defaulting to xaudio2, which does not support audio capture
+ SDL_setenv("SDL_AUDIODRIVER", "directsound", 1);
+#endif
+
+ Logger::info("Application: Initializing SDL Audio");
if (SDL_InitSubSystem(SDL_INIT_AUDIO))
- throw ApplicationException(strf("Couldn't initialize SDL Sound: {}", SDL_GetError()));
+ throw ApplicationException(strf("Couldn't initialize SDL Audio: {}", SDL_GetError()));
+
+ Logger::info("Application: using Audio Driver '{}'", SDL_GetCurrentAudioDriver());
SDL_JoystickEventState(SDL_ENABLE);
@@ -292,15 +298,15 @@ public:
};
SDL_AudioSpec obtained = {};
- m_sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, 0);
- if (!m_sdlAudioDevice) {
+ m_sdlAudioOutputDevice = SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, 0);
+ if (!m_sdlAudioOutputDevice) {
Logger::error("Application: Could not open audio device, no sound available!");
} else if (obtained.freq != desired.freq || obtained.channels != desired.channels || obtained.format != desired.format) {
- SDL_CloseAudioDevice(m_sdlAudioDevice);
+ SDL_CloseAudioDevice(m_sdlAudioOutputDevice);
Logger::error("Application: Could not open 44.1khz / 16 bit stereo audio device, no sound available!");
} else {
Logger::info("Application: Opened default audio device with 44.1khz / 16 bit stereo audio, {} sample size buffer", obtained.samples);
- SDL_PauseAudioDevice(m_sdlAudioDevice, 0);
+ SDL_PauseAudioDevice(m_sdlAudioOutputDevice, 0);
}
m_renderer = make_shared<OpenGl20Renderer>();
@@ -311,7 +317,10 @@ public:
~SdlPlatform() {
- SDL_CloseAudioDevice(m_sdlAudioDevice);
+ if (m_sdlAudioOutputDevice)
+ SDL_CloseAudioDevice(m_sdlAudioOutputDevice);
+
+ closeAudioInputDevice();
m_renderer.reset();
@@ -321,6 +330,43 @@ public:
SDL_Quit();
}
+ bool openAudioInputDevice(const char* name, int freq, int channels, void* userdata, SDL_AudioCallback callback) {
+ SDL_AudioSpec desired = {};
+ desired.freq = freq;
+ desired.format = AUDIO_S16SYS;
+ desired.samples = 1024;
+ desired.channels = channels;
+ desired.userdata = userdata;
+ desired.callback = callback;
+
+ closeAudioInputDevice();
+
+ SDL_AudioSpec obtained = {};
+ m_sdlAudioInputDevice = SDL_OpenAudioDevice(name, 1, &desired, &obtained, 0);
+
+ if (m_sdlAudioInputDevice) {
+ if (name)
+ Logger::info("Opened audio input device '{}'", name);
+ else
+ Logger::info("Opened default audio input device");
+ SDL_PauseAudioDevice(m_sdlAudioInputDevice, 0);
+ }
+ else
+ Logger::info("Failed to open audio input device: {}", SDL_GetError());
+
+ return m_sdlAudioInputDevice != 0;
+ }
+
+ bool closeAudioInputDevice() {
+ if (m_sdlAudioInputDevice) {
+ Logger::info("Closing audio input device");
+ SDL_CloseAudioDevice(m_sdlAudioInputDevice);
+ m_sdlAudioInputDevice = 0;
+ return true;
+ }
+ return false;
+ }
+
void cleanup() {
m_cursorCache.ptr(m_currentCursor);
m_cursorCache.cleanup();
@@ -397,7 +443,7 @@ public:
Logger::error("Application: threw exception during shutdown: {}", outputException(e, true));
}
- SDL_CloseAudioDevice(m_sdlAudioDevice);
+ SDL_CloseAudioDevice(m_sdlAudioOutputDevice);
m_SdlControllers.clear();
SDL_SetCursor(NULL);
@@ -569,6 +615,14 @@ private:
SDL_PauseAudio(true);
}
+ bool openAudioInputDevice(const char* name, int freq, int channels, void* userdata, AudioCallback callback) override {
+ return parent->openAudioInputDevice(name, freq, channels, userdata, callback);
+ };
+
+ bool closeAudioInputDevice() override {
+ return parent->closeAudioInputDevice();
+ };
+
float updateRate() const override {
return parent->m_updateRate;
}
@@ -803,7 +857,8 @@ private:
SDL_Window* m_sdlWindow = nullptr;
SDL_GLContext m_sdlGlContext = nullptr;
- SDL_AudioDeviceID m_sdlAudioDevice = 0;
+ SDL_AudioDeviceID m_sdlAudioOutputDevice = 0;
+ SDL_AudioDeviceID m_sdlAudioInputDevice = 0;
typedef std::unique_ptr<SDL_GameController, decltype(&SDL_GameControllerClose)> SDLGameControllerUPtr;
StableHashMap<int, SDLGameControllerUPtr> m_SdlControllers;