Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

LameLibEncoder.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2000 Tyrell Corporation. All rights reserved.
00004 
00005    Tyrell DarkIce
00006 
00007    File     : LameLibEncoder.h
00008    Version  : $Revision: 1.16 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/LameLibEncoder.h,v $
00011    
00012    Copyright notice:
00013 
00014     This program is free software; you can redistribute it and/or
00015     modify it under the terms of the GNU General Public License  
00016     as published by the Free Software Foundation; either version 2
00017     of the License, or (at your option) any later version.
00018    
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of 
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00022     GNU General Public License for more details.
00023    
00024     You should have received a copy of the GNU General Public License
00025     along with this program; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 /* ============================================================ include files */
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 /* ================================================================ constants */
00058 
00059 
00060 /* =================================================================== macros */
00061 
00062 
00063 /* =============================================================== data types */
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 /* ================================================= external data structures */
00438 
00439 
00440 /* ====================================================== function prototypes */
00441 
00442 
00443 #endif  /* LAME_LIB_ENCODER_H */
00444 
00445 
00446 /*------------------------------------------------------------------------------
00447  
00448   $Source: /cvsroot/darkice/darkice/src/LameLibEncoder.h,v $
00449 
00450   $Log: LameLibEncoder.h,v $
00451   Revision 1.16  2005/04/16 21:57:34  darkeye
00452   added AAC support through the faac codec, http://www.audiocoding.com/
00453 
00454   Revision 1.15  2004/01/07 13:18:17  darkeye
00455   commited patch sent by John Hay, fixing FreeBSD problems
00456 
00457   Revision 1.14  2002/08/04 10:26:06  darkeye
00458   added additional error checking to make sure that outChannel < inChannel
00459 
00460   Revision 1.13  2002/08/03 12:41:18  darkeye
00461   added possibility to stream in mono when recording in stereo
00462 
00463   Revision 1.12  2002/04/13 11:26:00  darkeye
00464   added cbr, abr and vbr setting feature with encoding quality
00465 
00466   Revision 1.11  2002/03/28 16:38:37  darkeye
00467   moved functions conv8() and conv16() to class Util
00468 
00469   Revision 1.10  2001/10/20 10:56:45  darkeye
00470   added possibility to disable highpass and lowpass filters for lame
00471 
00472   Revision 1.9  2001/10/19 12:39:42  darkeye
00473   created configure options to compile with or without lame / Ogg Vorbis
00474 
00475   Revision 1.8  2001/10/19 09:03:39  darkeye
00476   added support for resampling mp3 streams
00477 
00478   Revision 1.7  2001/09/15 11:35:08  darkeye
00479   minor fixes
00480 
00481   Revision 1.6  2001/09/14 19:31:06  darkeye
00482   added IceCast2 / vorbis support
00483 
00484   Revision 1.5  2001/09/02 09:54:12  darkeye
00485   fixed typos in CVS substition keywords
00486 
00487   Revision 1.4  2001/08/31 20:09:05  darkeye
00488   added funcitons conv8() and conv16()
00489 
00490   Revision 1.3  2001/08/30 17:25:56  darkeye
00491   renamed configure.h to config.h
00492 
00493   Revision 1.2  2001/08/29 21:06:16  darkeye
00494   added real support for 8 / 16 bit mono / stereo input
00495   (8 bit input still has to be spread on 16 bit words)
00496 
00497   Revision 1.1  2001/08/26 20:44:30  darkeye
00498   removed external command-line encoder support
00499   replaced it with a shared-object support for lame with the possibility
00500   of static linkage
00501 
00502 
00503   
00504 ------------------------------------------------------------------------------*/
00505 

Generated on Sat Oct 22 13:17:04 2005 for DarkIce by  doxygen 1.4.4