From 7340162a0aa3f42891ba9499c84c63298bf2d2d4 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 12 Jan 2003 03:45:49 +0000 Subject: [PATCH] fix sound thread chewing CPU due to very small loops --- stepmania/src/RageSound.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 7b92f3a59f..a69239d914 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -248,12 +248,15 @@ bool RageSound::Load(CString sSoundFilePath, bool cache) void RageSound::SetStartSeconds( float secs ) { + ASSERT(!playing); m_StartSample = int(secs*samplerate); } void RageSound::SetLengthSeconds(float secs) { ASSERT(secs == -1 || secs >= 0); + ASSERT(!playing); + if(secs == -1) m_LengthSamples = -1; else @@ -560,6 +563,19 @@ void RageSound::StartPlaying() ASSERT(!playing); + /* Sanity check: + * It's extremely inefficient to loop very small lengths of data. For example, + * if m_LengthSamples is 1000, then we'll decode a full buffer (which may be + * a second or more), queue up 1000 samples, then seek and redecode the whole + * full buffer of data and start again. This only happens due to bogus SAMPLELENGTH + * values, so throw a warning and set a more reasonable value. */ + if(m_LengthSamples < samplerate*2) + { + LOG->Warn("Looping sound \"%s\" for too small a period (%f seconds)", + GetLoadedFilePath().GetString(), float(m_LengthSamples) / samplerate); + m_LengthSamples = samplerate * 10; /* 10 seconds */ + } + /* Tell the sound manager to start mixing us. */ playing = true; SOUNDMAN->StartMixing(this);