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

TwoLameLibEncoder.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2005 Tyrell Corporation. All rights reserved.
00004 
00005    Tyrell DarkIce
00006 
00007    File     : TwoLameLibEncoder.cpp
00008    Version  : $Revision: 1.1 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/TwoLameLibEncoder.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 TWOLAME_LIB_ENCODER_H
00030 #define TWOLAME_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_TWOLAME_LIB
00044 #include <twolame.h>
00045 #else
00046 #error configure with twolame
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 TwoLameLibEncoder : public AudioEncoder, public virtual Reporter
00073 {
00074     private:
00075 
00079         twolame_options             * twolame_opts;
00080 
00084         Ref<Sink>                       sink;
00085 
00092         void
00093         init ( Sink           * sink )                  throw ( Exception );
00094 
00100         inline void
00101         strip ( void )                                  throw ( Exception )
00102         {
00103         }
00104 
00105 
00106     protected:
00107 
00113         inline
00114         TwoLameLibEncoder ( void )                         throw ( Exception )
00115         {
00116             throw Exception( __FILE__, __LINE__);
00117         }
00118 
00119 
00120     public:
00121 
00138         inline
00139         TwoLameLibEncoder ( Sink          * sink,
00140                             unsigned int    inSampleRate,
00141                             unsigned int    inBitsPerSample,
00142                             unsigned int    inChannel,
00143                             bool            inBigEndian,
00144                             BitrateMode     outBitrateMode,
00145                             unsigned int    outBitrate,
00146                             unsigned int    outSampleRate = 0,
00147                             unsigned int    outChannel    = 0 )
00148                                                         throw ( Exception )
00149             
00150                     : AudioEncoder ( inSampleRate,
00151                                      inBitsPerSample,
00152                                      inChannel,
00153                                      inBigEndian,
00154                                      outBitrateMode,
00155                                      outBitrate,
00156                                      0.0f,  // outQuality
00157                                      outSampleRate,
00158                                      outChannel )
00159         {
00160             init( sink );
00161         }
00162 
00177         inline
00178         TwoLameLibEncoder ( Sink                  * sink,
00179                             const AudioSource     * as,
00180                             BitrateMode             outBitrateMode,
00181                             unsigned int            outBitrate,
00182                             unsigned int            outSampleRate = 0,
00183                             unsigned int            outChannel    = 0 )
00184                                                             throw ( Exception )
00185             
00186                     : AudioEncoder ( as,
00187                                      outBitrateMode,
00188                                      outBitrate,
00189                                      0.0f,  // outQuality
00190                                      outSampleRate,
00191                                      outChannel )
00192         {
00193             init( sink );
00194         }
00195 
00201         inline
00202         TwoLameLibEncoder (  const TwoLameLibEncoder &    encoder )
00203                                                             throw ( Exception )
00204                     : AudioEncoder( encoder )
00205         {
00206             init( encoder.sink.get() );
00207         }
00208          
00209 
00215         inline virtual
00216         ~TwoLameLibEncoder ( void )                            throw ( Exception )
00217         {
00218             if ( isOpen() ) {
00219                 close();
00220             }
00221             strip();
00222         }
00223 
00231         inline virtual TwoLameLibEncoder &
00232         operator= ( const TwoLameLibEncoder &      encoder )   throw ( Exception )
00233         {
00234             if ( this != &encoder ) {
00235                 strip();
00236                 AudioEncoder::operator=( encoder);
00237                 init( encoder.sink.get() );
00238             }
00239 
00240             return *this;
00241         }
00242 
00248         inline const char *
00249         getLameVersion( void )
00250         {
00251             return get_twolame_version();
00252         }
00253 
00259         inline virtual bool
00260         isRunning ( void ) const           throw ()
00261         {
00262             return isOpen();
00263         }
00264 
00272         inline virtual bool
00273         start ( void )                      throw ( Exception )
00274         {
00275             return open();
00276         }
00277 
00283         inline virtual void
00284         stop ( void )                       throw ( Exception )
00285         {
00286             return close();
00287         }
00288 
00295         virtual bool
00296         open ( void )                               throw ( Exception );
00297 
00303         inline virtual bool
00304         isOpen ( void ) const                       throw ()
00305         {
00306             return twolame_opts != 0;
00307         }
00308 
00318         inline virtual bool
00319         canWrite (     unsigned int    sec,
00320                        unsigned int    usec )       throw ( Exception )
00321         {
00322             if ( !isOpen() ) {
00323                 return false;
00324             }
00325 
00326             return true;
00327         }
00328 
00340         virtual unsigned int
00341         write (        const void    * buf,
00342                        unsigned int    len )        throw ( Exception );
00343 
00350         virtual void
00351         flush ( void )                              throw ( Exception );
00352 
00358         virtual void
00359         close ( void )                              throw ( Exception );
00360 };
00361 
00362 
00363 /* ================================================= external data structures */
00364 
00365 
00366 /* ====================================================== function prototypes */
00367 
00368 
00369 #endif  /* TWOLAME_LIB_ENCODER_H */
00370 
00371 
00372 /*------------------------------------------------------------------------------
00373  
00374   $Source: /cvsroot/darkice/darkice/src/TwoLameLibEncoder.h,v $
00375 
00376   $Log: TwoLameLibEncoder.h,v $
00377   Revision 1.1  2006/01/25 22:49:59  darkeye
00378   added mpeg2 support thanks to Nicholas J Humfrey
00379 
00380 
00381   Revision 1.1  2005/05/02 23:05:02  nhumfrey
00382   initial version - based on LameLibEncoder 1.19
00383   
00384 ------------------------------------------------------------------------------*/
00385 

Generated on Fri May 19 15:36:48 2006 for DarkIce by  doxygen 1.4.4