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
00033
00034
00035
00036
00037
00044 #ifndef CCXX_AUDIO_H_
00045 #define CCXX_AUDIO_H_
00046
00047 #ifndef CCXX_PACKING
00048 #if defined(__GNUC__)
00049 #define CCXX_PACKED
00050 #elif !defined(__hpux) && !defined(_AIX)
00051 #define CCXX_PACKED
00052 #endif
00053 #endif
00054
00055 #ifndef W32
00056 #if defined(_WIN32) && defined(_MSC_VER)
00057 #pragma warning(disable: 4996)
00058 #define W32
00059 #endif
00060 #if defined(__BORLANDC__) && defined(__Windows)
00061 #define W32
00062 #endif
00063 #endif
00064
00065 #if !defined(__EXPORT) && defined(W32)
00066 #define __EXPORT __declspec(dllimport)
00067 #endif
00068
00069 #ifndef __EXPORT
00070 #define __EXPORT
00071 #endif
00072
00073 #ifdef W32
00074 #include <windows.h>
00075 #ifndef ssize_t
00076 #define ssize_t int
00077 #endif
00078 #else
00079 #include <cstddef>
00080 #include <cstdlib>
00081 #include <sys/types.h>
00082 #include <netinet/in.h>
00083 #endif
00084
00085 #include <ctime>
00086
00087 namespace ost {
00088
00089 #define AUDIO_SIGNED_LINEAR_RAW 1
00090 #define AUDIO_LINEAR_CONVERSION 1
00091 #define AUDIO_CODEC_MODULES 1
00092 #define AUDIO_LINEAR_FRAMING 1
00093 #define AUDIO_NATIVE_METHODS 1
00094 #define AUDIO_RATE_RESAMPLER 1
00095
00096 class __EXPORT AudioCodec;
00097 class __EXPORT AudioDevice;
00098
00107 class __EXPORT Audio
00108 {
00109 public:
00110 #ifdef W32
00111 typedef short Sample;
00112 typedef short *Linear;
00113 typedef short Level;
00114 typedef DWORD timeout_t;
00115 typedef WORD snd16_t;
00116 typedef DWORD snd32_t;
00117 #else
00118 typedef int16_t snd16_t;
00119 typedef int32_t snd32_t;
00120 typedef int16_t Level;
00121 typedef int16_t Sample;
00122 typedef int16_t *Linear;
00123 typedef unsigned long timeout_t;
00124 #endif
00125
00126 static const unsigned ndata;
00127
00128 typedef struct
00129 {
00130 float v2;
00131 float v3;
00132 float fac;
00133 } goertzel_state_t;
00134
00135 typedef struct
00136 {
00137 int hit1;
00138 int hit2;
00139 int hit3;
00140 int hit4;
00141 int mhit;
00142
00143 goertzel_state_t row_out[4];
00144 goertzel_state_t col_out[4];
00145 goertzel_state_t row_out2nd[4];
00146 goertzel_state_t col_out2nd[4];
00147 goertzel_state_t fax_tone;
00148 goertzel_state_t fax_tone2nd;
00149 float energy;
00150
00151 int current_sample;
00152 char digits[129];
00153 int current_digits;
00154 int detected_digits;
00155 int lost_digits;
00156 int digit_hits[16];
00157 int fax_hits;
00158 } dtmf_detect_state_t;
00159
00160 typedef struct
00161 {
00162 float fac;
00163 } tone_detection_descriptor_t;
00164
00165 typedef unsigned char *Encoded;
00166
00170 enum Rate
00171 {
00172 rateUnknown,
00173 rate6khz = 6000,
00174 rate8khz = 8000,
00175 rate16khz = 16000,
00176 rate44khz = 44100
00177 };
00178
00179 typedef enum Rate Rate;
00180
00184 enum Mode
00185 {
00186 modeRead,
00187 modeReadAny,
00188 modeReadOne,
00189 modeWrite,
00190 modeCache,
00191 modeInfo,
00192 modeFeed,
00193
00194 modeAppend,
00195 modeCreate
00196 };
00197
00198 typedef enum Mode Mode;
00199
00203 enum Encoding
00204 {
00205 unknownEncoding = 0,
00206 g721ADPCM,
00207 g722Audio,
00208 g722_7bit,
00209 g722_6bit,
00210 g723_2bit,
00211 g723_3bit,
00212 g723_5bit,
00213 gsmVoice,
00214 msgsmVoice,
00215 mulawAudio,
00216 alawAudio,
00217 mp1Audio,
00218 mp2Audio,
00219 mp3Audio,
00220 okiADPCM,
00221 voxADPCM,
00222 sx73Voice,
00223 sx96Voice,
00224
00225
00226
00227
00228 cdaStereo,
00229 cdaMono,
00230 pcm8Stereo,
00231 pcm8Mono,
00232 pcm16Stereo,
00233 pcm16Mono,
00234 pcm32Stereo,
00235 pcm32Mono,
00236
00237
00238 speexVoice,
00239 speexAudio,
00240
00241 g729Audio,
00242 ilbcAudio
00243 };
00244 typedef enum Encoding Encoding;
00245
00249 enum Format
00250 {
00251 raw,
00252 snd,
00253 riff,
00254 mpeg,
00255 wave
00256 };
00257 typedef enum Format Format;
00258
00262 enum DeviceMode
00263 {
00264 PLAY,
00265 RECORD,
00266 PLAYREC
00267 };
00268 typedef enum DeviceMode DeviceMode;
00269
00273 enum Error
00274 {
00275 errSuccess = 0,
00276 errReadLast,
00277 errNotOpened,
00278 errEndOfFile,
00279 errStartOfFile,
00280 errRateInvalid,
00281 errEncodingInvalid,
00282 errReadInterrupt,
00283 errWriteInterrupt,
00284 errReadFailure,
00285 errWriteFailure,
00286 errReadIncomplete,
00287 errWriteIncomplete,
00288 errRequestInvalid,
00289 errTOCFailed,
00290 errStatFailed,
00291 errInvalidTrack,
00292 errPlaybackFailed,
00293 errNotPlaying,
00294 errNoCodec
00295 };
00296 typedef enum Error Error;
00297
00298
00299 #ifdef CCXX_PACKED
00300 #pragma pack(1)
00301 #endif
00302
00303 typedef struct
00304 {
00305 #if __BYTE_ORDER == __LITTLE_ENDIAN
00306 unsigned char mp_sync1 : 8;
00307 unsigned char mp_crc : 1;
00308 unsigned char mp_layer : 2;
00309 unsigned char mp_ver : 2;
00310 unsigned char mp_sync2 : 3;
00311
00312 unsigned char mp_priv : 1;
00313 unsigned char mp_pad : 1;
00314 unsigned char mp_srate : 2;
00315 unsigned char mp_brate : 4;
00316
00317 unsigned char mp_emp : 2;
00318 unsigned char mp_original : 1;
00319 unsigned char mp_copyright: 1;
00320 unsigned char mp_extend : 2;
00321 unsigned char mp_channels : 2;
00322
00323 #else
00324 unsigned char mp_sync1 : 8;
00325
00326 unsigned char mp_sync2 : 3;
00327 unsigned char mp_ver : 2;
00328 unsigned char mp_layer : 2;
00329 unsigned char mp_crc : 1;
00330
00331 unsigned char mp_brate : 4;
00332 unsigned char mp_srate : 2;
00333 unsigned char mp_pad : 1;
00334 unsigned char mp_priv : 1;
00335
00336 unsigned char mp_channels : 2;
00337 unsigned char mp_extend : 2;
00338 unsigned char mp_copyright : 1;
00339 unsigned char mp_original : 1;
00340 unsigned char mp_emp : 2;
00341 #endif
00342 } mpeg_audio;
00343
00344 typedef struct
00345 {
00346 char tag_id[3];
00347 char tag_title[30];
00348 char tag_artist[30];
00349 char tag_album[30];
00350 char tag_year[4];
00351 char tag_note[30];
00352 unsigned char genre;
00353 } mpeg_tagv1;
00354
00355 #ifdef CCXX_PACKED
00356 #pragma pack()
00357 #endif
00358
00362 class __EXPORT Info
00363 {
00364 public:
00365 Format format;
00366 Encoding encoding;
00367 unsigned long rate;
00368 unsigned long bitrate;
00369 unsigned order;
00370 unsigned framesize, framecount, headersize, padding;
00371 timeout_t framing;
00372 char *annotation;
00373
00374 Info();
00375 void clear(void);
00376 void set(void);
00377 void setFraming(timeout_t frame);
00378 void setRate(Rate rate);
00379 };
00380
00387 static Level tolevel(float dbm);
00388
00395 static float todbm(Level power);
00396
00404 static bool hasDevice(unsigned device = 0);
00405
00416 static AudioDevice *getDevice(unsigned device = 0, DeviceMode mode = PLAY);
00417
00423 static const char *getCodecPath(void);
00424
00432 static const char *getMIME(Info &info);
00433
00441 static const char *getName(Encoding encoding);
00442
00450 static const char *getExtension(Encoding encoding);
00451
00462 static Encoding getEncoding(const char *name);
00463
00470 static Encoding getStereo(Encoding encoding);
00471
00478 static Encoding getMono(Encoding encoding);
00479
00486 static bool isLinear(Encoding encoding);
00487
00496 static bool isBuffered(Encoding encoding);
00497
00504 static bool isMono(Encoding encoding);
00505
00512 static bool isStereo(Encoding encoding);
00513
00521 static Rate getRate(Encoding encoding);
00522
00531 static Rate getRate(Encoding e, Rate request);
00532
00540 static timeout_t getFraming(Encoding encoding, timeout_t timeout = 0);
00541
00549 static timeout_t getFraming(Info &info, timeout_t timeout = 0);
00550
00558 static bool isEndian(Encoding encoding);
00559
00567 static bool isEndian(Info &info);
00568
00578 static bool swapEndian(Encoding encoding, void *buffer, unsigned number);
00579
00588 static void swapEncoded(Info &info, Encoded data, size_t bytes);
00589
00600 static bool swapEndian(Info &info, void *buffer, unsigned number);
00601
00610 static Level getImpulse(Encoding encoding, void *buffer, unsigned number);
00611
00620 static Level getImpulse(Info &info, void *buffer, unsigned number = 0);
00621
00631 static Level getPeak(Encoding encoding, void *buffer, unsigned number);
00632
00642 static Level getPeak(Info &info, void *buffer, unsigned number = 0);
00643
00651 static void toTimestamp(timeout_t duration, char *address, size_t size);
00652
00659 static timeout_t toTimeout(const char *timestamp);
00660
00683 static int getFrame(Encoding encoding, int samples = 0);
00684
00697 static int getCount(Encoding encoding);
00698
00707 static unsigned long toSamples(Encoding encoding, size_t bytes);
00708
00717 static unsigned long toSamples(Info &info, size_t bytes);
00718
00727 static size_t toBytes(Info &info, unsigned long number);
00728
00737 static size_t toBytes(Encoding encoding, unsigned long number);
00738
00747 static void fill(unsigned char *address, int number, Encoding encoding);
00748
00755 static bool loadPlugin(const char *path);
00756
00764 static size_t maxFramesize(Info &info);
00765 };
00766
00774 class __EXPORT AudioResample : public Audio
00775 {
00776 protected:
00777 unsigned mfact, dfact, max;
00778 unsigned gpos, ppos;
00779 Sample last;
00780 Linear buffer;
00781
00782 public:
00783 AudioResample(Rate mul, Rate div);
00784 ~AudioResample();
00785
00786 size_t process(Linear from, Linear to, size_t count);
00787 size_t estimate(size_t count);
00788 };
00789
00798 class __EXPORT AudioTone : public Audio
00799 {
00800 protected:
00801 Rate rate;
00802 unsigned samples;
00803 Linear frame;
00804 double df1, df2, p1, p2;
00805 Level m1, m2;
00806 bool silencer;
00807
00811 void silence(void);
00812
00816 void reset(void);
00817
00821 void cleanup(void);
00822
00829 void single(unsigned freq, Level level);
00830
00839 void dual(unsigned f1, unsigned f2, Level l1, Level l2);
00840
00841 public:
00847 inline Rate getRate(void)
00848 {return rate;};
00849
00855 inline size_t getSamples(void)
00856 {return samples;};
00857
00863 bool isSilent(void);
00864
00872 virtual Linear getFrame(void);
00873
00882 unsigned getFrames(Linear buffer, unsigned number);
00883
00890 virtual bool isComplete(void);
00891
00898 AudioTone(timeout_t duration = 20, Rate rate = rate8khz);
00899
00910 AudioTone(unsigned f1, unsigned f2, Level l1, Level l2,
00911 timeout_t duration = 20, Rate sample = rate8khz);
00912
00921 AudioTone(unsigned freq, Level level, timeout_t duration = 20, Rate sample = rate8khz);
00922
00923 virtual ~AudioTone();
00924 };
00925
00932 class __EXPORT AudioBase : public Audio
00933 {
00934 protected:
00935 Info info;
00936
00937 public:
00941 AudioBase();
00942
00948 AudioBase(Info *info);
00949
00953 virtual ~AudioBase();
00954
00960 inline Encoding getEncoding(void)
00961 {return info.encoding;};
00962
00968 inline unsigned getSampleRate(void)
00969 {return info.rate;};
00970
00978 virtual ssize_t putBuffer(Encoded data, size_t size) = 0;
00979
00988 ssize_t putNative(Encoded data, size_t size);
00989
00997 virtual ssize_t getBuffer(Encoded data, size_t size) = 0;
00998
01005 inline ssize_t getPacket(Encoded data)
01006 {return getBuffer(data, 0);};
01007
01015 ssize_t getNative(Encoded data, size_t size);
01016 };
01017
01025 class __EXPORT AudioBuffer : public AudioBase
01026 {
01027 public:
01028 AudioBuffer(Info *info, size_t size = 4096);
01029 virtual ~AudioBuffer();
01030
01038 ssize_t getBuffer(Encoded data, size_t number);
01039
01047 ssize_t putBuffer(Encoded data, size_t number);
01048
01049 private:
01050 char *buf;
01051 size_t size, start, len;
01052 void *mutexObject;
01053
01054 void enter(void);
01055 void leave(void);
01056 };
01057
01066 class __EXPORT AudioFile: public AudioBase
01067 {
01068 protected:
01069 char *pathname;
01070 Error error;
01071 unsigned long header;
01072 unsigned long minimum;
01073 unsigned long length;
01074
01075 void initialize(void);
01076 void getWaveFormat(int size);
01077 void mp3info(mpeg_audio *mp3);
01078
01079 union
01080 {
01081 int fd;
01082 void *handle;
01083 } file;
01084
01085 Mode mode;
01086 unsigned long iolimit;
01087
01088 virtual bool afCreate(const char *path, bool exclusive = false);
01089 virtual bool afOpen(const char *path, Mode m = modeWrite);
01090 virtual bool afPeek(unsigned char *data, unsigned size);
01091
01092 AudioCodec *getCodec(void);
01093
01106 virtual int afRead(unsigned char *data, unsigned size);
01107
01119 virtual int afWrite(unsigned char *data, unsigned size);
01120
01130 virtual bool afSeek(unsigned long pos);
01131
01135 virtual void afClose(void);
01136
01144 virtual char *getContinuation(void)
01145 {return NULL;};
01146
01155 const char * getErrorStr(Error err);
01156
01157 Error setError(Error err);
01158
01165 inline unsigned long getHeader(void)
01166 {return header;};
01167
01176 unsigned short getShort(unsigned char *data);
01177
01186 void setShort(unsigned char *data, unsigned short value);
01187
01196 unsigned long getLong(unsigned char *data);
01197
01206 void setLong(unsigned char *data, unsigned long value);
01207
01208 public:
01215 AudioFile(const char *name, unsigned long offset = 0);
01216
01224 AudioFile(const char *name, Info *info, unsigned long minimum = 0);
01225
01229 inline AudioFile()
01230 {initialize();};
01231
01232 virtual ~AudioFile();
01233
01244 void open(const char *name, Mode mode = modeWrite, timeout_t framing = 0);
01245
01256 void create(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01257
01264 time_t getAge(void);
01265
01271 inline size_t getSize(void)
01272 {return maxFramesize(info);};
01273
01279 void close(void);
01280
01288 void clear(void);
01289
01301 ssize_t getBuffer(Encoded buffer, size_t len = 0);
01302
01311 unsigned getLinear(Linear buffer, unsigned request = 0);
01312
01324 ssize_t putBuffer(Encoded buffer, size_t len = 0);
01325
01334 unsigned putLinear(Linear buffer, unsigned request = 0);
01335
01350 Error getSamples(void *buffer, unsigned samples = 0);
01351
01365 Error putSamples(void *buffer, unsigned samples = 0);
01366
01374 Error skip(long number);
01375
01383 Error setPosition(unsigned long samples = ~0l);
01384
01392 Error position(const char *timestamp);
01393
01400 void getPosition(char *timestamp, size_t size);
01401
01409 Error setLimit(unsigned long maximum = 0l);
01410
01418 Error getInfo(Info *info);
01419
01428 Error setMinimum(unsigned long minimum);
01429
01439 unsigned long getAbsolutePosition(void);
01440
01452 unsigned long getPosition(void);
01453
01459 virtual bool isOpen(void);
01460
01468 virtual bool hasPositioning(void)
01469 {return true;};
01470
01476 inline Encoding getEncoding(void)
01477 {return info.encoding;};
01478
01484 inline Format getFormat(void)
01485 {return info.format;};
01486
01493 inline unsigned getSampleRate(void)
01494 {return info.rate;};
01495
01501 inline char *getAnnotation(void)
01502 {return info.annotation;};
01503
01509 inline Error getError(void)
01510 {return error;};
01511
01512 inline bool operator!(void)
01513 {return (bool)!isOpen();};
01514
01520 bool isSigned(void);
01521 };
01522
01534 class __EXPORT AudioStream : public AudioFile
01535 {
01536 protected:
01537 AudioCodec *codec;
01538 Encoded framebuf;
01539 bool streamable;
01540 Linear bufferFrame;
01541 unsigned bufferPosition;
01542 unsigned bufferChannels;
01543 Linear encBuffer, decBuffer;
01544 unsigned encSize, decSize;
01545
01546 unsigned bufAudio(Linear samples, unsigned count, unsigned size);
01547
01548 public:
01552 AudioStream();
01553
01561 AudioStream(const char *name, Mode mode = modeRead, timeout_t framing = 0);
01562
01571 AudioStream(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01572
01573 virtual ~AudioStream();
01574
01582 ssize_t getBuffer(Encoded data, size_t count);
01583
01591 void open(const char *name, Mode mode = modeRead, timeout_t framing = 0);
01592
01601 void create(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01602
01606 void close(void);
01607
01611 void flush(void);
01612
01619 bool isStreamable(void);
01620
01624 unsigned getCount(void);
01625
01635 unsigned getEncoded(AudioCodec *codec, Encoded address, unsigned frames = 1);
01636
01646 unsigned putEncoded(AudioCodec *codec, Encoded address, unsigned frames = 1);
01647
01655 unsigned getEncoded(Encoded address, unsigned frames = 1);
01656
01664 unsigned putEncoded(Encoded address, unsigned frames = 1);
01665
01673 ssize_t getPacket(Encoded data);
01674
01683 unsigned getMono(Linear buffer, unsigned frames = 1);
01684
01693 unsigned getStereo(Linear buffer, unsigned frames = 1);
01694
01703 unsigned putMono(Linear buffer, unsigned frames = 1);
01704
01713 unsigned putStereo(Linear buffer, unsigned frames = 1);
01714
01724 unsigned bufMono(Linear buffer, unsigned count);
01725
01735 unsigned bufStereo(Linear buffer, unsigned count);
01736
01742 inline AudioCodec *getCodec(void)
01743 {return codec;};
01744 };
01745
01758 class __EXPORT AudioCodec : public Audio
01759 {
01760 protected:
01761 static AudioCodec *first;
01762 AudioCodec *next;
01763 Encoding encoding;
01764 const char *name;
01765 Info info;
01766
01767 AudioCodec();
01768
01776 virtual AudioCodec *getByFormat(const char *format)
01777 {return this;};
01778
01785 virtual AudioCodec *getByInfo(Info &info)
01786 {return this;};
01787
01788 public:
01795 AudioCodec(const char *name, Encoding encoding);
01796
01797 virtual ~AudioCodec() {};
01798
01805 static void endCodec(AudioCodec *codec);
01806
01816 static AudioCodec *getCodec(Encoding encoding, const char *format = NULL, bool loaded = false);
01817
01826 static AudioCodec *getCodec(Info &info, bool loaded = false);
01827
01834 static bool load(const char *name);
01835
01843 static bool load(Encoding encoding);
01844
01853 virtual Level getImpulse(void *buffer, unsigned number = 0);
01854
01862 virtual Level getPeak(void *buffer, unsigned number = 0);
01863
01874 virtual bool isSilent(Level threashold, void *buffer, unsigned number = 0);
01875
01884 virtual unsigned encode(Linear buffer, void *dest, unsigned number = 0) = 0;
01885
01894 virtual unsigned encodeBuffered(Linear Buffer, Encoded dest, unsigned number);
01895
01904 virtual unsigned decode(Linear buffer, void *source, unsigned number = 0) = 0;
01905
01915 virtual unsigned decodeBuffered(Linear buffer, Encoded source, unsigned len);
01916
01922 virtual unsigned getEstimated(void);
01923
01929 virtual unsigned getRequired(void);
01930
01940 virtual unsigned getPacket(Encoded destination, Encoded data, unsigned size);
01941
01947 inline Info getInfo(void)
01948 {return info;};
01949 };
01950
01951 class __EXPORT AudioDevice : public AudioBase
01952 {
01953 protected:
01954 bool enabled;
01955
01956 public:
01957 virtual ~AudioDevice() {};
01958
01966 virtual unsigned putSamples(Linear buffer, unsigned count) = 0;
01967
01975 virtual unsigned getSamples(Linear buffer, unsigned count) = 0;
01976
01985 virtual ssize_t putBuffer(Encoded data, size_t count);
01986
01995 virtual ssize_t getBuffer(Encoded data, size_t count);
01996
02004 virtual bool setEncoded(Info &info)
02005 {return false;};
02006
02015 virtual bool setAudio(Rate rate = rate8khz, bool stereo = false, timeout_t framing = 20) = 0;
02016
02023 virtual void sync(void)
02024 {return;};
02025
02029 virtual void flush(void) = 0;
02030
02040 unsigned bufMono(Linear buffer, unsigned count);
02041
02051 unsigned bufStereo(Linear buffer, unsigned count);
02052
02058 inline Info *getInfo(void)
02059 {return &info;};
02060
02069 inline bool isEnabled(void)
02070 {return enabled;};
02071 };
02072
02081 class __EXPORT TelTone : public AudioTone
02082 {
02083 public:
02084 typedef struct _tonedef
02085 {
02086 struct _tonedef *next;
02087 timeout_t duration, silence;
02088 unsigned count;
02089 unsigned short f1, f2;
02090 } tonedef_t;
02091
02092 typedef struct _tonekey
02093 {
02094 struct _tonekey *next;
02095 struct _tonedef *first;
02096 struct _tonedef *last;
02097 char id[1];
02098 } tonekey_t;
02099
02108 TelTone(tonekey_t *key, Level level, timeout_t frame = 20);
02109 ~TelTone();
02110
02117 Linear getFrame(void);
02118
02125 bool isComplete(void);
02126
02127
02135 static bool load(const char *pathname, const char *locale = NULL);
02136
02144 static tonekey_t *find(const char *tone, const char *locale = NULL);
02145
02146 protected:
02147 tonekey_t *tone;
02148 tonedef_t *def;
02149 unsigned remaining, silent, count;
02150 timeout_t framing;
02151 Level level;
02152 bool complete;
02153 };
02154
02164 class __EXPORT DTMFTones : public AudioTone
02165 {
02166 protected:
02167 unsigned remaining, dtmfframes;
02168 timeout_t frametime;
02169 const char *digits;
02170 Level level;
02171 bool complete;
02172
02173 public:
02182 DTMFTones(const char *digits, Level level, timeout_t duration = 20, timeout_t interdigit = 60);
02183
02184 ~DTMFTones();
02185
02186 Linear getFrame(void);
02187 bool isComplete(void);
02188 };
02189
02199 class __EXPORT MFTones : public AudioTone
02200 {
02201 protected:
02202 unsigned remaining, mfframes;
02203 timeout_t frametime;
02204 const char *digits;
02205 Level level;
02206 bool complete, kflag;
02207
02208 public:
02217 MFTones(const char *digits, Level level, timeout_t duration = 20, timeout_t interdigit = 60);
02218
02219 ~MFTones();
02220
02221 Linear getFrame(void);
02222 bool isComplete(void);
02223 };
02224
02225
02230 class __EXPORT DTMFDetect : public Audio
02231 {
02232 public:
02233 DTMFDetect();
02234 ~DTMFDetect();
02235
02244 int putSamples(Linear buffer, int count);
02245
02252 int getResult(char *data, int size);
02253
02254 protected:
02255 void goertzelInit(goertzel_state_t *s, tone_detection_descriptor_t *t);
02256 void goertzelUpdate(goertzel_state_t *s, Sample x[], int samples);
02257 float goertzelResult(goertzel_state_t *s);
02258
02259 private:
02260 dtmf_detect_state_t *state;
02261 tone_detection_descriptor_t dtmf_detect_row[4];
02262 tone_detection_descriptor_t dtmf_detect_col[4];
02263 tone_detection_descriptor_t dtmf_detect_row_2nd[4];
02264 tone_detection_descriptor_t dtmf_detect_col_2nd[4];
02265 tone_detection_descriptor_t fax_detect;
02266 tone_detection_descriptor_t fax_detect_2nd;
02267 };
02268
02269 }
02270
02271 #endif
02272