ccAudio
audio2.h
Go to the documentation of this file.
00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
00002 // Copyright (C) 2006-2008 David Sugar, Tycho Softworks.
00003 //
00004 // This file is part of GNU ccAudio2.
00005 //
00006 // GNU ccAudio2 is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU Lesser General Public License as published 
00008 // by the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // GNU ccAudio2 is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public License
00017 // along with GNU ccAudio2.  If not, see <http://www.gnu.org/licenses/>.
00018 
00025 #ifndef CCXX_AUDIO_H_
00026 #define CCXX_AUDIO_H_
00027 
00028 #ifndef CCXX_PACKING
00029 #if defined(__GNUC__)
00030 #define CCXX_PACKED
00031 #elif !defined(__hpux) && !defined(_AIX)
00032 #define CCXX_PACKED
00033 #endif
00034 #endif
00035 
00036 #ifndef W32
00037 #if defined(_WIN32) && defined(_MSC_VER)
00038 #pragma warning(disable: 4996)
00039 #define W32
00040 #endif
00041 #if defined(__BORLANDC__) && defined(__Windows)
00042 #define W32
00043 #endif
00044 #endif
00045 
00046 #if !defined(__EXPORT) && defined(W32)
00047 #define __EXPORT __declspec(dllimport)
00048 #endif
00049 
00050 #ifndef __EXPORT
00051 #define __EXPORT
00052 #endif
00053 
00054 #ifdef  W32
00055 #include <windows.h>
00056 #ifndef ssize_t
00057 #define ssize_t int
00058 #endif
00059 #else
00060 #include <cstddef>
00061 #include <cstdlib>
00062 #include <sys/types.h>
00063 #include <netinet/in.h>
00064 #endif
00065 
00066 #include <ctime>
00067 
00068 namespace ost {
00069 
00070 #define AUDIO_SIGNED_LINEAR_RAW 1
00071 #define AUDIO_LINEAR_CONVERSION 1
00072 #define AUDIO_CODEC_MODULES     1
00073 #define AUDIO_LINEAR_FRAMING    1
00074 #define AUDIO_NATIVE_METHODS    1
00075 #define AUDIO_RATE_RESAMPLER    1
00076 
00077 class __EXPORT AudioCodec;
00078 class __EXPORT AudioDevice;
00079 
00088 class __EXPORT Audio
00089 {
00090 public:
00091 #ifdef  W32
00092         typedef short   Sample;
00093         typedef short   *Linear;
00094         typedef short   Level;
00095         typedef DWORD   timeout_t;
00096         typedef WORD    snd16_t;
00097         typedef DWORD   snd32_t;
00098 #else
00099         typedef int16_t snd16_t;
00100         typedef int32_t snd32_t;
00101         typedef int16_t Level;
00102         typedef int16_t Sample;
00103         typedef int16_t *Linear;
00104         typedef unsigned long   timeout_t;
00105 #endif
00106 
00107         static const unsigned ndata;
00108 
00109         typedef struct {
00110         float v2;
00111                 float v3;
00112                 float fac;
00113         } goertzel_state_t;
00114 
00115         typedef struct {
00116                 int hit1;
00117                 int hit2;
00118                 int hit3;
00119                 int hit4;
00120                 int mhit;
00121 
00122                 goertzel_state_t row_out[4];
00123                 goertzel_state_t col_out[4];
00124                 goertzel_state_t row_out2nd[4];
00125                 goertzel_state_t col_out2nd[4];
00126                 goertzel_state_t fax_tone;
00127                 goertzel_state_t fax_tone2nd;
00128                 float energy;
00129 
00130                 int current_sample;
00131                 char digits[129];
00132                 int current_digits;
00133                 int detected_digits;
00134                 int lost_digits;
00135                 int digit_hits[16];
00136                 int fax_hits;
00137         } dtmf_detect_state_t;
00138 
00139         typedef struct {
00140                 float fac;
00141         } tone_detection_descriptor_t;
00142 
00143         typedef unsigned char *Encoded;
00144 
00148         enum    Rate {
00149                 rateUnknown,
00150                 rate6khz = 6000,
00151                 rate8khz = 8000,
00152                 rate16khz = 16000,
00153                 rate32khz = 32000,
00154                 rate44khz = 44100
00155         };
00156 
00157         typedef enum Rate Rate;
00158 
00162         enum    Mode {
00163                 modeRead,
00164                 modeReadAny,
00165                 modeReadOne,
00166                 modeWrite,
00167                 modeCache,
00168                 modeInfo,
00169                 modeFeed,
00170 
00171                 modeAppend,     // app specific placeholders...
00172                 modeCreate
00173         };
00174 
00175         typedef enum Mode Mode;
00176 
00180         enum    Encoding {
00181                 unknownEncoding = 0,
00182                 g721ADPCM,
00183                 g722Audio,
00184                 g722_7bit,
00185                 g722_6bit,
00186                 g723_2bit,
00187                 g723_3bit,
00188                 g723_5bit,
00189                 gsmVoice,
00190                 msgsmVoice,
00191                 mulawAudio,
00192                 alawAudio,
00193                 mp1Audio,
00194                 mp2Audio,
00195                 mp3Audio,
00196                 okiADPCM,
00197                 voxADPCM,
00198                 sx73Voice,
00199                 sx96Voice,
00200 
00201                 // Please keep the PCM types at the end of the list -
00202                 // see the "is this PCM or not?" code in
00203                 // AudioFile::close for why.
00204                 cdaStereo,
00205                 cdaMono,
00206                 pcm8Stereo,
00207                 pcm8Mono,
00208                 pcm16Stereo,
00209                 pcm16Mono,
00210                 pcm32Stereo,
00211                 pcm32Mono,
00212 
00213                 // speex codecs
00214                 speexVoice,     // narrow band
00215                 speexAudio,
00216 
00217                 g729Audio,
00218                 ilbcAudio,
00219                 speexUltra,
00220 
00221                 speexNarrow = speexVoice,
00222                 speexWide = speexAudio,
00223                 g723_4bit = g721ADPCM
00224         };
00225         typedef enum Encoding Encoding;
00226 
00230         enum Format {
00231                 raw,
00232                 snd,
00233                 riff,
00234                 mpeg,
00235                 wave
00236         };
00237         typedef enum Format Format;
00238 
00242         enum DeviceMode {
00243                 PLAY,
00244                 RECORD,
00245                 PLAYREC
00246         };
00247         typedef enum DeviceMode DeviceMode;
00248 
00252         enum Error {
00253                 errSuccess = 0,
00254                 errReadLast,
00255                 errNotOpened,
00256                 errEndOfFile,
00257                 errStartOfFile,
00258                 errRateInvalid,
00259                 errEncodingInvalid,
00260                 errReadInterrupt,
00261                 errWriteInterrupt,
00262                 errReadFailure,
00263                 errWriteFailure,
00264                 errReadIncomplete,
00265                 errWriteIncomplete,
00266                 errRequestInvalid,
00267                 errTOCFailed,
00268                 errStatFailed,
00269                 errInvalidTrack,
00270                 errPlaybackFailed,
00271                 errNotPlaying,
00272                 errNoCodec
00273         };
00274         typedef enum Error Error;
00275 
00276 
00277 #ifdef  CCXX_PACKED
00278 #pragma pack(1)
00279 #endif
00280 
00281         typedef struct {
00282 #if     __BYTE_ORDER == __LITTLE_ENDIAN
00283                 unsigned char mp_sync1 : 8;
00284                 unsigned char mp_crc   : 1;
00285                 unsigned char mp_layer : 2;
00286                 unsigned char mp_ver   : 2;
00287                 unsigned char mp_sync2 : 3;
00288 
00289                 unsigned char mp_priv  : 1;
00290                 unsigned char mp_pad   : 1;
00291                 unsigned char mp_srate : 2;
00292                 unsigned char mp_brate : 4;
00293 
00294                 unsigned char mp_emp   : 2;
00295                 unsigned char mp_original : 1;
00296                 unsigned char mp_copyright: 1;
00297                 unsigned char mp_extend   : 2;
00298                 unsigned char mp_channels : 2;
00299 
00300 #else
00301                 unsigned char mp_sync1 : 8;
00302 
00303                 unsigned char mp_sync2 : 3;
00304                 unsigned char mp_ver   : 2;
00305                 unsigned char mp_layer : 2;
00306                 unsigned char mp_crc   : 1;
00307 
00308                 unsigned char mp_brate : 4;
00309                 unsigned char mp_srate : 2;
00310                 unsigned char mp_pad   : 1;
00311                 unsigned char mp_priv  : 1;
00312 
00313                 unsigned char mp_channels : 2;
00314                 unsigned char mp_extend   : 2;
00315                 unsigned char mp_copyright : 1;
00316                 unsigned char mp_original : 1;
00317                 unsigned char mp_emp : 2;
00318 #endif
00319         }       mpeg_audio;
00320 
00321         typedef struct {
00322                 char tag_id[3];
00323                 char tag_title[30];
00324                 char tag_artist[30];
00325                 char tag_album[30];
00326                 char tag_year[4];
00327                 char tag_note[30];
00328                 unsigned char genre;
00329         }       mpeg_tagv1;
00330 
00331 #ifdef  CCXX_PACKED
00332 #pragma pack()
00333 #endif
00334 
00338         class __EXPORT Info
00339         {
00340         public:
00341                 Format format;
00342                 Encoding encoding;
00343                 unsigned long rate;
00344                 unsigned long bitrate;
00345                 unsigned order;
00346                 unsigned framesize, framecount, headersize, padding;
00347                 timeout_t framing;
00348                 char *annotation;
00349 
00350                 Info();
00351                 void clear(void);
00352                 void set(void);
00353                 void setFraming(timeout_t frame);
00354                 void setRate(Rate rate);
00355         };
00356 
00363         static Level tolevel(float dbm);
00364 
00371         static float todbm(Level power);
00372 
00380         static bool hasDevice(unsigned device = 0);
00381 
00392         static AudioDevice *getDevice(unsigned device = 0, DeviceMode mode = PLAY);
00393 
00399         static const char *getCodecPath(void);
00400 
00408         static const char *getMIME(Info &info);
00409 
00417         static const char *getName(Encoding encoding);
00418 
00426         static const char *getExtension(Encoding encoding);
00427 
00438         static Encoding getEncoding(const char *name);
00439 
00446         static Encoding getStereo(Encoding encoding);
00447 
00454         static Encoding getMono(Encoding encoding);
00455 
00462         static bool isLinear(Encoding encoding);
00463 
00472         static bool isBuffered(Encoding encoding);
00473 
00480         static bool isMono(Encoding encoding);
00481 
00488         static bool isStereo(Encoding encoding);
00489 
00497         static Rate getRate(Encoding encoding);
00498 
00507         static Rate getRate(Encoding e, Rate request);
00508 
00516         static timeout_t getFraming(Encoding encoding, timeout_t timeout = 0);
00517 
00525         static timeout_t getFraming(Info &info, timeout_t timeout = 0);
00526 
00534         static bool isEndian(Encoding encoding);
00535 
00543         static bool isEndian(Info &info);
00544 
00554         static bool swapEndian(Encoding encoding, void *buffer, unsigned number);
00555 
00564         static void swapEncoded(Info &info, Encoded data, size_t bytes);
00565 
00576         static bool swapEndian(Info &info, void *buffer, unsigned number);
00577 
00586         static Level getImpulse(Encoding encoding, void *buffer, unsigned number);
00587 
00596         static Level getImpulse(Info &info, void *buffer, unsigned number = 0);
00597 
00607         static Level getPeak(Encoding encoding, void *buffer, unsigned number);
00608 
00618         static Level getPeak(Info &info, void *buffer, unsigned number = 0);
00619 
00627         static void toTimestamp(timeout_t duration, char *address, size_t size);
00628 
00635         static timeout_t toTimeout(const char *timestamp);
00636 
00659         static int getFrame(Encoding encoding, int samples = 0);
00660 
00673         static int getCount(Encoding encoding);
00674 
00683         static unsigned long toSamples(Encoding encoding, size_t bytes);
00684 
00693         static unsigned long toSamples(Info &info, size_t bytes);
00694 
00703         static size_t toBytes(Info &info, unsigned long number);
00704 
00713         static size_t toBytes(Encoding encoding, unsigned long number);
00714 
00723         static void fill(unsigned char *address, int number, Encoding encoding);
00724 
00731         static bool loadPlugin(const char *path);
00732 
00740         static size_t maxFramesize(Info &info);
00741 };
00742 
00750 class __EXPORT AudioResample : public Audio
00751 {
00752 protected:
00753         unsigned mfact, dfact, max;
00754         unsigned gpos, ppos;
00755         Sample last;
00756         Linear buffer;
00757 
00758 public:
00759         AudioResample(Rate mul, Rate div);
00760         ~AudioResample();
00761 
00762         size_t process(Linear from, Linear to, size_t count);
00763         size_t estimate(size_t count);
00764 };
00765 
00774 class __EXPORT AudioTone : public Audio
00775 {
00776 protected:
00777         Rate rate;
00778         unsigned samples;
00779         Linear frame;
00780         double df1, df2, p1, p2;
00781         Level m1, m2;
00782         bool silencer;
00783 
00787         void silence(void);
00788 
00792         void reset(void);
00793 
00797         void cleanup(void);
00798 
00805         void single(unsigned freq, Level level);
00806 
00815         void dual(unsigned f1, unsigned f2, Level l1, Level l2);
00816 
00817 public:
00823         inline Rate getRate(void)
00824                 {return rate;};
00825 
00831         inline size_t getSamples(void)
00832                 {return samples;};
00833 
00839         bool isSilent(void);
00840 
00848         virtual Linear getFrame(void);
00849 
00858         unsigned getFrames(Linear buffer, unsigned number);
00859 
00866         virtual bool isComplete(void);
00867 
00874         AudioTone(timeout_t duration = 20, Rate rate = rate8khz);
00875 
00886         AudioTone(unsigned f1, unsigned f2, Level l1, Level l2,
00887                 timeout_t duration = 20, Rate sample = rate8khz);
00888 
00897         AudioTone(unsigned freq, Level level, timeout_t duration = 20, Rate sample = rate8khz);
00898 
00899         virtual ~AudioTone();
00900 };
00901 
00908 class __EXPORT AudioBase : public Audio
00909 {
00910 protected:
00911         Info info;
00912 
00913 public:
00917         AudioBase();
00918 
00924         AudioBase(Info *info);
00925 
00929         virtual ~AudioBase();
00930 
00936         inline Encoding getEncoding(void)
00937                 {return info.encoding;};
00938 
00944         inline unsigned getSampleRate(void)
00945                 {return info.rate;};
00946 
00954         virtual ssize_t putBuffer(Encoded data, size_t size) = 0;
00955 
00964         ssize_t putNative(Encoded data, size_t size);
00965 
00973         virtual ssize_t getBuffer(Encoded data, size_t size) = 0;
00974 
00981         inline ssize_t getPacket(Encoded data)
00982                 {return getBuffer(data, 0);};
00983 
00991         ssize_t getNative(Encoded data, size_t size);
00992 };
00993 
01001 class __EXPORT AudioBuffer : public AudioBase
01002 {
01003 public:
01004         AudioBuffer(Info *info, size_t size = 4096);
01005         virtual ~AudioBuffer();
01006 
01014         ssize_t getBuffer(Encoded data, size_t number);
01015 
01023         ssize_t putBuffer(Encoded data, size_t number);
01024 
01025 private:
01026         char *buf;
01027         size_t size, start, len;
01028         void *mutexObject;
01029 
01030         void enter(void);
01031         void leave(void);
01032 };
01033 
01042 class __EXPORT AudioFile: public AudioBase
01043 {
01044 protected:
01045         char *pathname;
01046         Error error;
01047         unsigned long header;           // offset to start of audio
01048         unsigned long minimum;          // minimum sample size required
01049         unsigned long length;           // current size of file, including header
01050 
01051         void initialize(void);
01052         void getWaveFormat(int size);
01053         void mp3info(mpeg_audio *mp3);
01054 
01055         union {
01056                 int fd;
01057                 void *handle;
01058         } file;
01059 
01060         Mode mode;
01061         unsigned long iolimit;
01062 
01063         virtual bool afCreate(const char *path, bool exclusive = false);
01064         virtual bool afOpen(const char *path, Mode m = modeWrite);
01065         virtual bool afPeek(unsigned char *data, unsigned size);
01066 
01067         AudioCodec *getCodec(void);
01068 
01081         virtual int afRead(unsigned char *data, unsigned size);
01082 
01094         virtual int afWrite(unsigned char *data, unsigned size);
01095 
01105         virtual bool afSeek(unsigned long pos);
01106 
01110         virtual void afClose(void);
01111 
01119         virtual char *getContinuation(void)
01120                 {return NULL;};
01121 
01130         const char * getErrorStr(Error err);
01131 
01132         Error setError(Error err);
01133 
01140         inline unsigned long getHeader(void)
01141                 {return header;};
01142 
01151         unsigned short getShort(unsigned char *data);
01152 
01161         void setShort(unsigned char *data, unsigned short value);
01162 
01171         unsigned long getLong(unsigned char *data);
01172 
01181         void setLong(unsigned char *data, unsigned long value);
01182 
01183 public:
01190         AudioFile(const char *name, unsigned long offset = 0);
01191 
01199         AudioFile(const char *name, Info *info, unsigned long minimum = 0);
01200 
01204         inline AudioFile()
01205                 {initialize();};
01206 
01207         virtual ~AudioFile();
01208 
01219         void open(const char *name, Mode mode = modeWrite, timeout_t framing = 0);
01220 
01231         void create(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01232 
01239         time_t getAge(void);
01240 
01246         inline size_t getSize(void)
01247                 {return maxFramesize(info);};
01248 
01254         void close(void);
01255 
01263         void clear(void);
01264 
01276         ssize_t getBuffer(Encoded buffer, size_t len = 0);
01277 
01286         unsigned getLinear(Linear buffer, unsigned request = 0);
01287 
01299         ssize_t putBuffer(Encoded buffer, size_t len = 0);
01300 
01309         unsigned putLinear(Linear buffer, unsigned request = 0);
01310 
01325         Error getSamples(void *buffer, unsigned samples = 0);
01326 
01340         Error putSamples(void *buffer, unsigned samples = 0);
01341 
01349         Error skip(long number);
01350 
01358         Error setPosition(unsigned long samples = ~0l);
01359 
01367         Error position(const char *timestamp);
01368 
01375         void getPosition(char *timestamp, size_t size);
01376 
01384         Error setLimit(unsigned long maximum = 0l);
01385 
01393         Error getInfo(Info *info);
01394 
01403         Error setMinimum(unsigned long minimum);
01404 
01414         unsigned long getAbsolutePosition(void);
01415 
01427         unsigned long getPosition(void);
01428 
01434         virtual bool isOpen(void);
01435 
01443         virtual bool hasPositioning(void)
01444                 {return true;};
01445 
01451         inline Encoding getEncoding(void)
01452                 {return info.encoding;};
01453 
01459         inline Format getFormat(void)
01460                 {return info.format;};
01461 
01468         inline unsigned getSampleRate(void)
01469                 {return info.rate;};
01470 
01476         inline char *getAnnotation(void)
01477                 {return info.annotation;};
01478 
01484         inline Error getError(void)
01485                 {return error;};
01486 
01487         inline bool operator!(void)
01488                 {return (bool)!isOpen();};
01489 
01495         bool isSigned(void);
01496 };
01497 
01509 class __EXPORT AudioStream : public AudioFile
01510 {
01511 protected:
01512         AudioCodec *codec;      // if needed
01513         Encoded framebuf;
01514         bool streamable;
01515         Linear bufferFrame;
01516         unsigned bufferPosition;
01517         unsigned bufferChannels;
01518         Linear encBuffer, decBuffer;
01519         unsigned encSize, decSize;
01520 
01521         unsigned bufAudio(Linear samples, unsigned count, unsigned size);
01522 
01523 public:
01527         AudioStream();
01528 
01536         AudioStream(const char *name, Mode mode = modeRead, timeout_t framing = 0);
01537 
01546         AudioStream(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01547 
01548         virtual ~AudioStream();
01549 
01557         ssize_t getBuffer(Encoded data, size_t count);
01558 
01566         void open(const char *name, Mode mode = modeRead, timeout_t framing = 0);
01567 
01576         void create(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01577 
01581         void close(void);
01582 
01586         void flush(void);
01587 
01594         bool isStreamable(void);
01595 
01599         unsigned getCount(void);        // frame count
01600 
01610         unsigned getEncoded(AudioCodec *codec, Encoded address, unsigned frames = 1);
01611 
01621         unsigned putEncoded(AudioCodec *codec, Encoded address, unsigned frames = 1);
01622 
01630         unsigned getEncoded(Encoded address, unsigned frames = 1);
01631 
01639         unsigned putEncoded(Encoded address, unsigned frames = 1);
01640 
01648         ssize_t getPacket(Encoded data);
01649 
01658         unsigned getMono(Linear buffer, unsigned frames = 1);
01659 
01668         unsigned getStereo(Linear buffer, unsigned frames = 1);
01669 
01678         unsigned putMono(Linear buffer, unsigned frames = 1);
01679 
01688         unsigned putStereo(Linear buffer, unsigned frames = 1);
01689 
01699         unsigned bufMono(Linear buffer, unsigned count);
01700 
01710         unsigned bufStereo(Linear buffer, unsigned count);
01711 
01717         inline AudioCodec *getCodec(void)
01718                 {return codec;};
01719 };
01720 
01733 class __EXPORT AudioCodec : public Audio
01734 {
01735 protected:
01736         static AudioCodec *first;
01737         AudioCodec *next;
01738         Encoding encoding;
01739         const char *name;
01740         Info info;
01741 
01742         AudioCodec();
01743 
01751         virtual AudioCodec *getByFormat(const char *format)
01752                 {return this;};
01753 
01760         virtual AudioCodec *getByInfo(Info &info)
01761                 {return this;};
01762 
01763 public:
01770         AudioCodec(const char *name, Encoding encoding);
01771 
01772         virtual ~AudioCodec() {};
01773 
01780         static void endCodec(AudioCodec *codec);
01781 
01791         static AudioCodec *getCodec(Encoding encoding, const char *format = NULL, bool loaded = false);
01792 
01801         static AudioCodec *getCodec(Info &info, bool loaded = false);
01802 
01809         static bool load(const char *name);
01810 
01818         static bool load(Encoding encoding);
01819 
01828         virtual Level getImpulse(void *buffer, unsigned number = 0);
01829 
01837         virtual Level getPeak(void *buffer, unsigned number = 0);
01838 
01849         virtual bool isSilent(Level threashold, void *buffer, unsigned number = 0);
01850 
01859         virtual unsigned encode(Linear buffer, void *dest, unsigned number = 0) = 0;
01860 
01869         virtual unsigned encodeBuffered(Linear Buffer, Encoded dest, unsigned number);
01870 
01879         virtual unsigned decode(Linear buffer, void *source, unsigned number = 0) = 0;
01880 
01890         virtual unsigned decodeBuffered(Linear buffer, Encoded source, unsigned len);
01891 
01897         virtual unsigned getEstimated(void);
01898 
01904         virtual unsigned getRequired(void);
01905 
01915         virtual unsigned getPacket(Encoded destination, Encoded data, unsigned size);
01916 
01922         inline Info getInfo(void)
01923                 {return info;};
01924 };
01925 
01926 class __EXPORT AudioDevice : public AudioBase
01927 {
01928 protected:
01929         bool enabled;
01930 
01931 public:
01932         virtual ~AudioDevice() {};
01933 
01941         virtual unsigned putSamples(Linear buffer, unsigned count) = 0;
01942 
01950         virtual unsigned getSamples(Linear buffer, unsigned count) = 0;
01951 
01960         virtual ssize_t putBuffer(Encoded data, size_t count);
01961 
01970         virtual ssize_t getBuffer(Encoded data, size_t count);
01971 
01979         virtual bool setEncoded(Info &info)
01980                 {return false;};
01981 
01990         virtual bool setAudio(Rate rate = rate8khz, bool stereo = false, timeout_t framing = 20) = 0;
01991 
01998         virtual void sync(void)
01999                 {return;};
02000 
02004         virtual void flush(void) = 0;
02005 
02015         unsigned bufMono(Linear buffer, unsigned count);
02016 
02026         unsigned bufStereo(Linear buffer, unsigned count);
02027 
02033         inline Info *getInfo(void)
02034                 {return &info;};
02035 
02044         inline bool isEnabled(void)
02045                 {return enabled;};
02046 };
02047 
02056 class __EXPORT TelTone : public AudioTone
02057 {
02058 public:
02059         typedef struct _tonedef {
02060                 struct _tonedef *next;
02061                 timeout_t duration, silence;
02062                 unsigned count;
02063                 unsigned short f1, f2;
02064         } tonedef_t;
02065 
02066         typedef struct _tonekey {
02067                 struct _tonekey *next;
02068                 struct _tonedef *first;
02069                 struct _tonedef *last;
02070                 char id[1];
02071         } tonekey_t;
02072 
02081         TelTone(tonekey_t *key, Level level, timeout_t frame = 20);
02082         ~TelTone();
02083 
02090         Linear getFrame(void);
02091 
02098         bool isComplete(void);
02099 
02100 
02108         static bool load(const char *pathname, const char *locale = NULL);
02109 
02117         static tonekey_t *find(const char *tone, const char *locale = NULL);
02118 
02119 protected:
02120         tonekey_t *tone;
02121         tonedef_t *def;
02122         unsigned remaining, silent, count;
02123         timeout_t framing;
02124         Level level;
02125         bool complete;
02126 };
02127 
02137 class __EXPORT DTMFTones : public AudioTone
02138 {
02139 protected:
02140         unsigned remaining, dtmfframes;
02141         timeout_t frametime;
02142         const char *digits;
02143         Level level;
02144         bool complete;
02145 
02146 public:
02155         DTMFTones(const char *digits, Level level, timeout_t duration = 20, timeout_t interdigit = 60);
02156 
02157         ~DTMFTones();
02158 
02159         Linear getFrame(void);
02160         bool isComplete(void);
02161 };
02162 
02172 class __EXPORT MFTones : public AudioTone
02173 {
02174 protected:
02175         unsigned remaining, mfframes;
02176         timeout_t frametime;
02177         const char *digits;
02178         Level level;
02179         bool complete, kflag;
02180 
02181 public:
02190         MFTones(const char *digits, Level level, timeout_t duration = 20, timeout_t interdigit = 60);
02191 
02192         ~MFTones();
02193 
02194         Linear getFrame(void);
02195         bool isComplete(void);
02196 };
02197 
02198 
02203 class __EXPORT DTMFDetect : public Audio
02204 {
02205 public:
02206         DTMFDetect();
02207         ~DTMFDetect();
02208 
02217         int putSamples(Linear buffer, int count);
02218 
02225         int getResult(char *data, int size);
02226 
02227 protected:
02228         void goertzelInit(goertzel_state_t *s, tone_detection_descriptor_t *t);
02229         void goertzelUpdate(goertzel_state_t *s, Sample x[], int samples);
02230         float goertzelResult(goertzel_state_t *s);
02231 
02232 private:
02233         dtmf_detect_state_t *state;
02234         tone_detection_descriptor_t dtmf_detect_row[4];
02235         tone_detection_descriptor_t dtmf_detect_col[4];
02236         tone_detection_descriptor_t dtmf_detect_row_2nd[4];
02237         tone_detection_descriptor_t dtmf_detect_col_2nd[4];
02238         tone_detection_descriptor_t fax_detect;
02239         tone_detection_descriptor_t fax_detect_2nd;
02240 };
02241 
02242 }
02243 
02244 #endif
02245