From 28f4204b09b04280340ffbbeaccf86b96f377296 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:12:55 +1000 Subject: more Voice work --- source/application/StarMainApplication_sdl.cpp | 52 ++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 7 deletions(-) (limited to 'source/application/StarMainApplication_sdl.cpp') diff --git a/source/application/StarMainApplication_sdl.cpp b/source/application/StarMainApplication_sdl.cpp index a7dc50f..8f47eeb 100644 --- a/source/application/StarMainApplication_sdl.cpp +++ b/source/application/StarMainApplication_sdl.cpp @@ -292,15 +292,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(); @@ -311,7 +311,10 @@ public: ~SdlPlatform() { - SDL_CloseAudioDevice(m_sdlAudioDevice); + if (m_sdlAudioOutputDevice) + SDL_CloseAudioDevice(m_sdlAudioOutputDevice); + + closeAudioInputDevice(); m_renderer.reset(); @@ -321,6 +324,32 @@ 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 = {}; + return (m_sdlAudioInputDevice = SDL_OpenAudioDevice(name, 1, &desired, &obtained, 0)) != 0; + } + + bool closeAudioInputDevice() { + if (m_sdlAudioInputDevice) { + SDL_CloseAudioDevice(m_sdlAudioInputDevice); + m_sdlAudioInputDevice = 0; + + return true; + } + + return false; + } + void cleanup() { m_cursorCache.ptr(m_currentCursor); m_cursorCache.cleanup(); @@ -397,7 +426,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 +598,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 +840,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 SDLGameControllerUPtr; StableHashMap m_SdlControllers; -- cgit v1.2.3