Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

bayonneaudio.h

Go to the documentation of this file.
00001 // Copyright (C) 1999-2001 Open Source Telecom Corporation.
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception to the GNU General Public License, permission is 
00018 // granted for additional uses of the text contained in its release
00019 // of ccaudio.
00020 //
00021 // The exception is that, if you link the ccaudio library with other
00022 // files to produce an executable, this does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public License.
00024 // Your use of that executable is in no way restricted on account of
00025 // linking the ccaudio library code into it.
00026 //
00027 // This exception does not however invalidate any other reasons why
00028 // the executable file might be covered by the GNU General Public License.
00029 // 
00030 // This exception applies only to the code released under the 
00031 // name ccaudio.  If you copy code from other releases into a copy of
00032 // ccaudio, as the General Public License permits, the exception does
00033 // not apply to the code that you add in this way.  To avoid misleading
00034 // anyone as to the status of such modified files, you must delete
00035 // this exception notice from them.
00036 // 
00037 // If you write modifications of your own for ccaudio, it is your choice
00038 // whether to permit this exception to apply to your modifications.
00039 // If you do not wish that, delete this exception notice.  
00040 
00041 #ifndef CCXX_BAYONNEAUDIO_H_
00042 #define CCXX_BAYONNEAUDIO_H_
00043 
00044 #ifndef CCXX_CONFIG_H_
00045 #include <cc++/config.h>
00046 #endif
00047 
00048 #ifndef CCXX_THREAD_H_
00049 #include <cc++/thread.h>
00050 #endif
00051 
00052 #ifdef  CCXX_NAMESPACES
00053 namespace ost {
00054 #endif
00055 
00056 #define AUDIO_SIGNED_LINEAR_RAW 1
00057 #define AUDIO_LINEAR_CONVERSION 1
00058 #define AUDIO_CODEC_MODULES     1
00059 
00060 typedef signed short *Linear;
00061 
00062 typedef struct
00063 {
00064         float v2;
00065         float v3;
00066         float fac;
00067 } goertzel_state_t;
00068 
00069 typedef struct
00070 {
00071         int hit1;
00072         int hit2;
00073         int hit3;
00074         int hit4;
00075         int mhit;
00076 
00077         goertzel_state_t row_out[4];
00078         goertzel_state_t col_out[4];
00079         goertzel_state_t row_out2nd[4];
00080         goertzel_state_t col_out2nd[4];
00081         goertzel_state_t fax_tone;
00082         goertzel_state_t fax_tone2nd;
00083         float energy;
00084 
00085         int current_sample;
00086         char digits[129];
00087         int current_digits;
00088         int detected_digits;
00089         int lost_digits;
00090         int digit_hits[16];
00091         int fax_hits;
00092 } dtmf_detect_state_t;
00093 
00094 typedef struct
00095 {
00096         float fac;
00097 } tone_detection_descriptor_t;
00098 
00099 class __EXPORT AudioCodec;
00100 
00109 class __EXPORT Audio
00110 {
00111 public:
00112         enum    Rate
00113         {
00114                 rateUnknown,
00115                 rate6khz = 6000,
00116                 rate8khz = 8000,
00117                 rate44khz = 44100
00118         };
00119 
00120         typedef enum Rate Rate;
00121 
00122         enum    Mode
00123         {
00124                 modeRead,
00125                 modeWrite,
00126                 modeCache,
00127                 modeInfo
00128         };
00129 
00130         typedef enum Mode Mode;
00131 
00132         enum    Encoding
00133         {
00134                 unknownEncoding = 0,
00135                 g721ADPCM,
00136                 g722Audio,
00137                 g722_7bit,
00138                 g722_6bit,
00139                 g723_3bit,
00140                 g723_5bit,
00141                 gsmVoice,
00142                 msgsmVoice,
00143                 mulawAudio,
00144                 alawAudio,
00145                 mp1Audio,
00146                 mp2Audio,
00147                 mp3Audio,
00148                 okiADPCM,
00149                 voxADPCM,
00150                 sx73Voice,
00151                 sx96Voice,
00152 
00153                 // Please keep the PCM types at the end of the list -
00154                 // see the "is this PCM or not?" code in
00155                 // AudioFile::close for why.
00156                 cdaStereo,
00157                 cdaMono,
00158                 pcm8Stereo,
00159                 pcm8Mono,
00160                 pcm16Stereo,
00161                 pcm16Mono,
00162                 pcm32Stereo,
00163                 pcm32Mono
00164         };
00165         typedef enum Encoding Encoding;
00166 
00167         enum Format
00168         {
00169                 raw,
00170                 snd,
00171                 riff,
00172                 mpeg,
00173                 wave
00174         };
00175         typedef enum Format Format;
00176 
00177         enum Error
00178         {
00179                 errSuccess = 0,
00180                 errReadLast,
00181                 errNotOpened,
00182                 errEndOfFile,
00183                 errStartOfFile,
00184                 errRateInvalid,
00185                 errEncodingInvalid,
00186                 errReadInterrupt,
00187                 errWriteInterrupt,
00188                 errReadFailure,
00189                 errWriteFailure,
00190                 errReadIncomplete,
00191                 errWriteIncomplete,
00192                 errRequestInvalid,
00193                 errTOCFailed,
00194                 errStatFailed,
00195                 errInvalidTrack,
00196                 errPlaybackFailed,
00197                 errNotPlaying,
00198                 errNoCodec
00199         };
00200         typedef enum Error Error;
00201 
00202         class __EXPORT Info
00203         {
00204         public:
00205                 Format format;
00206                 Encoding encoding;
00207                 unsigned long rate;
00208                 unsigned long bitrate;
00209                 unsigned order;
00210                 unsigned framesize, framecount;
00211                 timeout_t framing;
00212                 char *annotation;
00213 
00214                 Info();
00215                 void set(void);
00216                 void setFraming(timeout_t frame);
00217         };
00218 
00219         static bool isLinear(Encoding encoding);
00220         static bool isMono(Encoding encoding);
00221         static bool isStereo(Encoding encoding);
00222         static Rate getRate(Encoding encoding);
00223         static timeout_t getFraming(Encoding encoding);
00224         static bool isEndian(Encoding encoding);
00225         static bool isEndian(Info &info);
00226         static bool swapEndian(Encoding encoding, void *buffer, unsigned samples);
00227         static bool swapEndian(Info &info, void *buffer, unsigned samples);
00228         static short getImpulse(Encoding encoding, void *buffer, unsigned samples);
00229         static short getImpulse(Info &info, void *buffer, unsigned samples = 0);
00230         static short getPeak(Encoding encoding, void *buffer, unsigned samples);
00231         static short getPeak(Info &info, void *buffer, unsigned samples = 0);
00232 
00233 
00256         static int getFrame(Encoding encoding, int samples = 0);
00257 
00270         static int getCount(Encoding encoding);
00271         static unsigned long toSamples(Encoding encoding, size_t bytes);
00272         static unsigned long toSamples(Info &info, size_t bytes);
00273         static size_t toBytes(Info &info, unsigned long samples);
00274         static size_t toBytes(Encoding encoding, unsigned long samples);
00275         static void fill(unsigned char *addr, int samples, Encoding encoding);
00276 };
00277 
00286 class __EXPORT AudioFile: public Audio
00287 {
00288 protected:
00289         char *pathname;
00290         Error error;
00291         Info info;
00292         unsigned long header;           // offset to start of audio
00293         unsigned long minimum;          // minimum sample size required
00294         unsigned long length;           // current size of file, including header
00295 
00296         void initialize(void);
00297         void getWaveFormat(int size);
00298 
00299         union
00300         {
00301                 int fd;
00302                 void *handle;
00303         } file;
00304 
00305         Mode mode;
00306         unsigned long iolimit;
00307 
00308         virtual bool afCreate(const char *path, bool exclusive = false);
00309         virtual bool afOpen(const char *path, Mode m = modeWrite);
00310         virtual bool afPeek(unsigned char *data, unsigned size);
00311 
00312         AudioCodec *getCodec(void);
00313 
00326         virtual int afRead(unsigned char *data, unsigned size);
00327 
00339         virtual int afWrite(unsigned char *data, unsigned size);
00340 
00350         virtual bool afSeek(unsigned long pos);
00351         virtual void afClose(void);
00352 
00353         virtual char *getContinuation(void)
00354                 {return NULL;};
00355 
00364         const char * getErrorStr(Error err);
00365         Error setError(Error err);
00366 
00367         unsigned long getHeader(void)
00368                 {return header;};
00369 
00370         unsigned short getShort(unsigned char *data);
00371         void setShort(unsigned char *data, unsigned short value);
00372         unsigned long getLong(unsigned char *data);
00373         void setLong(unsigned char *data, unsigned long value);
00374 
00375 public:
00376         AudioFile(const char *fname, unsigned long samples = 0);
00377         AudioFile(const char *fname, Info *info, unsigned long min = 0);
00378 
00379         AudioFile()
00380                 {initialize();};
00381 
00382         virtual ~AudioFile()
00383                 {clear();};
00384 
00393         void open(const char *fname, Mode m = modeWrite, timeout_t framing = 0);
00394 
00404         void create(const char *fname, Info *info, bool exclusive = false, timeout_t framing = 0);
00405 
00417 
00426 
00439 
00449 
00463 
00473 
00489 
00505 
00521 
00534 
00562 
00577 
00608 
00619 
00628 
00638 
00647 
00659 
00669 
00679 
00686 
00695 

Generated on Tue Sep 13 02:19:08 2005 for Bayonne by  doxygen 1.4.4