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