fix sound thread chewing CPU due to very small loops

This commit is contained in:
Glenn Maynard
2003-01-12 03:45:49 +00:00
parent a88c866164
commit 7340162a0a
+16
View File
@@ -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);