00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef LAME_LIB_ENCODER_H
00030 #define LAME_LIB_ENCODER_H
00031
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035
00036
00037
00038
00039 #ifdef HAVE_CONFIG_H
00040 #include "config.h"
00041 #endif
00042
00043 #ifdef HAVE_LAME_LIB
00044 #include <lame/lame.h>
00045 #else
00046 #error configure with lame
00047 #endif
00048
00049
00050 #include "Ref.h"
00051 #include "Exception.h"
00052 #include "Reporter.h"
00053 #include "AudioEncoder.h"
00054 #include "Sink.h"
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00072 class LameLibEncoder : public AudioEncoder, public virtual Reporter
00073 {
00074 private:
00075
00079 lame_global_flags * lameGlobalFlags;
00080
00084 Ref<Sink> sink;
00085
00090 int lowpass;
00091
00096 int highpass;
00097
00112 inline void
00113 init ( Sink * sink,
00114 int lowpass,
00115 int highpass ) throw ( Exception )
00116 {
00117 this->lameGlobalFlags = NULL;
00118 this->sink = sink;
00119 this->lowpass = lowpass;
00120 this->highpass = highpass;
00121
00122 if ( getInBitsPerSample() != 16 && getInBitsPerSample() != 8 ) {
00123 throw Exception( __FILE__, __LINE__,
00124 "specified bits per sample not supported",
00125 getInBitsPerSample() );
00126 }
00127
00128 if ( getInChannel() != 1 && getInChannel() != 2 ) {
00129 throw Exception( __FILE__, __LINE__,
00130 "unsupported number of input channels for the encoder",
00131 getInChannel() );
00132 }
00133 if ( getOutChannel() != 1 && getOutChannel() != 2 ) {
00134 throw Exception( __FILE__, __LINE__,
00135 "unsupported number of output channels for the encoder",
00136 getOutChannel() );
00137 }
00138 if ( getInChannel() < getOutChannel() ) {
00139 throw Exception( __FILE__, __LINE__,
00140 "output channels greater then input channels",
00141 getOutChannel() );
00142 }
00143 }
00144
00150 inline void
00151 strip ( void ) throw ( Exception )
00152 {
00153 }
00154
00155
00156 protected:
00157
00163 inline
00164 LameLibEncoder ( void ) throw ( Exception )
00165 {
00166 throw Exception( __FILE__, __LINE__);
00167 }
00168
00169
00170 public:
00171
00197 inline
00198 LameLibEncoder ( Sink * sink,
00199 unsigned int inSampleRate,
00200 unsigned int inBitsPerSample,
00201 unsigned int inChannel,
00202 bool inBigEndian,
00203 BitrateMode outBitrateMode,
00204 unsigned int outBitrate,
00205 double outQuality,
00206 unsigned int outSampleRate = 0,
00207 unsigned int outChannel = 0,
00208 int lowpass = 0,
00209 int highpass = 0 )
00210 throw ( Exception )
00211
00212 : AudioEncoder ( inSampleRate,
00213 inBitsPerSample,
00214 inChannel,
00215 inBigEndian,
00216 outBitrateMode,
00217 outBitrate,
00218 outQuality,
00219 outSampleRate,
00220 outChannel )
00221 {
00222 init( sink, lowpass, highpass);
00223 }
00224
00248 inline
00249 LameLibEncoder ( Sink * sink,
00250 const AudioSource * as,
00251 BitrateMode outBitrateMode,
00252 unsigned int outBitrate,
00253 double outQuality,
00254 unsigned int outSampleRate = 0,
00255 unsigned int outChannel = 0,
00256 int lowpass = 0,
00257 int highpass = 0 )
00258 throw ( Exception )
00259
00260 : AudioEncoder ( as,
00261 outBitrateMode,
00262 outBitrate,
00263 outQuality,
00264 outSampleRate,
00265 outChannel )
00266 {
00267 init( sink, lowpass, highpass);
00268 }
00269
00275 inline
00276 LameLibEncoder ( const LameLibEncoder & encoder )
00277 throw ( Exception )
00278 : AudioEncoder( encoder )
00279 {
00280 init( encoder.sink.get(), encoder.lowpass, encoder.highpass );
00281 }
00282
00283
00289 inline virtual
00290 ~LameLibEncoder ( void ) throw ( Exception )
00291 {
00292 if ( isOpen() ) {
00293 close();
00294 }
00295 strip();
00296 }
00297
00305 inline virtual LameLibEncoder &
00306 operator= ( const LameLibEncoder & encoder ) throw ( Exception )
00307 {
00308 if ( this != &encoder ) {
00309 strip();
00310 AudioEncoder::operator=( encoder);
00311 init( encoder.sink.get(), encoder.lowpass, encoder.highpass );
00312 }
00313
00314 return *this;
00315 }
00316
00322 inline const char *
00323 getLameVersion( void )
00324 {
00325 return get_lame_version();
00326 }
00327
00333 inline virtual bool
00334 isRunning ( void ) const throw ()
00335 {
00336 return isOpen();
00337 }
00338
00346 inline virtual bool
00347 start ( void ) throw ( Exception )
00348 {
00349 return open();
00350 }
00351
00357 inline virtual void
00358 stop ( void ) throw ( Exception )
00359 {
00360 return close();
00361 }
00362
00369 virtual bool
00370 open ( void ) throw ( Exception );
00371
00377 inline virtual bool
00378 isOpen ( void ) const throw ()
00379 {
00380 return lameGlobalFlags != 0;
00381 }
00382
00392 inline virtual bool
00393 canWrite ( unsigned int sec,
00394 unsigned int usec ) throw ( Exception )
00395 {
00396 if ( !isOpen() ) {
00397 return false;
00398 }
00399
00400 return true;
00401 }
00402
00414 virtual unsigned int
00415 write ( const void * buf,
00416 unsigned int len ) throw ( Exception );
00417
00424 virtual void
00425 flush ( void ) throw ( Exception );
00426
00432 virtual void
00433 close ( void ) throw ( Exception );
00434 };
00435
00436
00437
00438
00439
00440
00441
00442
00443 #endif
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502