diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp b/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp index 579584cabc..1361d3ecc3 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp @@ -46,10 +46,10 @@ void RageSound_DSound::MixerThread() while(!shutdown) { CHECKPOINT; - /* Sleep for the size of one chunk. */ + /* Sleep for the size of one chunk, or until we're signalled. */ const int chunksize_frames = buffersize_frames / num_chunks; float sleep_secs = (float(chunksize_frames) / samplerate); - Sleep(int(1000 * sleep_secs)); + WaitForSingleObject( m_ThreadWakeupEvent, int(1000 * sleep_secs) ); CHECKPOINT; LockMutex L(SOUNDMAN->lock); @@ -193,6 +193,7 @@ RageSound_DSound::RageSound_DSound() /* Set channel volumes. */ VolumeChanged(); + m_ThreadWakeupEvent = CreateEvent( NULL, false, false, NULL ); MixingThread.SetName("Mixer thread"); MixingThread.Create( MixerThread_start, this ); } @@ -209,6 +210,8 @@ RageSound_DSound::~RageSound_DSound() for(unsigned i = 0; i < stream_pool.size(); ++i) delete stream_pool[i]; + + CloseHandle( m_ThreadWakeupEvent ); } void RageSound_DSound::VolumeChanged() @@ -254,6 +257,10 @@ void RageSound_DSound::StartMixing(RageSound *snd) if(stream_pool[i]->state == stream_pool[i]->INACTIVE) stream_pool[i]->state = stream_pool[i]->PLAYING; + /* Kick the decoder thread, so it'll start this sound up quickly. */ + L.Unlock(); + SetEvent( m_ThreadWakeupEvent ); + // LOG->Trace("new sound assigned to channel %i", i); } diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound.h b/stepmania/src/arch/Sound/RageSoundDriver_DSound.h index f6d4b433d5..a172dde7c3 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound.h @@ -38,6 +38,7 @@ class RageSound_DSound: public RageSoundDriver DSound ds; + HANDLE m_ThreadWakeupEvent; bool shutdown; /* tells the MixerThread to shut down */ static int MixerThread_start(void *p); void MixerThread();