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

AlsaDspSource.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2004 
00004    LS Informationstechnik (LIKE)
00005    University of Erlangen Nuremberg
00006    All rights reserved.
00007 
00008    Tyrell DarkIce
00009 
00010    File     : AlsaDspSource.h
00011    Version  : $Revision: 1.2 $
00012    Author   : $Author: darkeye $
00013    Location : $Source: /cvsroot/darkice/darkice/src/AlsaDspSource.h,v $
00014    
00015    Copyright notice:
00016 
00017     This program is free software; you can redistribute it and/or
00018     modify it under the terms of the GNU General Public License  
00019     as published by the Free Software Foundation; either version 2
00020     of the License, or (at your option) any later version.
00021    
00022     This program is distributed in the hope that it will be useful,
00023     but WITHOUT ANY WARRANTY; without even the implied warranty of 
00024     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00025     GNU General Public License for more details.
00026    
00027     You should have received a copy of the GNU General Public License
00028     along with this program; if not, write to the Free Software
00029     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00030 
00031 ------------------------------------------------------------------------------*/
00032 #ifndef ALSA_SOURCE_H
00033 #define ALSA_SOURCE_H
00034 
00035 #ifndef __cplusplus
00036 #error This is a C++ include file
00037 #endif
00038 
00039 
00040 /* ============================================================ include files */
00041 
00042 #ifdef HAVE_CONFIG_H
00043 #include "config.h"
00044 #endif
00045 
00046 #include "Reporter.h"
00047 #include "AudioSource.h"
00048 
00049 #ifdef HAVE_ALSA_LIB
00050 #include <alsa/asoundlib.h>
00051 #else
00052 #error configure for ALSA 
00053 #endif
00054 
00055 
00056 /* ================================================================ constants */
00057 
00058 
00059 /* =================================================================== macros */
00060 
00061 
00062 /* =============================================================== data types */
00063 
00070 class AlsaDspSource : public AudioSource, public virtual Reporter
00071 {
00072     private:
00073 
00077         char *pcmName;
00078 
00082         snd_pcm_t *captureHandle;
00083 
00088         int bytesPerFrame;
00089 
00093         bool running;
00094 
00098         unsigned int bufferTime;
00099 
00100 
00101     protected:
00102 
00108         inline
00109         AlsaDspSource ( void )                       throw ( Exception )
00110         {
00111             throw Exception( __FILE__, __LINE__);
00112         }
00113 
00120         void
00121         init (  const char    * name )              throw ( Exception );
00122 
00128         void
00129         strip ( void )                              throw ( Exception );
00130 
00131 
00132     public:
00133 
00144         inline
00145         AlsaDspSource (  const char    * name,
00146                          int             sampleRate    = 44100,
00147                          int             bitsPerSample = 16,
00148                          int             channel       = 2 )
00149                                                         throw ( Exception )
00150                     : AudioSource( sampleRate, bitsPerSample, channel)
00151         {
00152             init( name);
00153         }
00154 
00161         inline
00162         AlsaDspSource (  const AlsaDspSource &    ds )    throw ( Exception )
00163                     : AudioSource( ds )
00164         {
00165             init( ds.pcmName);
00166         }
00167 
00173         inline virtual
00174         ~AlsaDspSource ( void )                          throw ( Exception )
00175         {
00176             strip();
00177         }
00178 
00186         inline virtual AlsaDspSource &
00187         operator= (     const AlsaDspSource &     ds )   throw ( Exception )
00188         {
00189             if ( this != &ds ) {
00190                 strip();
00191                 AudioSource::operator=( ds);
00192                 init( ds.pcmName);
00193             }
00194             return *this;
00195         }
00196 
00202         virtual bool
00203         isBigEndian ( void ) const           throw ();
00204 
00216         virtual bool
00217         open ( void )                                   throw ( Exception );
00218 
00224         inline virtual bool
00225         isOpen ( void ) const                           throw ()
00226         {
00227             return captureHandle != 0;
00228         }
00229 
00241         virtual bool
00242         canRead (               unsigned int    sec,
00243                                 unsigned int    usec )  throw ( Exception );
00244 
00254         virtual unsigned int
00255         read (                  void          * buf,
00256                                 unsigned int    len )   throw ( Exception );
00257 
00263         virtual void
00264         close ( void )                                  throw ( Exception );
00265 
00271         inline virtual unsigned int
00272         getBufferTime( void ) const
00273         { 
00274             return bufferTime;
00275         }
00276 
00282         inline virtual void
00283         setBufferTime( unsigned int time ) {
00284             bufferTime = time;
00285         }
00286 };
00287 
00288 
00289 /* ================================================= external data structures */
00290 
00291 
00292 /* ====================================================== function prototypes */
00293 
00294 
00295 
00296 #endif  /* ALSA_SOURCE_H */
00297 
00298 
00299 /*------------------------------------------------------------------------------
00300  
00301   $Source: /cvsroot/darkice/darkice/src/AlsaDspSource.h,v $
00302 
00303   $Log: AlsaDspSource.h,v $
00304   Revision 1.2  2005/04/14 11:53:17  darkeye
00305   fixed API documentation issues
00306 
00307   Revision 1.1  2004/02/15 12:06:29  darkeye
00308   added ALSA support, thanks to Christian Forster
00309 
00310   
00311 ------------------------------------------------------------------------------*/
00312 

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