Simplify: move vars out of a struct that's no longer used
This commit is contained in:
+30
-32
@@ -66,13 +66,13 @@ RageSound::RageSound()
|
|||||||
LockMut(SOUNDMAN->lock);
|
LockMut(SOUNDMAN->lock);
|
||||||
|
|
||||||
original = this;
|
original = this;
|
||||||
stream.Sample = NULL;
|
Sample = NULL;
|
||||||
position = 0;
|
position = 0;
|
||||||
stopped_position = -1;
|
stopped_position = -1;
|
||||||
playing = false;
|
playing = false;
|
||||||
StopMode = M_STOP;
|
StopMode = M_STOP;
|
||||||
speed_input_samples = speed_output_samples = 1;
|
speed_input_samples = speed_output_samples = 1;
|
||||||
stream.buf.reserve(internal_buffer_size);
|
databuf.reserve(internal_buffer_size);
|
||||||
m_StartSample = 0;
|
m_StartSample = 0;
|
||||||
m_LengthSamples = -1;
|
m_LengthSamples = -1;
|
||||||
AccurateSync = false;
|
AccurateSync = false;
|
||||||
@@ -99,7 +99,7 @@ RageSound::RageSound(const RageSound &cpy)
|
|||||||
ASSERT(SOUNDMAN);
|
ASSERT(SOUNDMAN);
|
||||||
LockMut(SOUNDMAN->lock);
|
LockMut(SOUNDMAN->lock);
|
||||||
|
|
||||||
stream.Sample = NULL;
|
Sample = NULL;
|
||||||
|
|
||||||
original = cpy.original;
|
original = cpy.original;
|
||||||
m_StartSample = cpy.m_StartSample;
|
m_StartSample = cpy.m_StartSample;
|
||||||
@@ -112,8 +112,8 @@ RageSound::RageSound(const RageSound &cpy)
|
|||||||
speed_input_samples = cpy.speed_input_samples;
|
speed_input_samples = cpy.speed_input_samples;
|
||||||
speed_output_samples = cpy.speed_output_samples;
|
speed_output_samples = cpy.speed_output_samples;
|
||||||
|
|
||||||
stream.buf.reserve(internal_buffer_size);
|
databuf.reserve(internal_buffer_size);
|
||||||
stream.Sample = cpy.stream.Sample->Copy();
|
Sample = cpy.Sample->Copy();
|
||||||
|
|
||||||
/* Load() won't work on a copy if m_sFilePath is already set, so
|
/* Load() won't work on a copy if m_sFilePath is already set, so
|
||||||
* copy this down here. */
|
* copy this down here. */
|
||||||
@@ -128,18 +128,18 @@ void RageSound::Unload()
|
|||||||
if(IsPlaying())
|
if(IsPlaying())
|
||||||
StopPlaying();
|
StopPlaying();
|
||||||
|
|
||||||
delete stream.Sample;
|
delete Sample;
|
||||||
stream.Sample = NULL;
|
Sample = NULL;
|
||||||
|
|
||||||
m_sFilePath = "";
|
m_sFilePath = "";
|
||||||
stream.buf.clear();
|
databuf.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is called upon fatal failure. Replace the sound with silence. */
|
/* This is called upon fatal failure. Replace the sound with silence. */
|
||||||
void RageSound::Fail(CString reason)
|
void RageSound::Fail(CString reason)
|
||||||
{
|
{
|
||||||
delete stream.Sample;
|
delete Sample;
|
||||||
stream.Sample = NULL;
|
Sample = NULL;
|
||||||
|
|
||||||
LOG->Warn("sound error %s", reason.c_str());
|
LOG->Warn("sound error %s", reason.c_str());
|
||||||
/* XXX: we can't do this anymore, and it was a hack anyway */
|
/* XXX: we can't do this anymore, and it was a hack anyway */
|
||||||
@@ -175,16 +175,13 @@ bool RageSound::Load(CString sSoundFilePath, int precache)
|
|||||||
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());
|
||||||
|
|
||||||
if(PREFSMAN->m_bSoundPreloadAll)
|
|
||||||
precache = true;
|
|
||||||
|
|
||||||
/* 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(NewSample))
|
||||||
{
|
{
|
||||||
stream.Sample = Preload;
|
Sample = Preload;
|
||||||
delete NewSample;
|
delete NewSample;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -194,7 +191,8 @@ bool RageSound::Load(CString sSoundFilePath, int precache)
|
|||||||
NewSample->SetPosition_Fast(0);
|
NewSample->SetPosition_Fast(0);
|
||||||
delete Preload;
|
delete Preload;
|
||||||
}
|
}
|
||||||
stream.Sample = NewSample;
|
|
||||||
|
Sample = NewSample;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -225,7 +223,7 @@ void RageSound::Update(float delta)
|
|||||||
/* Return the number of bytes available in the input buffer. */
|
/* Return the number of bytes available in the input buffer. */
|
||||||
int RageSound::Bytes_Available() const
|
int RageSound::Bytes_Available() const
|
||||||
{
|
{
|
||||||
return stream.buf.size();
|
return databuf.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -294,13 +292,13 @@ int RageSound::FillBuf(int bytes)
|
|||||||
{
|
{
|
||||||
LockMut(SOUNDMAN->lock);
|
LockMut(SOUNDMAN->lock);
|
||||||
|
|
||||||
ASSERT(stream.Sample);
|
ASSERT(Sample);
|
||||||
|
|
||||||
bool got_something = false;
|
bool got_something = false;
|
||||||
|
|
||||||
while(bytes > 0)
|
while(bytes > 0)
|
||||||
{
|
{
|
||||||
if(read_block_size > stream.buf.capacity() - stream.buf.size())
|
if(read_block_size > databuf.capacity() - databuf.size())
|
||||||
break; /* full */
|
break; /* full */
|
||||||
|
|
||||||
char inbuf[10240];
|
char inbuf[10240];
|
||||||
@@ -321,7 +319,7 @@ int RageSound::FillBuf(int bytes)
|
|||||||
|
|
||||||
ASSERT(read_size < sizeof(inbuf));
|
ASSERT(read_size < sizeof(inbuf));
|
||||||
|
|
||||||
cnt = stream.Sample->Read(inbuf, read_size);
|
cnt = Sample->Read(inbuf, read_size);
|
||||||
if(cnt == 0)
|
if(cnt == 0)
|
||||||
return got_something; /* EOF */
|
return got_something; /* EOF */
|
||||||
|
|
||||||
@@ -330,7 +328,7 @@ int RageSound::FillBuf(int bytes)
|
|||||||
if(cnt == -1)
|
if(cnt == -1)
|
||||||
{
|
{
|
||||||
/* XXX untested */
|
/* XXX untested */
|
||||||
Fail(stream.Sample->GetError());
|
Fail(Sample->GetError());
|
||||||
|
|
||||||
/* Pretend we got data; we actually just switched to a non-streaming
|
/* Pretend we got data; we actually just switched to a non-streaming
|
||||||
* buffer. */
|
* buffer. */
|
||||||
@@ -338,7 +336,7 @@ int RageSound::FillBuf(int bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add the data to the buffer. */
|
/* Add the data to the buffer. */
|
||||||
stream.buf.write((const char *) inbuf, cnt);
|
databuf.write((const char *) inbuf, cnt);
|
||||||
bytes -= cnt;
|
bytes -= cnt;
|
||||||
got_something = true;
|
got_something = true;
|
||||||
}
|
}
|
||||||
@@ -371,10 +369,10 @@ int RageSound::GetData(char *buffer, int size)
|
|||||||
memset(buffer, 0, got);
|
memset(buffer, 0, got);
|
||||||
} else {
|
} else {
|
||||||
/* Feed data out of our streaming buffer. */
|
/* Feed data out of our streaming buffer. */
|
||||||
ASSERT(stream.Sample);
|
ASSERT(Sample);
|
||||||
got = min(int(stream.buf.size()), size);
|
got = min(int(databuf.size()), size);
|
||||||
if(buffer)
|
if(buffer)
|
||||||
stream.buf.read(buffer, got);
|
databuf.read(buffer, got);
|
||||||
}
|
}
|
||||||
|
|
||||||
return got;
|
return got;
|
||||||
@@ -543,13 +541,13 @@ void RageSound::Stop()
|
|||||||
|
|
||||||
float RageSound::GetLengthSeconds()
|
float RageSound::GetLengthSeconds()
|
||||||
{
|
{
|
||||||
ASSERT(stream.Sample);
|
ASSERT(Sample);
|
||||||
int len = stream.Sample->GetLength();
|
int len = Sample->GetLength();
|
||||||
|
|
||||||
if(len < 0)
|
if(len < 0)
|
||||||
{
|
{
|
||||||
LOG->Warn("GetLengthSeconds failed on %s: %s",
|
LOG->Warn("GetLengthSeconds failed on %s: %s",
|
||||||
GetLoadedFilePath().GetString(), stream.Sample->GetError().c_str() );
|
GetLoadedFilePath().GetString(), Sample->GetError().c_str() );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,20 +659,20 @@ bool RageSound::SetPositionSamples( int samples )
|
|||||||
int ms = int(float(samples) * 1000.f / samplerate);
|
int ms = int(float(samples) * 1000.f / samplerate);
|
||||||
ms = max(ms, 0);
|
ms = max(ms, 0);
|
||||||
|
|
||||||
stream.buf.clear();
|
databuf.clear();
|
||||||
|
|
||||||
ASSERT(stream.Sample);
|
ASSERT(Sample);
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
if(AccurateSync)
|
if(AccurateSync)
|
||||||
ret = stream.Sample->SetPosition_Accurate(ms);
|
ret = Sample->SetPosition_Accurate(ms);
|
||||||
else
|
else
|
||||||
ret = stream.Sample->SetPosition_Fast(ms);
|
ret = Sample->SetPosition_Fast(ms);
|
||||||
|
|
||||||
if(ret == -1)
|
if(ret == -1)
|
||||||
{
|
{
|
||||||
/* XXX untested */
|
/* XXX untested */
|
||||||
Fail(stream.Sample->GetError());
|
Fail(Sample->GetError());
|
||||||
return false; /* failed */
|
return false; /* failed */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,11 +88,8 @@ private:
|
|||||||
* this is ourself. */
|
* this is ourself. */
|
||||||
RageSound *original;
|
RageSound *original;
|
||||||
|
|
||||||
/* These are only used when big == true: */
|
SoundReader *Sample;
|
||||||
struct stream_t {
|
CircBuf databuf;
|
||||||
SoundReader *Sample;
|
|
||||||
CircBuf buf;
|
|
||||||
} stream;
|
|
||||||
int FillBuf(int bytes);
|
int FillBuf(int bytes);
|
||||||
|
|
||||||
/* Sound blocks we've sent out recently through GetPCM. We keep track
|
/* Sound blocks we've sent out recently through GetPCM. We keep track
|
||||||
|
|||||||
Reference in New Issue
Block a user