From 5d0ce128e4eac9ec71f0b96b452a34b51d143bdc Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 21 Dec 2002 23:14:46 +0000 Subject: [PATCH] fix up stopping --- .../Sound/RageSoundDriver_DSound_Software.cpp | 39 +++++++++---------- .../Sound/RageSoundDriver_DSound_Software.h | 2 +- .../arch/Sound/RageSoundDriver_WaveOut.cpp | 39 +++++++++---------- .../src/arch/Sound/RageSoundDriver_WaveOut.h | 2 +- 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp b/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp index 4ba30c6924..eadfa00acf 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp @@ -78,22 +78,19 @@ bool RageSound_DSound_Software::GetPCM() for(unsigned i = 0; i < sounds.size(); ++i) { if(sounds[i]->stopping) + continue; + + /* Call the callback. */ + unsigned got = sounds[i]->snd->GetPCM((char *) buf, len, play_pos); + + SOUNDMAN->MixAudio( + (Uint8 *) locked_buf, (Uint8 *) buf, got, SDL_MIX_MAXVOLUME/2); + + if(got < len) { - if(sounds[i]->flush_bufs) - sounds[i]->flush_bufs--; - } else { - /* Call the callback. */ - unsigned got = sounds[i]->snd->GetPCM((char *) buf, len, play_pos); - - SOUNDMAN->MixAudio( - (Uint8 *) locked_buf, (Uint8 *) buf, got, SDL_MIX_MAXVOLUME/2); - - if(got < len) - { - /* This sound is finishing. */ - sounds[i]->stopping = true; - sounds[i]->flush_bufs = 2; - } + /* This sound is finishing. */ + sounds[i]->stopping = true; + sounds[i]->flush_pos = str_ds->GetMaxPosition(); } } @@ -122,11 +119,13 @@ void RageSound_DSound_Software::Update(float delta) vector snds = sounds; for(unsigned i = 0; i < snds.size(); ++i) { - if(sounds[i]->stopping && !sounds[i]->flush_bufs) - { - /* This sound is done. */ - snds[i]->snd->SoundStopped(); - } + if(!snds[i]->stopping) continue; + + if(GetPosition(snds[i]->snd) < snds[i]->flush_pos) + continue; /* stopping but still flushing */ + + /* This sound is done. */ + snds[i]->snd->SoundStopped(); } } diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.h b/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.h index 5e4f05f456..f204f53145 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.h @@ -15,7 +15,7 @@ class RageSound_DSound_Software: public RageSoundDriver bool stopping; - int flush_bufs; /* state == STOPPING only */ + int flush_pos; /* state == STOPPING only */ sound() { snd = NULL; stopping=false; } }; diff --git a/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp b/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp index a6173ddda0..fa2793956f 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp @@ -85,22 +85,19 @@ bool RageSound_WaveOut::GetPCM() for(unsigned i = 0; i < sounds.size(); ++i) { if(sounds[i]->stopping) + continue; + + /* Call the callback. */ + unsigned got = sounds[i]->snd->GetPCM((char *) buf, chunksize, last_cursor_pos); + + SOUNDMAN->MixAudio( + (Uint8 *) buffers[b].lpData, (Uint8 *) buf, got, SDL_MIX_MAXVOLUME/2); + + if(got < chunksize) { - if(sounds[i]->flush_bufs) - sounds[i]->flush_bufs--; - } else { - /* Call the callback. */ - unsigned got = sounds[i]->snd->GetPCM((char *) buf, chunksize, last_cursor_pos); - - SOUNDMAN->MixAudio( - (Uint8 *) buffers[b].lpData, (Uint8 *) buf, got, SDL_MIX_MAXVOLUME/2); - - if(got < chunksize) - { - /* This sound is finishing. */ - sounds[i]->stopping = true; - sounds[i]->flush_bufs = num_chunks; - } + /* This sound is finishing. */ + sounds[i]->stopping = true; + sounds[i]->flush_pos = last_cursor_pos + (got / samplesize); } } @@ -133,11 +130,13 @@ void RageSound_WaveOut::Update(float delta) vector snds = sounds; for(unsigned i = 0; i < snds.size(); ++i) { - if(sounds[i]->stopping && !sounds[i]->flush_bufs) - { - /* This sound is done. */ - snds[i]->snd->SoundStopped(); - } + if(!sounds[i]->stopping) continue; + + if(GetPosition(snds[i]->snd) < sounds[i]->flush_pos) + continue; /* stopping but still flushing */ + + /* This sound is done. */ + snds[i]->snd->SoundStopped(); } } diff --git a/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.h b/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.h index fa3b3c383d..5613b1c5f0 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.h @@ -12,7 +12,7 @@ class RageSound_WaveOut: public RageSoundDriver bool stopping; - int flush_bufs; /* state == STOPPING only */ + int flush_pos; /* state == STOPPING only */ sound() { snd = NULL; stopping=false; } };