diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index db6f22e014..4fff90b94b 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -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; } diff --git a/stepmania/src/RageSoundReader_Preload.cpp b/stepmania/src/RageSoundReader_Preload.cpp index e5f57c663f..e326e700cb 100644 --- a/stepmania/src/RageSoundReader_Preload.cpp +++ b/stepmania/src/RageSoundReader_Preload.cpp @@ -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; } diff --git a/stepmania/src/RageSoundReader_Preload.h b/stepmania/src/RageSoundReader_Preload.h index a6948857f5..3b0c1d4cb6 100644 --- a/stepmania/src/RageSoundReader_Preload.h +++ b/stepmania/src/RageSoundReader_Preload.h @@ -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() { } };