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 float v2;
00130 float v3;
00131 float fac;
00132 } goertzel_state_t;
00133
00134 typedef struct {
00135 int hit1;
00136 int hit2;
00137 int hit3;
00138 int hit4;
00139 int mhit;
00140
00141 goertzel_state_t row_out[4];
00142 goertzel_state_t col_out[4];
00143 goertzel_state_t row_out2nd[4];
00144 goertzel_state_t col_out2nd[4];
00145 goertzel_state_t fax_tone;
00146 goertzel_state_t fax_tone2nd;
00147 float energy;
00148
00149 int current_sample;
00150 char digits[129];
00151 int current_digits;
00152 int detected_digits;
00153 int lost_digits;
00154 int digit_hits[16];
00155 int fax_hits;
00156 } dtmf_detect_state_t;
00157
00158 typedef struct {
00159 float fac;
00160 } tone_detection_descriptor_t;
00161
00162 typedef unsigned char *Encoded;
00163
00167 enum Rate {
00168 rateUnknown,
00169 rate6khz = 6000,
00170 rate8khz = 8000,
00171 rate16khz = 16000,
00172 rate32khz = 32000,
00173 rate44khz = 44100
00174 };
00175
00176 typedef enum Rate Rate;
00177
00181 enum Mode {
00182 modeRead,
00183 modeReadAny,
00184 modeReadOne,
00185 modeWrite,
00186 modeCache,
00187 modeInfo,
00188 modeFeed,
00189
00190 modeAppend,
00191 modeCreate
00192 };
00193
00194 typedef enum Mode Mode;
00195
00199 enum Encoding {
00200 unknownEncoding = 0,
00201 g721ADPCM,
00202 g722Audio,
00203 g722_7bit,
00204 g722_6bit,
00205 g723_2bit,
00206 g723_3bit,
00207 g723_5bit,
00208 gsmVoice,
00209 msgsmVoice,
00210 mulawAudio,
00211 alawAudio,
00212 mp1Audio,
00213 mp2Audio,
00214 mp3Audio,
00215 okiADPCM,
00216 voxADPCM,
00217 sx73Voice,
00218 sx96Voice,
00219
00220
00221
00222
00223 cdaStereo,
00224 cdaMono,
00225 pcm8Stereo,
00226 pcm8Mono,
00227 pcm16Stereo,
00228 pcm16Mono,
00229 pcm32Stereo,
00230 pcm32Mono,
00231
00232
00233 speexVoice,
00234 speexAudio,
00235
00236 g729Audio,
00237 ilbcAudio,
00238 speexUltra,
00239
00240 speexNarrow = speexVoice,
00241 speexWide = speexAudio,
00242 g723_4bit = g721ADPCM
00243 };
00244 typedef enum Encoding Encoding;
00245
00249 enum Format {
00250 raw,
00251 snd,
00252 riff,
00253 mpeg,
00254 wave
00255 };
00256 typedef enum Format Format;
00257
00261 enum DeviceMode {
00262 PLAY,
00263 RECORD,
00264 PLAYREC
00265 };
00266 typedef enum DeviceMode DeviceMode;
00267
00271 enum Error {
00272 errSuccess = 0,
00273 errReadLast,
00274 errNotOpened,
00275 errEndOfFile,
00276 errStartOfFile,
00277 errRateInvalid,
00278 errEncodingInvalid,
00279 errReadInterrupt,
00280 errWriteInterrupt,
00281 errReadFailure,
00282 errWriteFailure,
00283 errReadIncomplete,
00284 errWriteIncomplete,
00285 errRequestInvalid,
00286 errTOCFailed,
00287 errStatFailed,
00288 errInvalidTrack,
00289 errPlaybackFailed,
00290 errNotPlaying,
00291 errNoCodec
00292 };
00293 typedef enum Error Error;
00294
00295
00296 #ifdef CCXX_PACKED
00297 #pragma pack(1)
00298 #endif
00299
00300 typedef struct {
00301 #if __BYTE_ORDER == __LITTLE_ENDIAN
00302 unsigned char mp_sync1 : 8;
00303 unsigned char mp_crc : 1;
00304 unsigned char mp_layer : 2;
00305 unsigned char mp_ver : 2;
00306 unsigned char mp_sync2 : 3;
00307
00308 unsigned char mp_priv : 1;
00309 unsigned char mp_pad : 1;
00310 unsigned char mp_srate : 2;
00311 unsigned char mp_brate : 4;
00312
00313 unsigned char mp_emp : 2;
00314 unsigned char mp_original : 1;
00315 unsigned char mp_copyright: 1;
00316 unsigned char mp_extend : 2;
00317 unsigned char mp_channels : 2;
00318
00319 #else
00320 unsigned char mp_sync1 : 8;
00321
00322 unsigned char mp_sync2 : 3;
00323 unsigned char mp_ver : 2;
00324 unsigned char mp_layer : 2;
00325 unsigned char mp_crc : 1;
00326
00327 unsigned char mp_brate : 4;
00328 unsigned char mp_srate : 2;
00329 unsigned char mp_pad : 1;
00330 unsigned char mp_priv : 1;
00331
00332 unsigned char mp_channels : 2;
00333 unsigned char mp_extend : 2;
00334 unsigned char mp_copyright : 1;
00335 unsigned char mp_original : 1;
00336 unsigned char mp_emp : 2;
00337 #endif
00338 } mpeg_audio;
00339
00340 typedef struct {
00341 char tag_id[3];
00342 char tag_title[30];
00343 char tag_artist[30];
00344 char tag_album[30];
00345 char tag_year[4];
00346 char tag_note[30];
00347 unsigned char genre;
00348 } mpeg_tagv1;
00349
00350 #ifdef CCXX_PACKED
00351 #pragma pack()
00352 #endif
00353
00357 class __EXPORT Info
00358 {
00359 public:
00360 Format format;
00361 Encoding encoding;
00362 unsigned long rate;
00363 unsigned long bitrate;
00364 unsigned order;
00365 unsigned framesize, framecount, headersize, padding;
00366 timeout_t framing;
00367 char *annotation;
00368
00369 Info();
00370 void clear(void);
00371 void set(void);
00372 void setFraming(timeout_t frame);
00373 void setRate(Rate rate);
00374 };
00375
00382 static Level tolevel(float dbm);
00383
00390 static float todbm(Level power);
00391
00399 static bool hasDevice(unsigned device = 0);
00400
00411 static AudioDevice *getDevice(unsigned device = 0, DeviceMode mode = PLAY);
00412
00418 static const char *getCodecPath(void);
00419
00427 static const char *getMIME(Info &info);
00428
00436 static const char *getName(Encoding encoding);
00437
00445 static const char *getExtension(Encoding encoding);
00446
00457 static Encoding getEncoding(const char *name);
00458
00465 static Encoding getStereo(Encoding encoding);
00466
00473 static Encoding getMono(Encoding encoding);
00474
00481 static bool isLinear(Encoding encoding);
00482
00491 static bool isBuffered(Encoding encoding);
00492
00499 static bool isMono(Encoding encoding);
00500
00507 static bool isStereo(Encoding encoding);
00508
00516 static Rate getRate(Encoding encoding);
00517
00526 static Rate getRate(Encoding e, Rate request);
00527
00535 static timeout_t getFraming(Encoding encoding, timeout_t timeout = 0);
00536
00544 static timeout_t getFraming(Info &info, timeout_t timeout = 0);
00545
00553 static bool isEndian(Encoding encoding);
00554
00562 static bool isEndian(Info &info);
00563
00573 static bool swapEndian(Encoding encoding, void *buffer, unsigned number);
00574
00583 static void swapEncoded(Info &info, Encoded data, size_t bytes);
00584
00595 static bool swapEndian(Info &info, void *buffer, unsigned number);
00596
00605 static Level getImpulse(Encoding encoding, void *buffer, unsigned number);
00606
00615 static Level getImpulse(Info &info, void *buffer, unsigned number = 0);
00616
00626 static Level getPeak(Encoding encoding, void *buffer, unsigned number);
00627
00637 static Level getPeak(Info &info, void *buffer, unsigned number = 0);
00638
00646 static void toTimestamp(timeout_t duration, char *address, size_t size);
00647
00654 static timeout_t toTimeout(const char *timestamp);
00655
00678 static int getFrame(Encoding encoding, int samples = 0);
00679
00692 static int getCount(Encoding encoding);
00693
00702 static unsigned long toSamples(Encoding encoding, size_t bytes);
00703
00712 static unsigned long toSamples(Info &info, size_t bytes);
00713
00722 static size_t toBytes(Info &info, unsigned long number);
00723
00732 static size_t toBytes(Encoding encoding, unsigned long number);
00733
00742 static void fill(unsigned char *address, int number, Encoding encoding);
00743
00750 static bool loadPlugin(const char *path);
00751
00759 static size_t maxFramesize(Info &info);
00760 };
00761
00769 class __EXPORT AudioResample : public Audio
00770 {
00771 protected:
00772 unsigned mfact, dfact, max;
00773 unsigned gpos, ppos;
00774 Sample last;
00775 Linear buffer;
00776
00777 public:
00778 AudioResample(Rate mul, Rate div);
00779 ~AudioResample();
00780
00781 size_t process(Linear from, Linear to, size_t count);
00782 size_t estimate(size_t count);
00783 };
00784
00793 class __EXPORT AudioTone : public Audio
00794 {
00795 protected:
00796 Rate rate;
00797 unsigned samples;
00798 Linear frame;
00799 double df1, df2, p1, p2;
00800 Level m1, m2;
00801 bool silencer;
00802
00806 void silence(void);
00807
00811 void reset(void);
00812
00816 void cleanup(void);
00817
00824 void single(unsigned freq, Level level);
00825
00834 void dual(unsigned f1, unsigned f2, Level l1, Level l2);
00835
00836 public:
00842 inline Rate getRate(void)
00843 {return rate;};
00844
00850 inline size_t getSamples(void)
00851 {return samples;};
00852
00858 bool isSilent(void);
00859
00867 virtual Linear getFrame(void);
00868
00877 unsigned getFrames(Linear buffer, unsigned number);
00878
00885 virtual bool isComplete(void);
00886
00893 AudioTone(timeout_t duration = 20, Rate rate = rate8khz);
00894
00905 AudioTone(unsigned f1, unsigned f2, Level l1, Level l2,
00906 timeout_t duration = 20, Rate sample = rate8khz);
00907
00916 AudioTone(unsigned freq, Level level, timeout_t duration = 20, Rate sample = rate8khz);
00917
00918 virtual ~AudioTone();
00919 };
00920
00927 class __EXPORT AudioBase : public Audio
00928 {
00929 protected:
00930 Info info;
00931
00932 public:
00936 AudioBase();
00937
00943 AudioBase(Info *info);
00944
00948 virtual ~AudioBase();
00949
00955 inline Encoding getEncoding(void)
00956 {return info.encoding;};
00957
00963 inline unsigned getSampleRate(void)
00964 {return info.rate;};
00965
00973 virtual ssize_t putBuffer(Encoded data, size_t size) = 0;
00974
00983 ssize_t putNative(Encoded data, size_t size);
00984
00992 virtual ssize_t getBuffer(Encoded data, size_t size) = 0;
00993
01000 inline ssize_t getPacket(Encoded data)
01001 {return getBuffer(data, 0);};
01002
01010 ssize_t getNative(Encoded data, size_t size);
01011 };
01012
01020 class __EXPORT AudioBuffer : public AudioBase
01021 {
01022 public:
01023 AudioBuffer(Info *info, size_t size = 4096);
01024 virtual ~AudioBuffer();
01025
01033 ssize_t getBuffer(Encoded data, size_t number);
01034
01042 ssize_t putBuffer(Encoded data, size_t number);
01043
01044 private:
01045 char *buf;
01046 size_t size, start, len;
01047 void *mutexObject;
01048
01049 void enter(void);
01050 void leave(void);
01051 };
01052
01061 class __EXPORT AudioFile: public AudioBase
01062 {
01063 protected:
01064 char *pathname;
01065 Error error;
01066 unsigned long header;
01067 unsigned long minimum;
01068 unsigned long length;
01069
01070 void initialize(void);
01071 void getWaveFormat(int size);
01072 void mp3info(mpeg_audio *mp3);
01073
01074 union {
01075 int fd;
01076 void *handle;
01077 } file;
01078
01079 Mode mode;
01080 unsigned long iolimit;
01081
01082 virtual bool afCreate(const char *path, bool exclusive = false);
01083 virtual bool afOpen(const char *path, Mode m = modeWrite);
01084 virtual bool afPeek(unsigned char *data, unsigned size);
01085
01086 AudioCodec *getCodec(void);
01087
01100 virtual int afRead(unsigned char *data, unsigned size);
01101
01113 virtual int afWrite(unsigned char *data, unsigned size);
01114
01124 virtual bool afSeek(unsigned long pos);
01125
01129 virtual void afClose(void);
01130
01138 virtual char *getContinuation(void)
01139 {return NULL;};
01140
01149 const char * getErrorStr(Error err);
01150
01151 Error setError(Error err);
01152
01159 inline unsigned long getHeader(void)
01160 {return header;};
01161
01170 unsigned short getShort(unsigned char *data);
01171
01180 void setShort(unsigned char *data, unsigned short value);
01181
01190 unsigned long getLong(unsigned char *data);
01191
01200 void setLong(unsigned char *data, unsigned long value);
01201
01202 public:
01209 AudioFile(const char *name, unsigned long offset = 0);
01210
01218 AudioFile(const char *name, Info *info, unsigned long minimum = 0);
01219
01223 inline AudioFile()
01224 {initialize();};
01225
01226 virtual ~AudioFile();
01227
01238 void open(const char *name, Mode mode = modeWrite, timeout_t framing = 0);
01239
01250 void create(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01251
01258 time_t getAge(void);
01259
01265 inline size_t getSize(void)
01266 {return maxFramesize(info);};
01267
01273 void close(void);
01274
01282 void clear(void);
01283
01295 ssize_t getBuffer(Encoded buffer, size_t len = 0);
01296
01305 unsigned getLinear(Linear buffer, unsigned request = 0);
01306
01318 ssize_t putBuffer(Encoded buffer, size_t len = 0);
01319
01328 unsigned putLinear(Linear buffer, unsigned request = 0);
01329
01344 Error getSamples(void *buffer, unsigned samples = 0);
01345
01359 Error putSamples(void *buffer, unsigned samples = 0);
01360
01368 Error skip(long number);
01369
01377 Error setPosition(unsigned long samples = ~0l);
01378
01386 Error position(const char *timestamp);
01387
01394 void getPosition(char *timestamp, size_t size);
01395
01403 Error setLimit(unsigned long maximum = 0l);
01404
01412 Error getInfo(Info *info);
01413
01422 Error setMinimum(unsigned long minimum);
01423
01433 unsigned long getAbsolutePosition(void);
01434
01446 unsigned long getPosition(void);
01447
01453 virtual bool isOpen(void);
01454
01462 virtual bool hasPositioning(void)
01463 {return true;};
01464
01470 inline Encoding getEncoding(void)
01471 {return info.encoding;};
01472
01478 inline Format getFormat(void)
01479 {return info.format;};
01480
01487 inline unsigned getSampleRate(void)
01488 {return info.rate;};
01489
01495 inline char *getAnnotation(void)
01496 {return info.annotation;};
01497
01503 inline Error getError(void)
01504 {return error;};
01505
01506 inline bool operator!(void)
01507 {return (bool)!isOpen();};
01508
01514 bool isSigned(void);
01515 };
01516
01528 class __EXPORT AudioStream : public AudioFile
01529 {
01530 protected:
01531 AudioCodec *codec;
01532 Encoded framebuf;
01533 bool streamable;
01534 Linear bufferFrame;
01535 unsigned bufferPosition;
01536 unsigned bufferChannels;
01537 Linear encBuffer, decBuffer;
01538 unsigned encSize, decSize;
01539
01540 unsigned bufAudio(Linear samples, unsigned count, unsigned size);
01541
01542 public:
01546 AudioStream();
01547
01555 AudioStream(const char *name, Mode mode = modeRead, timeout_t framing = 0);
01556
01565 AudioStream(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01566
01567 virtual ~AudioStream();
01568
01576 ssize_t getBuffer(Encoded data, size_t count);
01577
01585 void open(const char *name, Mode mode = modeRead, timeout_t framing = 0);
01586
01595 void create(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01596
01600 void close(void);
01601
01605 void flush(void);
01606
01613 bool isStreamable(void);
01614
01618 unsigned getCount(void);
01619
01629 unsigned getEncoded(AudioCodec *codec, Encoded address, unsigned frames = 1);
01630
01640 unsigned putEncoded(AudioCodec *codec, Encoded address, unsigned frames = 1);
01641
01649 unsigned getEncoded(Encoded address, unsigned frames = 1);
01650
01658 unsigned putEncoded(Encoded address, unsigned frames = 1);
01659
01667 ssize_t getPacket(Encoded data);
01668
01677 unsigned getMono(Linear buffer, unsigned frames = 1);
01678
01687 unsigned getStereo(Linear buffer, unsigned frames = 1);
01688
01697 unsigned putMono(Linear buffer, unsigned frames = 1);
01698
01707 unsigned putStereo(Linear buffer, unsigned frames = 1);
01708
01718 unsigned bufMono(Linear buffer, unsigned count);
01719
01729 unsigned bufStereo(Linear buffer, unsigned count);
01730
01736 inline AudioCodec *getCodec(void)
01737 {return codec;};
01738 };
01739
01752 class __EXPORT AudioCodec : public Audio
01753 {
01754 protected:
01755 static AudioCodec *first;
01756 AudioCodec *next;
01757 Encoding encoding;
01758 const char *name;
01759 Info info;
01760
01761 AudioCodec();
01762
01770 virtual AudioCodec *getByFormat(const char *format)
01771 {return this;};
01772
01779 virtual AudioCodec *getByInfo(Info &info)
01780 {return this;};
01781
01782 public:
01789 AudioCodec(const char *name, Encoding encoding);
01790
01791 virtual ~AudioCodec() {};
01792
01799 static void endCodec(AudioCodec *codec);
01800
01810 static AudioCodec *getCodec(Encoding encoding, const char *format = NULL, bool loaded = false);
01811
01820 static AudioCodec *getCodec(Info &info, bool loaded = false);
01821
01828 static bool load(const char *name);
01829
01837 static bool load(Encoding encoding);
01838
01847 virtual Level getImpulse(void *buffer, unsigned number = 0);
01848
01856 virtual Level getPeak(void *buffer, unsigned number = 0);
01857
01868 virtual bool isSilent(Level threashold, void *buffer, unsigned number = 0);
01869
01878 virtual unsigned encode(Linear buffer, void *dest, unsigned number = 0) = 0;
01879
01888 virtual unsigned encodeBuffered(Linear Buffer, Encoded dest, unsigned number);
01889
01898 virtual unsigned decode(Linear buffer, void *source, unsigned number = 0) = 0;
01899
01909 virtual unsigned decodeBuffered(Linear buffer, Encoded source, unsigned len);
01910
01916 virtual unsigned getEstimated(void);
01917
01923 virtual unsigned getRequired(void);
01924
01934 virtual unsigned getPacket(Encoded destination, Encoded data, unsigned size);
01935
01941 inline Info getInfo(void)
01942 {return info;};
01943 };
01944
01945 class __EXPORT AudioDevice : public AudioBase
01946 {
01947 protected:
01948 bool enabled;
01949
01950 public:
01951 virtual ~AudioDevice() {};
01952
01960 virtual unsigned putSamples(Linear buffer, unsigned count) = 0;
01961
01969 virtual unsigned getSamples(Linear buffer, unsigned count) = 0;
01970
01979 virtual ssize_t putBuffer(Encoded data, size_t count);
01980
01989 virtual ssize_t getBuffer(Encoded data, size_t count);
01990
01998 virtual bool setEncoded(Info &info)
01999 {return false;};
02000
02009 virtual bool setAudio(Rate rate = rate8khz, bool stereo = false, timeout_t framing = 20) = 0;
02010
02017 virtual void sync(void)
02018 {return;};
02019
02023 virtual void flush(void) = 0;
02024
02034 unsigned bufMono(Linear buffer, unsigned count);
02035
02045 unsigned bufStereo(Linear buffer, unsigned count);
02046
02052 inline Info *getInfo(void)
02053 {return &info;};
02054
02063 inline bool isEnabled(void)
02064 {return enabled;};
02065 };
02066
02075 class __EXPORT TelTone : public AudioTone
02076 {
02077 public:
02078 typedef struct _tonedef {
02079 struct _tonedef *next;
02080 timeout_t duration, silence;
02081 unsigned count;
02082 unsigned short f1, f2;
02083 } tonedef_t;
02084
02085 typedef struct _tonekey {
02086 struct _tonekey *next;
02087 struct _tonedef *first;
02088 struct _tonedef *last;
02089 char id[1];
02090 } tonekey_t;
02091
02100 TelTone(tonekey_t *key, Level level, timeout_t frame = 20);
02101 ~TelTone();
02102
02109 Linear getFrame(void);
02110
02117 bool isComplete(void);
02118
02119
02127 static bool load(const char *pathname, const char *locale = NULL);
02128
02136 static tonekey_t *find(const char *tone, const char *locale = NULL);
02137
02138 protected:
02139 tonekey_t *tone;
02140 tonedef_t *def;
02141 unsigned remaining, silent, count;
02142 timeout_t framing;
02143 Level level;
02144 bool complete;
02145 };
02146
02156 class __EXPORT DTMFTones : public AudioTone
02157 {
02158 protected:
02159 unsigned remaining, dtmfframes;
02160 timeout_t frametime;
02161 const char *digits;
02162 Level level;
02163 bool complete;
02164
02165 public:
02174 DTMFTones(const char *digits, Level level, timeout_t duration = 20, timeout_t interdigit = 60);
02175
02176 ~DTMFTones();
02177
02178 Linear getFrame(void);
02179 bool isComplete(void);
02180 };
02181
02191 class __EXPORT MFTones : public AudioTone
02192 {
02193 protected:
02194 unsigned remaining, mfframes;
02195 timeout_t frametime;
02196 const char *digits;
02197 Level level;
02198 bool complete, kflag;
02199
02200 public:
02209 MFTones(const char *digits, Level level, timeout_t duration = 20, timeout_t interdigit = 60);
02210
02211 ~MFTones();
02212
02213 Linear getFrame(void);
02214 bool isComplete(void);
02215 };
02216
02217
02222 class __EXPORT DTMFDetect : public Audio
02223 {
02224 public:
02225 DTMFDetect();
02226 ~DTMFDetect();
02227
02236 int putSamples(Linear buffer, int count);
02237
02244 int getResult(char *data, int size);
02245
02246 protected:
02247 void goertzelInit(goertzel_state_t *s, tone_detection_descriptor_t *t);
02248 void goertzelUpdate(goertzel_state_t *s, Sample x[], int samples);
02249 float goertzelResult(goertzel_state_t *s);
02250
02251 private:
02252 dtmf_detect_state_t *state;
02253 tone_detection_descriptor_t dtmf_detect_row[4];
02254 tone_detection_descriptor_t dtmf_detect_col[4];
02255 tone_detection_descriptor_t dtmf_detect_row_2nd[4];
02256 tone_detection_descriptor_t dtmf_detect_col_2nd[4];
02257 tone_detection_descriptor_t fax_detect;
02258 tone_detection_descriptor_t fax_detect_2nd;
02259 };
02260
02261 }
02262
02263 #endif
02264