cleanup
This commit is contained in:
@@ -3,103 +3,106 @@
|
|||||||
|
|
||||||
RageSoundReader_Resample_Fast::RageSoundReader_Resample_Fast()
|
RageSoundReader_Resample_Fast::RageSoundReader_Resample_Fast()
|
||||||
{
|
{
|
||||||
source = NULL;
|
m_pSource = NULL;
|
||||||
samplerate = -1;
|
m_iOutputSampleRate = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSoundReader_Resample_Fast::Open(SoundReader *source_)
|
void RageSoundReader_Resample_Fast::Open( SoundReader *pSource )
|
||||||
{
|
{
|
||||||
source = source_;
|
m_pSource = pSource;
|
||||||
ASSERT(source);
|
ASSERT(m_pSource);
|
||||||
|
|
||||||
samplerate = source->GetSampleRate();
|
m_iOutputSampleRate = m_pSource->GetSampleRate();
|
||||||
resamp.SetInputSampleRate(samplerate);
|
m_Resamp.SetInputSampleRate( m_iOutputSampleRate );
|
||||||
resamp.SetChannels( source->GetNumChannels() );
|
m_Resamp.SetChannels( m_pSource->GetNumChannels() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RageSoundReader_Resample_Fast::~RageSoundReader_Resample_Fast()
|
RageSoundReader_Resample_Fast::~RageSoundReader_Resample_Fast()
|
||||||
{
|
{
|
||||||
delete source;
|
delete m_pSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSoundReader_Resample_Fast::SetSampleRate(int hz)
|
void RageSoundReader_Resample_Fast::SetSampleRate( int hz )
|
||||||
{
|
{
|
||||||
samplerate = hz;
|
m_iOutputSampleRate = hz;
|
||||||
resamp.SetOutputSampleRate(samplerate);
|
m_Resamp.SetOutputSampleRate( m_iOutputSampleRate );
|
||||||
}
|
}
|
||||||
|
|
||||||
int RageSoundReader_Resample_Fast::GetLength() const
|
int RageSoundReader_Resample_Fast::GetLength() const
|
||||||
{
|
{
|
||||||
resamp.reset();
|
m_Resamp.reset();
|
||||||
return source->GetLength();
|
return m_pSource->GetLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
int RageSoundReader_Resample_Fast::GetLength_Fast() const
|
int RageSoundReader_Resample_Fast::GetLength_Fast() const
|
||||||
{
|
{
|
||||||
resamp.reset();
|
m_Resamp.reset();
|
||||||
return source->GetLength_Fast();
|
return m_pSource->GetLength_Fast();
|
||||||
}
|
}
|
||||||
|
|
||||||
int RageSoundReader_Resample_Fast::SetPosition_Accurate(int ms)
|
int RageSoundReader_Resample_Fast::SetPosition_Accurate( int ms )
|
||||||
{
|
{
|
||||||
resamp.reset();
|
m_Resamp.reset();
|
||||||
return source->SetPosition_Accurate(ms);
|
return m_pSource->SetPosition_Accurate(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
int RageSoundReader_Resample_Fast::SetPosition_Fast(int ms)
|
int RageSoundReader_Resample_Fast::SetPosition_Fast( int ms )
|
||||||
{
|
{
|
||||||
resamp.reset();
|
m_Resamp.reset();
|
||||||
return source->SetPosition_Fast(ms);
|
return m_pSource->SetPosition_Fast(ms);
|
||||||
}
|
}
|
||||||
static const int BUFSIZE = 1024*16;
|
static const int BUFSIZE = 1024*16;
|
||||||
|
|
||||||
int RageSoundReader_Resample_Fast::Read(char *buf, unsigned len)
|
int RageSoundReader_Resample_Fast::Read( char *pBuf, unsigned iSize )
|
||||||
{
|
{
|
||||||
int bytes_read = 0;
|
int iBytesRead = 0;
|
||||||
while(len)
|
while( iSize )
|
||||||
{
|
{
|
||||||
int size = resamp.read(buf, len);
|
{
|
||||||
|
int iGot = m_Resamp.read( pBuf, iSize );
|
||||||
|
|
||||||
if(size == -1)
|
if( iGot == -1 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
buf += size;
|
pBuf += iGot;
|
||||||
len -= size;
|
iSize -= iGot;
|
||||||
bytes_read += size;
|
iBytesRead += iGot;
|
||||||
|
|
||||||
|
if( iGot )
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(size == 0)
|
|
||||||
{
|
{
|
||||||
static char buf[BUFSIZE];
|
static char buf[BUFSIZE];
|
||||||
|
int iGot = m_pSource->Read(buf, sizeof(buf));
|
||||||
|
|
||||||
int cnt = source->Read(buf, sizeof(buf));
|
if( iGot == -1 )
|
||||||
|
|
||||||
if(cnt == -1)
|
|
||||||
{
|
{
|
||||||
SetError(source->GetError());
|
SetError( m_pSource->GetError() );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(cnt == 0)
|
if( iGot == 0 )
|
||||||
resamp.eof();
|
m_Resamp.eof();
|
||||||
else
|
else
|
||||||
resamp.write(buf, cnt);
|
m_Resamp.write( buf, iGot );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytes_read;
|
return iBytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundReader *RageSoundReader_Resample_Fast::Copy() const
|
SoundReader *RageSoundReader_Resample_Fast::Copy() const
|
||||||
{
|
{
|
||||||
SoundReader *new_source = source->Copy();
|
SoundReader *pNewSource = m_pSource->Copy();
|
||||||
RageSoundReader_Resample_Fast *ret = new RageSoundReader_Resample_Fast;
|
RageSoundReader_Resample_Fast *pRet = new RageSoundReader_Resample_Fast;
|
||||||
ret->Open(new_source);
|
pRet->Open( pNewSource );
|
||||||
ret->SetSampleRate(samplerate);
|
pRet->SetSampleRate( m_iOutputSampleRate );
|
||||||
return ret;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2003 Glenn Maynard
|
* Copyright (c) 2003-2005 Glenn Maynard
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
|||||||
@@ -10,38 +10,39 @@
|
|||||||
/* This class changes the sampling rate of a sound. */
|
/* This class changes the sampling rate of a sound. */
|
||||||
class RageSoundReader_Resample_Fast: public RageSoundReader_Resample
|
class RageSoundReader_Resample_Fast: public RageSoundReader_Resample
|
||||||
{
|
{
|
||||||
int samplerate;
|
|
||||||
|
|
||||||
bool FillBuf();
|
|
||||||
|
|
||||||
SoundReader *source;
|
|
||||||
|
|
||||||
mutable RageSoundResampler resamp;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* We own source. */
|
/* We own pSource. */
|
||||||
void Open(SoundReader *source);
|
void Open( SoundReader *pSource );
|
||||||
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 *pBuf, unsigned iSize );
|
||||||
RageSoundReader_Resample_Fast();
|
RageSoundReader_Resample_Fast();
|
||||||
virtual ~RageSoundReader_Resample_Fast();
|
virtual ~RageSoundReader_Resample_Fast();
|
||||||
SoundReader *Copy() const;
|
SoundReader *Copy() const;
|
||||||
|
|
||||||
/* Change the actual sample rate of a sound. */
|
/* Change the actual sample rate of a sound. */
|
||||||
void SetSampleRate(int hz);
|
void SetSampleRate( int hz );
|
||||||
|
|
||||||
int GetSampleRate() const { return samplerate; }
|
int GetSampleRate() const { return m_iOutputSampleRate; }
|
||||||
unsigned GetNumChannels() const { return source->GetNumChannels(); }
|
unsigned GetNumChannels() const { return m_pSource->GetNumChannels(); }
|
||||||
bool IsStreamingFromDisk() const { return source->IsStreamingFromDisk(); }
|
bool IsStreamingFromDisk() const { return m_pSource->IsStreamingFromDisk(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool FillBuf();
|
||||||
|
|
||||||
|
int m_iOutputSampleRate;
|
||||||
|
|
||||||
|
SoundReader *m_pSource;
|
||||||
|
|
||||||
|
mutable RageSoundResampler m_Resamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2003 Glenn Maynard
|
* Copyright (c) 2003-2005 Glenn Maynard
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
|||||||
Reference in New Issue
Block a user