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
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
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
00057
00058
00059
00060
00061
00062
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
00290
00291
00292
00293
00294
00295
00296 #endif
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312