From 5c41e31f6084b08debee474a431e0f32d0f8be0b Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 12 Apr 2004 20:02:47 +0000 Subject: [PATCH] add SOUND->PlayOnceFromAnnouncer(); this is now the preferred way to play an announcer. Announcer files are in many separate directories; scanning a directory can cause a skip, so we don't want to do that in the main thread during gameplay. --- stepmania/src/RageSounds.cpp | 64 ++++++++++++++++++++++++++---------- stepmania/src/RageSounds.h | 1 + 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/stepmania/src/RageSounds.cpp b/stepmania/src/RageSounds.cpp index 987d3c38ee..aa8a5b342b 100644 --- a/stepmania/src/RageSounds.cpp +++ b/stepmania/src/RageSounds.cpp @@ -9,6 +9,7 @@ #include "NotesLoaderSM.h" #include "PrefsManager.h" #include "RageDisplay.h" +#include "AnnouncerManager.h" RageSounds *SOUND = NULL; @@ -64,6 +65,7 @@ static RageThread MusicThread; #include "RageUtil_CircularBuffer.h" CircBuf g_SoundsToPlayOnce; CircBuf g_SoundsToPlayOnceFromDir; +CircBuf g_SoundsToPlayOnceFromAnnouncer; struct MusicToPlay { @@ -199,6 +201,27 @@ static void StartMusic( MusicToPlay &ToPlay ) g_Playing = NewMusic; } +static void DoPlayOnceFromDir( CString sPath ) +{ + if( sPath == "" ) + return; + + // make sure there's a slash at the end of this path + if( sPath.Right(1) != "/" ) + sPath += "/"; + + CStringArray arraySoundFiles; + GetDirListing( sPath + "*.mp3", arraySoundFiles ); + GetDirListing( sPath + "*.wav", arraySoundFiles ); + GetDirListing( sPath + "*.ogg", arraySoundFiles ); + + if( arraySoundFiles.empty() ) + return; + + int index = rand() % arraySoundFiles.size(); + SOUNDMAN->PlayOnce( sPath + arraySoundFiles[index] ); +} + static void StartQueuedSounds() { CString *p; @@ -210,26 +233,18 @@ static void StartQueuedSounds() } while( g_SoundsToPlayOnceFromDir.read( &p, 1 ) ) + { + CString sPath( *p ); + DoPlayOnceFromDir( sPath ); + delete p; + } + + while( g_SoundsToPlayOnceFromAnnouncer.read( &p, 1 ) ) { CString sPath( *p ); if( sPath != "" ) - { - // make sure there's a slash at the end of this path - if( sPath.Right(1) != "/" ) - sPath += "/"; - - CStringArray arraySoundFiles; - GetDirListing( sPath + "*.mp3", arraySoundFiles ); - GetDirListing( sPath + "*.wav", arraySoundFiles ); - GetDirListing( sPath + "*.ogg", arraySoundFiles ); - - if( arraySoundFiles.empty() ) - return; - - int index = rand() % arraySoundFiles.size(); - SOUNDMAN->PlayOnce( sPath + arraySoundFiles[index] ); - } - + sPath = ANNOUNCER->GetPathTo( sPath ); + DoPlayOnceFromDir( sPath ); delete p; } @@ -264,6 +279,7 @@ RageSounds::RageSounds() g_SoundsToPlayOnce.reserve( 16 ); g_SoundsToPlayOnceFromDir.reserve( 16 ); + g_SoundsToPlayOnceFromAnnouncer.reserve( 16 ); g_MusicsToPlay.reserve( 16 ); g_Mutex = new RageMutex("RageSounds"); @@ -300,6 +316,9 @@ RageSounds::~RageSounds() while( g_SoundsToPlayOnceFromDir.read( &p, 1 ) ) delete p; + while( g_SoundsToPlayOnceFromAnnouncer.read( &p, 1 ) ) + delete p; + MusicToPlay *pMusic; while( g_MusicsToPlay.read( &pMusic, 1 ) ) delete pMusic; @@ -465,6 +484,17 @@ void RageSounds::PlayOnceFromDir( CString PlayOnceFromDir ) StartQueuedSounds(); } +void RageSounds::PlayOnceFromAnnouncer( CString sFolderName ) +{ + /* Add the path to the g_SoundsToPlayOnceFromDir queue. */ + CString *p = new CString( sFolderName ); + if( !g_SoundsToPlayOnceFromAnnouncer.write( &p, 1 ) ) + delete p; + + if( !g_ThreadedMusicStart ) + StartQueuedSounds(); +} + float RageSounds::GetPlayLatency() const { return SOUNDMAN->GetPlayLatency(); diff --git a/stepmania/src/RageSounds.h b/stepmania/src/RageSounds.h index 2a27d28861..e6d569a695 100644 --- a/stepmania/src/RageSounds.h +++ b/stepmania/src/RageSounds.h @@ -23,6 +23,7 @@ public: void PlayOnce( CString sPath ); void PlayOnceFromDir( CString sDir ); + void PlayOnceFromAnnouncer( CString sFolderName ); float GetPlayLatency() const; void HandleSongTimer( bool on=true );