From dfe8acc3a87d6c6c59cf09931b13300a44e249db Mon Sep 17 00:00:00 2001 From: Aaron VonderHaar Date: Tue, 15 Apr 2003 05:56:39 +0000 Subject: [PATCH] Finally working! Not the most optimized or robust, but at least now playable under linux. --- .../src/arch/Sound/RageSoundDriver_ALSA9.cpp | 33 ++++++++++++++++--- .../src/arch/Sound/RageSoundDriver_ALSA9.h | 2 +- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp index c32e03fdf3..02ce9cdfd0 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp @@ -56,13 +56,37 @@ void RageSound_ALSA9::MixerThread() * assigns it; we might get here before that happens, though. */ while(!SOUNDMAN && !shutdown) SDL_Delay(10); + RageTimer Speaker; + + float delay_ms, passed_ms; + unsigned int frames_read; + while(!shutdown) { - GetData(); - //SDL_Delay(10); + frames_read = GetData(); + delay_ms = 1000 * float(frames_read) / samplerate; + + passed_ms = Speaker.GetDeltaTime(); + + //LOG->Trace("@@@@@ DELAY %f - %f = %f ms", delay_ms, passed_ms, delay_ms - passed_ms); + + if (delay_ms > passed_ms) + /* If we sleep for the full delay, we will just + * miss the deadline, the ALSA pipe will underrun, + * we will have to recover, lots of bad things to + * make the sound start skipping. + * Instead, just sleep for half the time + * so we wake up with time to spare + */ + SDL_Delay(int(delay_ms-passed_ms) / 2); + else + LOG->Trace("RageSound_ALSA9: Missed deadline by %f ms", (delay_ms - passed_ms) ); + } } -bool RageSound_ALSA9::GetData() +/* Returns the number of frames processed + */ +unsigned int RageSound_ALSA9::GetData() { LockMutex L(SOUNDMAN->lock); @@ -127,8 +151,9 @@ bool RageSound_ALSA9::GetData() } last_cursor_pos = new_cursor; + //last_cursor_pos += buffersize_frames; - return true; + return buffersize_frames; } /** diff --git a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.h b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.h index 98e47df0b3..0cf97ed62c 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.h @@ -46,7 +46,7 @@ public: void MixerThread(); SDL_Thread *MixerThreadPtr; - bool GetData(); + unsigned int GetData(); void Recover(int r); /* virtuals: */