From 990eb50e4a15a8e2bd0efb8f2a0d3a16a3c84074 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 5 Feb 2004 21:03:03 +0000 Subject: [PATCH] fix ALSA problems when going through plug --- stepmania/src/arch/Sound/ALSA9Helpers.cpp | 6 +++++- stepmania/src/arch/Sound/ALSA9Helpers.h | 2 +- stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp | 5 +---- stepmania/src/arch/Sound/RageSoundDriver_ALSA9_Software.cpp | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/stepmania/src/arch/Sound/ALSA9Helpers.cpp b/stepmania/src/arch/Sound/ALSA9Helpers.cpp index 3ba27f79d6..30c3691c0c 100644 --- a/stepmania/src/arch/Sound/ALSA9Helpers.cpp +++ b/stepmania/src/arch/Sound/ALSA9Helpers.cpp @@ -218,7 +218,9 @@ Alsa9Buf::~Alsa9Buf() } -int Alsa9Buf::GetNumFramesToFill( int writeahead ) +/* Don't fill the buffer any more than than "writeahead". Don't write any + * more than "chunksize" at a time. */ +int Alsa9Buf::GetNumFramesToFill( snd_pcm_sframes_t writeahead, snd_pcm_sframes_t chunksize ) { snd_pcm_sframes_t avail_frames = dsnd_pcm_avail_update(pcm); @@ -253,6 +255,8 @@ int Alsa9Buf::GetNumFramesToFill( int writeahead ) const snd_pcm_sframes_t filled_frames = max( 0l, total_frames - avail_frames ); snd_pcm_sframes_t frames_to_fill = clamp( writeahead - filled_frames, 0l, (snd_pcm_sframes_t)writeahead ); + frames_to_fill = min( frames_to_fill, chunksize ); + frames_to_fill -= frames_to_fill % xfer_align; return frames_to_fill; diff --git a/stepmania/src/arch/Sound/ALSA9Helpers.h b/stepmania/src/arch/Sound/ALSA9Helpers.h index 73f1ea34a6..9ec80b9e95 100644 --- a/stepmania/src/arch/Sound/ALSA9Helpers.h +++ b/stepmania/src/arch/Sound/ALSA9Helpers.h @@ -35,7 +35,7 @@ public: Alsa9Buf( hw hardware, int channels ); ~Alsa9Buf(); - int GetNumFramesToFill( int writeahead ); + int GetNumFramesToFill( snd_pcm_sframes_t writeahead, snd_pcm_sframes_t chunksize ); void Write( const Sint16 *buffer, int frames ); unsigned FindSampleRate( unsigned rate ); diff --git a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp index bd44312267..8f592aee1d 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9.cpp @@ -56,10 +56,7 @@ RageSound_ALSA9::stream::~stream() /* Returns the number of frames processed */ bool RageSound_ALSA9::stream::GetData(bool init) { - int frames_to_fill = pcm->GetNumFramesToFill( max_writeahead ); - if( !init ) - frames_to_fill = min( frames_to_fill, chunksize ); - + int frames_to_fill = pcm->GetNumFramesToFill( max_writeahead, init? max_writeahead:chunksize ); if( frames_to_fill < chunksize ) return false; diff --git a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9_Software.cpp b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9_Software.cpp index 974f55e58c..9dcd687fb4 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_ALSA9_Software.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_ALSA9_Software.cpp @@ -61,7 +61,7 @@ bool RageSound_ALSA9_Software::GetData() { const int chunksize = max_writeahead / num_chunks; - const int frames_to_fill = min( chunksize, pcm->GetNumFramesToFill( max_writeahead ) ); + const int frames_to_fill = pcm->GetNumFramesToFill( max_writeahead, chunksize ); if( frames_to_fill <= 0 ) return false;