From 65764e2150e448d47c395cce59e6057c083dc76b Mon Sep 17 00:00:00 2001 From: darkeye Date: Sun, 4 Aug 2002 10:26:06 +0000 Subject: [PATCH] added additional error checking to make sure that outChannel < inChannel --- darkice/trunk/src/LameLibEncoder.cpp | 17 +++++------------ darkice/trunk/src/LameLibEncoder.h | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/darkice/trunk/src/LameLibEncoder.cpp b/darkice/trunk/src/LameLibEncoder.cpp index 71e9e86..510a5ff 100644 --- a/darkice/trunk/src/LameLibEncoder.cpp +++ b/darkice/trunk/src/LameLibEncoder.cpp @@ -269,19 +269,7 @@ LameLibEncoder :: write ( const void * buf, unsigned int bitsPerSample = getInBitsPerSample(); unsigned int inChannels = getInChannel(); - unsigned int outChannels = getOutChannel(); - if ( inChannels != 1 && inChannels != 2 ) { - throw Exception( __FILE__, __LINE__, - "unsupported number of input channels for the encoder", - inChannels ); - } - if ( outChannels != 1 && outChannels != 2 ) { - throw Exception( __FILE__, __LINE__, - "unsupported number of output channels for the encoder", - outChannels ); - } - unsigned int sampleSize = (bitsPerSample / 8) * inChannels; unsigned char * b = (unsigned char*) buf; unsigned int processed = len - (len % sampleSize); @@ -307,6 +295,8 @@ LameLibEncoder :: write ( const void * buf, } // data chunk size estimate according to lame documentation + // NOTE: mp3Size is calculated based on the number of input channels + // which may be bigger than need, as output channels can be less unsigned int mp3Size = (unsigned int) (1.25 * nSamples + 7200); unsigned char * mp3Buf = new unsigned char[mp3Size]; int ret; @@ -394,6 +384,9 @@ LameLibEncoder :: close ( void ) throw ( Exception ) $Source$ $Log$ + Revision 1.16 2002/08/04 10:26:06 darkeye + added additional error checking to make sure that outChannel < inChannel + Revision 1.15 2002/08/03 12:41:18 darkeye added possibility to stream in mono when recording in stereo diff --git a/darkice/trunk/src/LameLibEncoder.h b/darkice/trunk/src/LameLibEncoder.h index 7f3b86d..f7e739e 100644 --- a/darkice/trunk/src/LameLibEncoder.h +++ b/darkice/trunk/src/LameLibEncoder.h @@ -123,6 +123,22 @@ class LameLibEncoder : public AudioEncoder, public virtual Reporter "specified bits per sample not supported", getInBitsPerSample() ); } + + if ( getInChannel() != 1 && getInChannel() != 2 ) { + throw Exception( __FILE__, __LINE__, + "unsupported number of input channels for the encoder", + getInChannel() ); + } + if ( getOutChannel() != 1 && getOutChannel() != 2 ) { + throw Exception( __FILE__, __LINE__, + "unsupported number of output channels for the encoder", + getOutChannel() ); + } + if ( getInChannel() < getOutChannel() ) { + throw Exception( __FILE__, __LINE__, + "output channels greater then input channels", + getOutChannel() ); + } } /** @@ -431,6 +447,9 @@ class LameLibEncoder : public AudioEncoder, public virtual Reporter $Source$ $Log$ + Revision 1.14 2002/08/04 10:26:06 darkeye + added additional error checking to make sure that outChannel < inChannel + Revision 1.13 2002/08/03 12:41:18 darkeye added possibility to stream in mono when recording in stereo