Simplify.

Remove preloading; it's not useful.
This commit is contained in:
Glenn Maynard
2003-04-23 18:33:59 +00:00
parent 30aa2a6822
commit a5e6cd2787
3 changed files with 19 additions and 17 deletions
+7 -11
View File
@@ -174,26 +174,22 @@ bool RageSound::Load(CString sSoundFilePath, int precache)
if(!NewSample->Open(sSoundFilePath.GetString()))
RageException::Throw( "RageSoundManager::RageSoundManager: error opening sound %s: %s",
sSoundFilePath.GetString(), NewSample->GetError().c_str());
Sample = NewSample;
/* Try to precache. */
if(precache)
{
SoundReader_Preload *Preload = new SoundReader_Preload;
if(Preload->Open(NewSample))
{
if(Preload->Open(Sample)) {
Sample = Preload;
delete NewSample;
return true;
} else {
/* Preload failed. It read some data, so we need to rewind the
* reader. */
Sample->SetPosition_Fast(0);
delete Preload;
}
/* Preload failed. It read some data, so we need to rewind the
* reader. */
NewSample->SetPosition_Fast(0);
delete Preload;
}
Sample = NewSample;
return true;
}
+6 -4
View File
@@ -16,6 +16,9 @@ int SoundReader_Preload::total_samples() const
bool SoundReader_Preload::Open(SoundReader *source)
{
ASSERT(source);
// samplerate = source->GetSampleRate();
/* Check the length, and see if we think it'll fit in the buffer. */
int len = source->GetLength_Fast();
if(len != -1)
@@ -23,8 +26,7 @@ bool SoundReader_Preload::Open(SoundReader *source)
float secs = len / 1000.f;
int pcmsize = int(secs * samplerate * samplesize); /* seconds -> bytes */
if(!PREFSMAN->m_bSoundPreloadAll &&
pcmsize > max_prebuf_size)
if(pcmsize > max_prebuf_size)
return false; /* Don't bother trying to preload it. */
buf.get_owned().reserve(pcmsize);
@@ -45,12 +47,12 @@ bool SoundReader_Preload::Open(SoundReader *source)
/* Add the buffer. */
buf.get_owned().append(buffer, buffer+cnt);
if(!PREFSMAN->m_bSoundPreloadAll &&
buf.get_owned().size() > max_prebuf_size)
if(buf.get_owned().size() > max_prebuf_size)
return false; /* too big */
}
position = 0;
delete source;
return true;
}
+6 -2
View File
@@ -29,15 +29,19 @@ class SoundReader_Preload: public SoundReader {
int total_samples() const;
int samplerate;
public:
/* This will throw a nonfatal exception if this sound isn't
* suitable for preloading. */
/* Return true if the sound has been preloaded, in which case source will
* be deleted. Otherwise, return false. */
bool Open(SoundReader *source);
int GetLength() const;
int GetLength_Fast() const;
int SetPosition_Accurate(int ms);
int SetPosition_Fast(int ms);
int Read(char *buf, unsigned len);
int GetSampleRate() const { return samplerate; }
SoundReader *Copy() const;
~SoundReader_Preload() { }
};