From f3229f111c5786505c46746f4166594779967cae Mon Sep 17 00:00:00 2001 From: Aloshi Date: Mon, 20 May 2013 10:57:04 -0500 Subject: [PATCH] Fix for audio not reinitializing on restart. --- src/AudioManager.cpp | 13 +++++++++++-- src/AudioManager.h | 3 +++ src/Window.cpp | 2 ++ src/main.cpp | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/AudioManager.cpp b/src/AudioManager.cpp index d1cb02c17..05f0a93b9 100644 --- a/src/AudioManager.cpp +++ b/src/AudioManager.cpp @@ -50,6 +50,15 @@ void AudioManager::mixAudio(void *unused, Uint8 *stream, int len) } AudioManager::AudioManager() +{ +} + +AudioManager::~AudioManager() +{ + deinit(); +} + +void AudioManager::init() { //Set up format and callback. Play 16-bit stereo audio at 44.1Khz sAudioFormat.freq = 44100; @@ -65,7 +74,7 @@ AudioManager::AudioManager() } } -AudioManager::~AudioManager() +void AudioManager::deinit() { SDL_PauseAudio(1); SDL_CloseAudio(); @@ -97,4 +106,4 @@ void AudioManager::play() { //unpause audio, the mixer will figure out if samples need to be played... SDL_PauseAudio(0); -} \ No newline at end of file +} diff --git a/src/AudioManager.h b/src/AudioManager.h index b20a965b2..af3b0dbf1 100644 --- a/src/AudioManager.h +++ b/src/AudioManager.h @@ -26,6 +26,9 @@ public: static void play(); virtual ~AudioManager(); + + static void init(); + static void deinit(); }; #endif diff --git a/src/Window.cpp b/src/Window.cpp index 119ac9c5f..26e36a983 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -53,6 +53,7 @@ void Window::init() { mInputManager->init(); Renderer::init(0, 0); + AudioManager::init(); for(unsigned int i = 0; i < mGuiStack.size(); i++) { @@ -68,6 +69,7 @@ void Window::deinit() } mInputManager->deinit(); + AudioManager::deinit(); Renderer::deinit(); } diff --git a/src/main.cpp b/src/main.cpp index d0f347903..90d7617fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,6 @@ #include "SystemData.h" #include #include "components/GuiDetectDevice.h" -#include "AudioManager.h" #include "platform.h" #include "Log.h" #include "Window.h" @@ -121,6 +120,7 @@ int main(int argc, char* argv[]) Window window; //don't call Window.init() because we manually pass the resolution to Renderer::init window.getInputManager()->init(); + AudioManager::init(); //try loading the system config file if(!fs::exists(SystemData::getConfigPath())) //if it doesn't exist, create the example and quit