diff --git a/AV.cc b/AV.cc index e57d061..0936425 100644 --- a/AV.cc +++ b/AV.cc @@ -60,10 +60,14 @@ AV::AV() cerr << "SDL_OpenAudio() error." << endl; exit(3); } + + m_active_sounds_mutex = SDL_CreateMutex(); } AV::~AV() { + SDL_PauseAudio(1); + SDL_DestroyMutex(m_active_sounds_mutex); SDL_CloseAudio(); Sound_Quit(); SDL_Quit(); @@ -134,13 +138,16 @@ refptr AV::createSound() void AV::playSound(AV::Sound * s) { + SDL_mutexP(m_active_sounds_mutex); m_active_sounds.insert(s); + SDL_mutexV(m_active_sounds_mutex); SDL_PauseAudio(0); } void AV::playCallback(Uint8 * stream, int len) { memset(stream, 0, len); + SDL_mutexP(m_active_sounds_mutex); for (std::set::iterator it = m_active_sounds.begin(); it != m_active_sounds.end(); it++) @@ -154,6 +161,7 @@ void AV::playCallback(Uint8 * stream, int len) { SDL_PauseAudio(1); } + SDL_mutexV(m_active_sounds_mutex); } AV::Sound::Sound(AV & av) diff --git a/AV.h b/AV.h index 149543c..b420bfb 100644 --- a/AV.h +++ b/AV.h @@ -77,6 +77,7 @@ class AV std::set< refptr > m_sounds; #endif std::set< Sound * > m_active_sounds; + SDL_mutex * m_active_sounds_mutex; }; #endif