implement GetNumChannels to simplify (if mono, send mono sound,

not stereo)
This commit is contained in:
Glenn Maynard
2006-12-10 04:20:22 +00:00
parent f97d80afdc
commit 3859d3b7bc
2 changed files with 11 additions and 17 deletions
+10 -17
View File
@@ -743,29 +743,22 @@ static void mono_to_stereo( char *dst, const char *src, unsigned len )
int RageSoundReader_MP3::Read( char *buf, int iFrames ) int RageSoundReader_MP3::Read( char *buf, int iFrames )
{ {
uint32_t iFramesWritten = 0; int iFramesWritten = 0;
uint32_t bw = 0;
unsigned len = iFrames * sizeof(int16_t) * GetNumChannels(); while( iFrames > 0 )
while( bw < len )
{ {
if( mad->outleft > 0 ) if( mad->outleft > 0 )
{ {
/* Ratio of input bytes to output bytes. */ int iFramesToCopy = min( iFrames, int(mad->outleft / (sizeof(int16_t) * GetNumChannels())) );
const int Ratio = Channels == 1? 2:1; const int iBytesToCopy = iFramesToCopy * sizeof(int16_t) * GetNumChannels();
/* Input bytes to be copied: */ memcpy( buf, mad->outbuf + mad->outpos, iBytesToCopy );
const unsigned cpysize = min( (len - bw)/Ratio, mad->outleft );
if( Channels == 1 ) buf += iBytesToCopy;
mono_to_stereo( (char *) buf + bw, (const char *) mad->outbuf + mad->outpos, cpysize ); iFrames -= iFramesToCopy;
else iFramesWritten += iFramesToCopy;
memcpy( buf + bw, mad->outbuf + mad->outpos, cpysize ); mad->outpos += iBytesToCopy;
mad->outleft -= iBytesToCopy;
bw += cpysize * Ratio;
iFramesWritten += (cpysize * Ratio) / (sizeof(int16_t) * GetNumChannels());
mad->outpos += cpysize;
mad->outleft -= cpysize;
continue; continue;
} }
+1
View File
@@ -18,6 +18,7 @@ public:
int SetPosition_Accurate( int iSample ); int SetPosition_Accurate( int iSample );
int SetPosition_Fast( int iSample ); int SetPosition_Fast( int iSample );
int Read( char *pBuf, int iFrames ); int Read( char *pBuf, int iFrames );
unsigned GetNumChannels() const { return Channels; }
int GetSampleRate() const { return SampleRate; } int GetSampleRate() const { return SampleRate; }
int GetNextSourceFrame() const; int GetNextSourceFrame() const;