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 )
{
uint32_t iFramesWritten = 0;
uint32_t bw = 0;
int iFramesWritten = 0;
unsigned len = iFrames * sizeof(int16_t) * GetNumChannels();
while( bw < len )
while( iFrames > 0 )
{
if( mad->outleft > 0 )
{
/* Ratio of input bytes to output bytes. */
const int Ratio = Channels == 1? 2:1;
int iFramesToCopy = min( iFrames, int(mad->outleft / (sizeof(int16_t) * GetNumChannels())) );
const int iBytesToCopy = iFramesToCopy * sizeof(int16_t) * GetNumChannels();
/* Input bytes to be copied: */
const unsigned cpysize = min( (len - bw)/Ratio, mad->outleft );
memcpy( buf, mad->outbuf + mad->outpos, iBytesToCopy );
if( Channels == 1 )
mono_to_stereo( (char *) buf + bw, (const char *) mad->outbuf + mad->outpos, cpysize );
else
memcpy( buf + bw, mad->outbuf + mad->outpos, cpysize );
bw += cpysize * Ratio;
iFramesWritten += (cpysize * Ratio) / (sizeof(int16_t) * GetNumChannels());
mad->outpos += cpysize;
mad->outleft -= cpysize;
buf += iBytesToCopy;
iFrames -= iFramesToCopy;
iFramesWritten += iFramesToCopy;
mad->outpos += iBytesToCopy;
mad->outleft -= iBytesToCopy;
continue;
}
+1
View File
@@ -18,6 +18,7 @@ public:
int SetPosition_Accurate( int iSample );
int SetPosition_Fast( int iSample );
int Read( char *pBuf, int iFrames );
unsigned GetNumChannels() const { return Channels; }
int GetSampleRate() const { return SampleRate; }
int GetNextSourceFrame() const;