RageSoundReader::Read(char *) -> int16_t *. This was originally

char * based on the idea of supporting more than one sample type.
I don't plan to do that (though I may change the sample type to float
or int32).
This commit is contained in:
Glenn Maynard
2007-01-20 01:10:24 +00:00
parent 29edd8be6c
commit fd4b5f93bb
29 changed files with 94 additions and 97 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
REGISTER_CLASS_TRAITS( RageSoundReader, pCopy->Copy() );
/* Read(), handling the STREAM_LOOPED and empty return cases. */
int RageSoundReader::RetriedRead( char *pBuffer, int iFrames, int *iSourceFrame, float *fRate )
int RageSoundReader::RetriedRead( int16_t *pBuffer, int iFrames, int *iSourceFrame, float *fRate )
{
if( iFrames == 0 )
return 0;
+2 -2
View File
@@ -9,7 +9,7 @@ public:
virtual int GetLength() const = 0; /* ms */
virtual int GetLength_Fast() const { return GetLength(); } /* ms */
virtual int SetPosition( int iSample ) = 0;
virtual int Read( char *pBuf, int iFrames ) = 0;
virtual int Read( int16_t *pBuf, int iFrames ) = 0;
virtual ~RageSoundReader() { }
virtual RageSoundReader *Copy() const = 0;
virtual int GetSampleRate() const = 0;
@@ -40,7 +40,7 @@ public:
virtual float GetStreamToSourceRatio() const = 0;
virtual RString GetError() const = 0;
int RetriedRead( char *pBuffer, int iFrames, int *iSourceFrame = NULL, float *fRate = NULL );
int RetriedRead( int16_t *pBuffer, int iFrames, int *iSourceFrame = NULL, float *fRate = NULL );
};
#endif
+4 -4
View File
@@ -299,7 +299,7 @@ float RageSoundReader_Chain::GetStreamToSourceRatio() const
/* As we iterate through the sound tree, we'll find that we need data from different
* sounds; a sound may be needed by more than one other sound. */
int RageSoundReader_Chain::Read( char *pBuffer, int iFrames )
int RageSoundReader_Chain::Read( int16_t *pBuffer, int iFrames )
{
while( m_iNextSound < m_aSounds.size() && m_iCurrentFrame == m_aSounds[m_iNextSound].GetOffsetFrame(m_iActualSampleRate) )
{
@@ -327,7 +327,7 @@ int RageSoundReader_Chain::Read( char *pBuffer, int iFrames )
/* We have only one source, and it matches our target. Don't mix; read
* directly from the source into the destination. This is to optimize
* the common case of having one BGM track and no autoplay sounds. */
iFrames = m_apActiveSounds.front()->pSound->Read( (char *) pBuffer, iFrames );
iFrames = m_apActiveSounds.front()->pSound->Read( pBuffer, iFrames );
if( iFrames < 0 )
ReleaseSound( m_apActiveSounds.front() );
if( iFrames > 0 )
@@ -360,7 +360,7 @@ int RageSoundReader_Chain::Read( char *pBuffer, int iFrames )
int iFramesRead = 0;
while( iFramesRead < iFrames )
{
int iGotFrames = pSound->RetriedRead( (char *) Buffer, iFrames - iFramesRead );
int iGotFrames = pSound->RetriedRead( Buffer, iFrames - iFramesRead );
if( iGotFrames < 0 )
{
iFramesRead = iGotFrames;
@@ -380,7 +380,7 @@ int RageSoundReader_Chain::Read( char *pBuffer, int iFrames )
/* Read mixed frames into the output buffer. */
int iMaxFramesRead = mix.size() / m_iChannels;
mix.read( (int16_t *) pBuffer );
mix.read( pBuffer );
m_iCurrentFrame += iMaxFramesRead;
return iMaxFramesRead;
+1 -1
View File
@@ -34,7 +34,7 @@ public:
int GetLength() const;
int GetLength_Fast() const;
int SetPosition( int iFrame );
int Read( char *pBuf, int iFrames );
int Read( int16_t *pBuf, int iFrames );
int GetSampleRate() const { return m_iActualSampleRate; }
unsigned GetNumChannels() const { return m_iChannels; }
bool SetProperty( const RString &sProperty, float fValue );
+19 -20
View File
@@ -77,7 +77,7 @@ public:
/* m_sBuffer[0] corresponds to frame number m_iBufferPositionFrames. */
int m_iBufferPositionFrames;
RString m_sBuffer;
basic_string<int16_t> m_sBuffer;
};
int RageSoundReader_Split::GetLength() const { return m_pImpl->m_pSource->GetLength(); }
@@ -132,23 +132,23 @@ bool RageSoundReader_Split::SetProperty( const RString &sProperty, float fValue
return m_pImpl->m_pSource->SetProperty( sProperty, fValue );
}
int RageSoundReader_Split::Read( char *pBuf, int iFrames )
int RageSoundReader_Split::Read( int16_t *pBuf, int iFrames )
{
m_iRequestFrames = iFrames;
int iRet = m_pImpl->ReadBuffer();
int iBytesAvailable = m_pImpl->m_sBuffer.size();
const char *pSrc = m_pImpl->m_sBuffer.data();
int iSamplesAvailable = m_pImpl->m_sBuffer.size();
const int16_t *pSrc = m_pImpl->m_sBuffer.data();
if( m_pImpl->m_iBufferPositionFrames < m_iPositionFrame )
{
int iSkipFrames = m_iPositionFrame - m_pImpl->m_iBufferPositionFrames;
int iSkipBytes = iSkipFrames * sizeof(int16_t) * m_pImpl->m_pSource->GetNumChannels();
pSrc += iSkipBytes;
iBytesAvailable -= iSkipBytes;
int iSkipSamples = iSkipFrames * m_pImpl->m_pSource->GetNumChannels();
pSrc += iSkipSamples;
iSamplesAvailable -= iSkipSamples;
}
int iFramesWanted = iFrames;
int iFramesAvailable = iBytesAvailable / (sizeof(int16_t) * m_pImpl->m_pSource->GetNumChannels());
int iFramesAvailable = iSamplesAvailable / (m_pImpl->m_pSource->GetNumChannels());
/* Report any errors from Read() if we don't have any data buffered to
* return. If we do have data, finish returning it first. */
@@ -158,16 +158,15 @@ int RageSoundReader_Split::Read( char *pBuf, int iFrames )
iFramesAvailable = min( iFramesAvailable, iFramesWanted );
{
const int16_t *pSrcSamples = (const int16_t *) pSrc;
RageSoundMixBuffer mix;
for( int i = 0; i < (int) m_aChannels.size(); ++i )
{
const ChannelMap &chan = m_aChannels[i];
mix.SetWriteOffset( chan.m_iToChannel );
mix.write( pSrcSamples + chan.m_iFromChannel, iFramesAvailable, m_pImpl->m_pSource->GetNumChannels(), m_iNumOutputChannels );
mix.write( pSrc + chan.m_iFromChannel, iFramesAvailable, m_pImpl->m_pSource->GetNumChannels(), m_iNumOutputChannels );
}
mix.read( (int16_t *) pBuf );
mix.read( pBuf );
}
m_iPositionFrame += iFramesAvailable;
@@ -194,7 +193,7 @@ int RageSoundSplitterImpl::ReadBuffer()
{
int iEraseFrames = iMinFrameRequested - m_iBufferPositionFrames;
iEraseFrames = min( iEraseFrames, (int) m_sBuffer.size() );
m_sBuffer.erase( 0, iEraseFrames * sizeof(int16_t) * m_pSource->GetNumChannels() );
m_sBuffer.erase( 0, iEraseFrames * m_pSource->GetNumChannels() );
m_iBufferPositionFrames += iEraseFrames;
}
@@ -205,24 +204,24 @@ int RageSoundSplitterImpl::ReadBuffer()
m_sBuffer.clear();
}
int iFramesBuffered = m_sBuffer.size() / (sizeof(int16_t) * m_pSource->GetNumChannels() );
int iFramesBuffered = m_sBuffer.size() / m_pSource->GetNumChannels();
int iFramesToRead = iMaxFrameRequested - (m_iBufferPositionFrames + iFramesBuffered);
if( iFramesToRead <= 0 )
return 1; // requested data already buffered
int iBytesToRead = iFramesToRead * sizeof(int16_t) * m_pSource->GetNumChannels();
int iOldSizeBytes = m_sBuffer.size();
m_sBuffer.resize( iOldSizeBytes + iBytesToRead );
int iGotFrames = m_pSource->Read( &m_sBuffer[0] + iOldSizeBytes, iFramesToRead );
int iSamplesToRead = iFramesToRead * m_pSource->GetNumChannels();
int iOldSizeSamples = m_sBuffer.size();
m_sBuffer.resize( iOldSizeSamples + iSamplesToRead );
int iGotFrames = m_pSource->Read( &m_sBuffer[0] + iOldSizeSamples, iFramesToRead );
if( iGotFrames < 0 )
{
m_sBuffer.resize( iOldSizeBytes );
m_sBuffer.resize( iOldSizeSamples );
return iGotFrames;
}
int iGotBytes = iGotFrames * sizeof(int16_t) * m_pSource->GetNumChannels();
m_sBuffer.resize( iOldSizeBytes + iGotBytes );
int iGotSamples = iGotFrames * m_pSource->GetNumChannels();
m_sBuffer.resize( iOldSizeSamples + iGotSamples );
return 1;
}
+1 -1
View File
@@ -17,7 +17,7 @@ public:
virtual int GetLength() const;
virtual int GetLength_Fast() const;
virtual int SetPosition( int iFrame );
virtual int Read( char *pBuf, int iFrames );
virtual int Read( int16_t *pBuf, int iFrames );
virtual int GetSampleRate() const;
virtual unsigned GetNumChannels() const;
virtual bool SetProperty( const RString &sProperty, float fValue );
+3 -3
View File
@@ -48,7 +48,7 @@ int RageSoundReader_Extend::GetEndFrame() const
return m_iStartFrames + m_iLengthFrames;
}
int RageSoundReader_Extend::GetData( char *pBuffer, int iFrames )
int RageSoundReader_Extend::GetData( int16_t *pBuffer, int iFrames )
{
int iFramesToRead = iFrames;
if( m_iLengthFrames != -1 )
@@ -80,7 +80,7 @@ int RageSoundReader_Extend::GetData( char *pBuffer, int iFrames )
return iRet;
}
int RageSoundReader_Extend::Read( char *pBuffer, int iFrames )
int RageSoundReader_Extend::Read( int16_t *pBuffer, int iFrames )
{
int iFramesRead = GetData( pBuffer, iFrames );
if( iFramesRead == RageSoundReader::END_OF_FILE )
@@ -109,7 +109,7 @@ int RageSoundReader_Extend::Read( char *pBuffer, int iFrames )
const int iEndSecond = m_iPositionFrames + iFramesRead;
const float fStartVolume = SCALE( iStartSecond, iStartFadingOutAt, iFinishFadingOutAt, 1.0f, 0.0f );
const float fEndVolume = SCALE( iEndSecond, iStartFadingOutAt, iFinishFadingOutAt, 1.0f, 0.0f );
RageSoundUtil::Fade( (int16_t *) pBuffer, iFramesRead, fStartVolume, fEndVolume );
RageSoundUtil::Fade( pBuffer, iFramesRead, fStartVolume, fEndVolume );
}
m_iPositionFrames += iFramesRead;
+2 -2
View File
@@ -10,7 +10,7 @@ class RageSoundReader_Extend: public RageSoundReader_Filter
public:
RageSoundReader_Extend( RageSoundReader *pSource );
virtual int SetPosition( int iFrame );
virtual int Read( char *pBuffer, int iFrames );
virtual int Read( int16_t *pBuffer, int iFrames );
virtual int GetNextSourceFrame() const;
virtual bool SetProperty( const RString &sProperty, float fValue );
@@ -19,7 +19,7 @@ public:
private:
int GetEndFrame() const;
int GetData( char *pBuffer, int iFrames );
int GetData( int16_t *pBuffer, int iFrames );
int m_iPositionFrames;
+1 -1
View File
@@ -16,7 +16,7 @@ public:
virtual int GetLength() const { return m_pSource->GetLength(); }
virtual int GetLength_Fast() const { return m_pSource->GetLength_Fast(); }
virtual int SetPosition( int iFrame ) { return m_pSource->SetPosition( iFrame ); }
virtual int Read( char *pBuf, int iFrames ) { return m_pSource->Read( pBuf, iFrames ); }
virtual int Read( int16_t *pBuf, int iFrames ) { return m_pSource->Read( pBuf, iFrames ); }
virtual int GetSampleRate() const { return m_pSource->GetSampleRate(); }
virtual unsigned GetNumChannels() const { return m_pSource->GetNumChannels(); }
virtual bool SetProperty( const RString &sProperty, float fValue ) { return m_pSource->SetProperty( sProperty, fValue ); }
+4 -3
View File
@@ -743,7 +743,7 @@ static void mono_to_stereo( char *dst, const char *src, unsigned len )
}
}
int RageSoundReader_MP3::Read( char *buf, int iFrames )
int RageSoundReader_MP3::Read( int16_t *buf, int iFrames )
{
int iFramesWritten = 0;
@@ -752,11 +752,12 @@ int RageSoundReader_MP3::Read( char *buf, int iFrames )
if( mad->outleft > 0 )
{
int iFramesToCopy = min( iFrames, int(mad->outleft / (sizeof(int16_t) * GetNumChannels())) );
const int iBytesToCopy = iFramesToCopy * sizeof(int16_t) * GetNumChannels();
const int iSamplesToCopy = iFramesToCopy * GetNumChannels();
const int iBytesToCopy = iSamplesToCopy * sizeof(int16_t);
memcpy( buf, mad->outbuf + mad->outpos, iBytesToCopy );
buf += iBytesToCopy;
buf += iSamplesToCopy;
iFrames -= iFramesToCopy;
iFramesWritten += iFramesToCopy;
mad->outpos += iBytesToCopy;
+1 -1
View File
@@ -16,7 +16,7 @@ public:
int GetLength() const { return GetLengthConst(false); }
int GetLength_Fast() const { return GetLengthConst(true); }
int SetPosition( int iSample );
int Read( char *pBuf, int iFrames );
int Read( int16_t *pBuf, int iFrames );
unsigned GetNumChannels() const { return Channels; }
int GetSampleRate() const { return SampleRate; }
int GetNextSourceFrame() const;
+3 -4
View File
@@ -9,7 +9,7 @@ RageSoundReader_Pan::RageSoundReader_Pan( RageSoundReader *pSource ):
}
int RageSoundReader_Pan::Read( char *pBuf, int iFrames )
int RageSoundReader_Pan::Read( int16_t *pBuf, int iFrames )
{
iFrames = m_pSource->Read( pBuf, iFrames );
if( iFrames < 0 )
@@ -17,16 +17,15 @@ int RageSoundReader_Pan::Read( char *pBuf, int iFrames )
int iSamples = iFrames * m_pSource->GetNumChannels();
int16_t *pSampleBuf = (int16_t *) pBuf;
if( m_pSource->GetNumChannels() == 1 )
{
RageSoundUtil::ConvertMonoToStereoInPlace( pSampleBuf, iSamples );
RageSoundUtil::ConvertMonoToStereoInPlace( pBuf, iSamples );
iSamples *= 2;
}
/* This block goes from iStreamFrame to iStreamFrame+iGotFrames. */
if( GetNumChannels() == 2 && m_fPan != 0.0 )
RageSoundUtil::Pan( pSampleBuf, iFrames, m_fPan );
RageSoundUtil::Pan( pBuf, iFrames, m_fPan );
return iFrames;
}
+1 -1
View File
@@ -11,7 +11,7 @@ public:
RageSoundReader_Pan( RageSoundReader *pSource );
RageSoundReader_Pan *Copy() const { return new RageSoundReader_Pan(*this); }
virtual unsigned GetNumChannels() const;
virtual int Read( char *pBuf, int iFrames );
virtual int Read( int16_t *pBuf, int iFrames );
virtual bool SetProperty( const RString &sProperty, float fValue );
private:
@@ -40,7 +40,7 @@ RageSoundReader_PitchChange::RageSoundReader_PitchChange( const RageSoundReader_
m_fLastSetPitchRatio = cpy.m_fLastSetPitchRatio;
}
int RageSoundReader_PitchChange::Read( char *pBuf, int iFrames )
int RageSoundReader_PitchChange::Read( int16_t *pBuf, int iFrames )
{
/* m_pSpeedChange->NextReadWillStep is true if speed changes will be applied
* immediately on the next Read(). When this is true, apply the ratio to the
+1 -1
View File
@@ -13,7 +13,7 @@ public:
RageSoundReader_PitchChange( RageSoundReader *pSource );
RageSoundReader_PitchChange( const RageSoundReader_PitchChange &cpy );
virtual int Read( char *pBuf, int iFrames );
virtual int Read( int16_t *pBuf, int iFrames );
virtual bool SetProperty( const RString &sProperty, float fValue );
void SetSpeedRatio( float fRatio ) { m_fSpeedRatio = fRatio; }
@@ -15,14 +15,14 @@ RageSoundReader_PostBuffering::RageSoundReader_PostBuffering( RageSoundReader *p
}
int RageSoundReader_PostBuffering::Read( char *pBuf, int iFrames )
int RageSoundReader_PostBuffering::Read( int16_t *pBuf, int iFrames )
{
iFrames = m_pSource->Read( pBuf, iFrames );
if( iFrames < 0 )
return iFrames;
if( m_fVolume != 1.0f )
RageSoundUtil::Attenuate( (int16_t *) pBuf, iFrames * this->GetNumChannels(), m_fVolume );
RageSoundUtil::Attenuate( pBuf, iFrames * this->GetNumChannels(), m_fVolume );
return iFrames;
}
@@ -10,7 +10,7 @@ class RageSoundReader_PostBuffering: public RageSoundReader_Filter
public:
RageSoundReader_PostBuffering( RageSoundReader *pSource );
RageSoundReader_PostBuffering *Copy() const { return new RageSoundReader_PostBuffering(*this); }
virtual int Read( char *pBuf, int iFrames );
virtual int Read( int16_t *pBuf, int iFrames );
virtual bool SetProperty( const RString &sProperty, float fValue );
private:
+5 -5
View File
@@ -3,6 +3,7 @@
#include "global.h"
#include "RageSoundReader_Preload.h"
#include "RageUtil.h"
#define samplesize (sizeof(int16_t) * m_iChannels) /* 16-bit */
@@ -60,9 +61,8 @@ bool RageSoundReader_Preload::Open( RageSoundReader *pSource )
if( pSource->GetStreamToSourceRatio() != m_fRate )
return false; /* Don't bother trying to preload it. */
char buffer[1024];
int iBytesPerFrame = m_iChannels * sizeof(int16_t);
int iCnt = pSource->Read( buffer, sizeof(buffer) / iBytesPerFrame );
int16_t buffer[1024];
int iCnt = pSource->Read( buffer, ARRAYSIZE(buffer) / m_iChannels );
if( iCnt == END_OF_FILE )
break;
@@ -70,7 +70,7 @@ bool RageSoundReader_Preload::Open( RageSoundReader *pSource )
return false;
/* Add the buffer. */
m_Buffer.Get()->append( buffer, buffer+iCnt*iBytesPerFrame );
m_Buffer.Get()->append( (char *) buffer, (char *) (buffer+iCnt*m_iChannels) );
if( m_Buffer.Get()->size() > max_prebuf_size )
return false; /* too big */
@@ -110,7 +110,7 @@ int RageSoundReader_Preload::GetNextSourceFrame() const
return lrintf(m_iPosition * m_fRate);
}
int RageSoundReader_Preload::Read( char *pBuffer, int iFrames )
int RageSoundReader_Preload::Read( int16_t *pBuffer, int iFrames )
{
const int iSizeFrames = m_Buffer->size() / samplesize;
const int iFramesAvail = iSizeFrames - m_iPosition;
+1 -1
View File
@@ -16,7 +16,7 @@ public:
int GetLength() const;
int GetLength_Fast() const;
int SetPosition( int iFrame );
int Read( char *pBuffer, int iLength );
int Read( int16_t *pBuffer, int iLength );
int GetSampleRate() const { return m_iSampleRate; }
unsigned GetNumChannels() const { return m_iChannels; }
int GetNextSourceFrame() const;
@@ -647,12 +647,10 @@ int RageSoundReader_Resample_Good::SetPosition( int iFrame )
return m_pSource->SetPosition( iFrame );
}
int RageSoundReader_Resample_Good::Read( char *pBuf_, int iFrames )
int RageSoundReader_Resample_Good::Read( int16_t *pBuf, int iFrames )
{
int iChannels = m_apResamplers.size();
int16_t *pBuf = (int16_t *) pBuf_;
int iFramesRead = 0;
/* If the ratio is 1:1, then we're effectively disabled, and we can read
@@ -661,13 +659,13 @@ int RageSoundReader_Resample_Good::Read( char *pBuf_, int iFrames )
GetFactors( iDownFactor, iUpFactor );
if( m_apResamplers[0]->GetFilled() == 0 && iDownFactor == iUpFactor && GetRate() == 1.0f )
return m_pSource->Read( pBuf_, iFrames );
return m_pSource->Read( pBuf, iFrames );
{
int iFramesNeeded = m_apResamplers[0]->NumInputsForOutputSamples(iFrames);
int16_t *pTmpBuf = (int16_t *) alloca( iFramesNeeded * sizeof(int16_t) * iChannels );
ASSERT( pTmpBuf );
int iFramesIn = m_pSource->Read( (char *) pTmpBuf, iFramesNeeded );
int iFramesIn = m_pSource->Read( pTmpBuf, iFramesNeeded );
if( iFramesIn < 0 )
return iFramesIn;
@@ -15,7 +15,7 @@ public:
RageSoundReader_Resample_Good( RageSoundReader *pSource, int iSampleRate );
RageSoundReader_Resample_Good( const RageSoundReader_Resample_Good &cpy );
int SetPosition( int iFrame );
int Read( char *pBuf, int iFrames );
int Read( int16_t *pBuf, int iFrames );
virtual ~RageSoundReader_Resample_Good();
RageSoundReader_Resample_Good *Copy() const;
bool SetProperty( const RString &sProperty, float fValue );
@@ -90,7 +90,7 @@ int RageSoundReader_SpeedChange::FillData( int iMaxFrames )
return m_iDataBufferAvailFrames;
int16_t *pTempBuffer = (int16_t *) alloca( iBytesToRead );
int iGotFrames = m_pSource->Read( (char *) pTempBuffer, iFramesToRead );
int iGotFrames = m_pSource->Read( pTempBuffer, iFramesToRead );
if( iGotFrames < 0 )
{
if( iGotFrames == END_OF_FILE && m_iDataBufferAvailFrames )
@@ -233,17 +233,15 @@ int RageSoundReader_SpeedChange::GetCursorAvail() const
return iCursorAvail;
}
int RageSoundReader_SpeedChange::Read( char *buf, int iFrames )
int RageSoundReader_SpeedChange::Read( int16_t *pBuf, int iFrames )
{
int16_t *pBuf = (int16_t *) buf;
while( 1 )
{
if( m_iDataBufferAvailFrames == 0 && m_fTrailingSpeedRatio == m_fSpeedRatio && m_fSpeedRatio == 1.0f )
{
/* Fast path: the buffer is empty, and we're not scaling the audio. Read directly
* into the output buffer, to eliminate memory and copying overhead. */
return m_pSource->Read( (char *) pBuf, iFrames );
return m_pSource->Read( pBuf, iFrames );
}
int iCursorAvail = GetCursorAvail();
+1 -1
View File
@@ -11,7 +11,7 @@ public:
RageSoundReader_SpeedChange( RageSoundReader *pSource );
virtual int SetPosition( int iFrame );
virtual int Read( char *pBuf, int iFrames );
virtual int Read( int16_t *pBuf, int iFrames );
virtual RageSoundReader_SpeedChange *Copy() const { return new RageSoundReader_SpeedChange(*this); }
virtual bool SetProperty( const RString &sProperty, float fValue );
virtual int GetNextSourceFrame() const;
@@ -139,16 +139,16 @@ int RageSoundReader_ThreadedBuffer::SetPosition( int iFrame )
int RageSoundReader_ThreadedBuffer::GetEmptyFrames() const
{
int iBytesPerFrame = sizeof(int16_t) * this->GetNumChannels();
if( g_iReadBlockSizeFrames * iBytesPerFrame > m_DataBuffer.num_writable() )
int iSamplesPerFrame = this->GetNumChannels();
if( g_iReadBlockSizeFrames * iSamplesPerFrame > m_DataBuffer.num_writable() )
return 0;
return m_DataBuffer.num_writable() / iBytesPerFrame;
return m_DataBuffer.num_writable() / iSamplesPerFrame;
}
int RageSoundReader_ThreadedBuffer::GetFilledFrames() const
{
int iBytesPerFrame = sizeof(int16_t) * this->GetNumChannels();
return m_DataBuffer.num_readable() / iBytesPerFrame;
int iSamplesPerFrame = this->GetNumChannels();
return m_DataBuffer.num_readable() / iSamplesPerFrame;
}
int RageSoundReader_ThreadedBuffer::GetNextSourceFrame() const
@@ -267,8 +267,8 @@ int RageSoundReader_ThreadedBuffer::FillBlock()
if( GetEmptyFrames() == 0 )
return 0;
int iBytesPerFrame = sizeof(int16_t) * this->GetNumChannels();
ASSERT( g_iReadBlockSizeFrames * iBytesPerFrame <= m_DataBuffer.num_writable() );
int iSamplesPerFrame = this->GetNumChannels();
ASSERT( g_iReadBlockSizeFrames * iSamplesPerFrame <= m_DataBuffer.num_writable() );
int iGotFrames;
int iNextSourceFrame = 0;
@@ -279,9 +279,9 @@ int RageSoundReader_ThreadedBuffer::FillBlock()
{
/* We own m_pSource, even after unlocking, because m_bFilling is true. */
unsigned iBufSize;
char *pBuf = m_DataBuffer.get_write_pointer( &iBufSize );
ASSERT( (iBufSize % iBytesPerFrame) == 0 );
iGotFrames = m_pSource->RetriedRead( pBuf, min(g_iReadBlockSizeFrames, iBufSize / iBytesPerFrame), &iNextSourceFrame, &fRate );
int16_t *pBuf = m_DataBuffer.get_write_pointer( &iBufSize );
ASSERT( (iBufSize % iSamplesPerFrame) == 0 );
iGotFrames = m_pSource->RetriedRead( pBuf, min(g_iReadBlockSizeFrames, iBufSize / iSamplesPerFrame), &iNextSourceFrame, &fRate );
}
m_Event.Lock();
@@ -289,7 +289,7 @@ int RageSoundReader_ThreadedBuffer::FillBlock()
if( iGotFrames > 0 )
{
/* Add the data to the buffer. */
m_DataBuffer.advance_write_pointer( iGotFrames * iBytesPerFrame );
m_DataBuffer.advance_write_pointer( iGotFrames * iSamplesPerFrame );
if( iNextSourceFrame != m_StreamPosition.back().iPositionOfFirstFrame + m_StreamPosition.back().iFramesBuffered ||
fRate != m_StreamPosition.back().fRate )
{
@@ -306,7 +306,7 @@ int RageSoundReader_ThreadedBuffer::FillBlock()
return iGotFrames;
}
int RageSoundReader_ThreadedBuffer::Read( char *pBuffer, int iFrames )
int RageSoundReader_ThreadedBuffer::Read( int16_t *pBuffer, int iFrames )
{
if( !m_bEOF )
EnableBuffering();
@@ -333,8 +333,8 @@ int RageSoundReader_ThreadedBuffer::Read( char *pBuffer, int iFrames )
{
Mapping &pos = m_StreamPosition.front();
int iFramesToRead = min( iFrames, pos.iFramesBuffered );
int iBytesPerFrame = sizeof(int16_t) * this->GetNumChannels();
m_DataBuffer.read( pBuffer, iFramesToRead * iBytesPerFrame );
int iSamplesPerFrame = this->GetNumChannels();
m_DataBuffer.read( pBuffer, iFramesToRead * iSamplesPerFrame );
pos.iPositionOfFirstFrame += iFramesToRead;
pos.iFramesBuffered -= iFramesToRead;
iRet = iFramesToRead;
@@ -18,7 +18,7 @@ public:
RageSoundReader_ThreadedBuffer *Copy() const { return new RageSoundReader_ThreadedBuffer(*this); }
virtual int SetPosition( int iFrame );
virtual int Read( char *pBuffer, int iLength );
virtual int Read( int16_t *pBuffer, int iLength );
virtual int GetNextSourceFrame() const;
virtual int GetLength() const;
@@ -46,7 +46,7 @@ private:
int m_iSampleRate;
int m_iChannels;
CircBuf<char> m_DataBuffer;
CircBuf<int16_t> m_DataBuffer;
struct Mapping
{
+4 -4
View File
@@ -160,7 +160,7 @@ int RageSoundReader_Vorbisfile::SetPosition( int iFrame )
return 1;
}
int RageSoundReader_Vorbisfile::Read( char *buf, int iFrames )
int RageSoundReader_Vorbisfile::Read( int16_t *buf, int iFrames )
{
int frames_read = 0;
@@ -201,9 +201,9 @@ int RageSoundReader_Vorbisfile::Read( char *buf, int iFrames )
{
int bstream;
#if defined(INTEGER_VORBIS)
ret = ov_read( vf, buf, iFrames * bytes_per_frame, &bstream );
ret = ov_read( vf, (char *) buf, iFrames * bytes_per_frame, &bstream );
#else // float vorbis decoder
ret = ov_read( vf, buf, iFrames * bytes_per_frame, (BYTE_ORDER == BIG_ENDIAN)?1:0, 2, 1, &bstream );
ret = ov_read( vf, (char *) buf, iFrames * bytes_per_frame, (BYTE_ORDER == BIG_ENDIAN)?1:0, 2, 1, &bstream );
#endif
{
vorbis_info *vi = ov_info( vf, -1 );
@@ -233,7 +233,7 @@ int RageSoundReader_Vorbisfile::Read( char *buf, int iFrames )
int iFramesRead = ret / bytes_per_frame;
read_offset += ret / bytes_per_frame;
buf += ret;
buf += ret / sizeof(int16_t);
frames_read += iFramesRead;
iFrames -= iFramesRead;
}
+1 -1
View File
@@ -16,7 +16,7 @@ public:
int GetLength() const;
int SetPosition( int iFrame );
int Read( char *pBuf, int iFrames );
int Read( int16_t *pBuf, int iFrames );
int GetSampleRate() const;
unsigned GetNumChannels() const { return channels; }
int GetNextSourceFrame() const;
+10 -8
View File
@@ -42,7 +42,7 @@ struct WavReader
WavReader( RageFile &f, const RageSoundReader_WAV::WavData &data ):
m_File(f), m_WavData(data) { }
virtual ~WavReader() { }
virtual int Read( char *pBuf, int iFrames ) = 0;
virtual int Read( int16_t *pBuf, int iFrames ) = 0;
virtual int GetLength() const = 0;
virtual bool Init() = 0;
virtual int SetPosition( int iFrame ) = 0;
@@ -72,7 +72,7 @@ struct WavReaderPCM: public WavReader
return true;
}
int Read( char *buf, int iFrames )
int Read( int16_t *buf, int iFrames )
{
int len = iFrames * m_WavData.m_iChannels * sizeof(int16_t);
if( m_WavData.m_iBitsPerSample == 8 )
@@ -92,7 +92,7 @@ struct WavReaderPCM: public WavReader
iGotSamples = iGot;
break;
case 16:
Convert16BitFromLittleEndian( (int16_t *) buf, iGot/2 );
Convert16BitFromLittleEndian( buf, iGot/2 );
iGotSamples = iGot / 2;
break;
}
@@ -290,9 +290,10 @@ public:
return true;
}
int Read( char *buf, int iFrames )
int Read( int16_t *buf, int iFrames )
{
int iBytesPerFrame = m_WavData.m_iChannels * sizeof(int16_t);
int iSamplesPerFrame = m_WavData.m_iChannels;
int iBytesPerFrame = iSamplesPerFrame * sizeof(int16_t);
int iGotFrames = 0;
while( iGotFrames < (int) iFrames )
{
@@ -311,11 +312,12 @@ public:
int iFramesToCopy = (m_iBufferAvail-m_iBufferUsed) / iBytesPerFrame;
iFramesToCopy = min( iFramesToCopy, (int) (iFrames-iGotFrames) );
int iBytesToCopy = iFramesToCopy * iBytesPerFrame;
int iSamplesToCopy = iFramesToCopy * iSamplesPerFrame;
int iBytesToCopy = iSamplesToCopy * sizeof(int16_t);
memcpy( buf, m_pBuffer+m_iBufferUsed, iBytesToCopy );
m_iBufferUsed += iBytesToCopy;
iGotFrames += iFramesToCopy;
buf += iBytesToCopy;
buf += iSamplesToCopy;
}
return iGotFrames;
@@ -539,7 +541,7 @@ int RageSoundReader_WAV::GetNextSourceFrame() const
return m_pImpl->GetNextSourceFrame();
}
int RageSoundReader_WAV::Read( char *pBuf, int iFrames )
int RageSoundReader_WAV::Read( int16_t *pBuf, int iFrames )
{
ASSERT( m_pImpl != NULL );
return m_pImpl->Read( pBuf, iFrames );
+1 -1
View File
@@ -14,7 +14,7 @@ public:
void Close();
int GetLength() const;
int SetPosition( int iFrame );
int Read( char *pBuf, int iFrames );
int Read( int16_t *pBuf, int iFrames );
int GetSampleRate() const { return m_WavData.m_iSampleRate; }
unsigned GetNumChannels() const { return m_WavData.m_iChannels; }
int GetNextSourceFrame() const;