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 rate32khz = 32000,
00177 rate44khz = 44100
00178 };
00179
00180 typedef enum Rate Rate;
00181
00185 enum Mode
00186 {
00187 modeRead,
00188 modeReadAny,
00189 modeReadOne,
00190 modeWrite,
00191 modeCache,
00192 modeInfo,
00193 modeFeed,
00194
00195 modeAppend,
00196 modeCreate
00197 };
00198
00199 typedef enum Mode Mode;
00200
00204 enum Encoding
00205 {
00206 unknownEncoding = 0,
00207 g721ADPCM,
00208 g722Audio,
00209 g722_7bit,
00210 g722_6bit,
00211 g723_2bit,
00212 g723_3bit,
00213 g723_5bit,
00214 gsmVoice,
00215 msgsmVoice,
00216 mulawAudio,
00217 alawAudio,
00218 mp1Audio,
00219 mp2Audio,
00220 mp3Audio,
00221 okiADPCM,
00222 voxADPCM,
00223 sx73Voice,
00224 sx96Voice,
00225
00226
00227
00228
00229 cdaStereo,
00230 cdaMono,
00231 pcm8Stereo,
00232 pcm8Mono,
00233 pcm16Stereo,
00234 pcm16Mono,
00235 pcm32Stereo,
00236 pcm32Mono,
00237
00238
00239 speexVoice,
00240 speexAudio,
00241
00242 g729Audio,
00243 ilbcAudio,
00244 speexUltra,
00245
00246 speexNarrow = speexVoice,
00247 speexWide = speexAudio,
00248 g723_4bit = g721ADPCM
00249 };
00250 typedef enum Encoding Encoding;
00251
00255 enum Format
00256 {
00257 raw,
00258 snd,
00259 riff,
00260 mpeg,
00261 wave
00262 };
00263 typedef enum Format Format;
00264
00268 enum DeviceMode
00269 {
00270 PLAY,
00271 RECORD,
00272 PLAYREC
00273 };
00274 typedef enum DeviceMode DeviceMode;
00275
00279 enum Error
00280 {
00281 errSuccess = 0,
00282 errReadLast,
00283 errNotOpened,
00284 errEndOfFile,
00285 errStartOfFile,
00286 errRateInvalid,
00287 errEncodingInvalid,
00288 errReadInterrupt,
00289 errWriteInterrupt,
00290 errReadFailure,
00291 errWriteFailure,
00292 errReadIncomplete,
00293 errWriteIncomplete,
00294 errRequestInvalid,
00295 errTOCFailed,
00296 errStatFailed,
00297 errInvalidTrack,
00298 errPlaybackFailed,
00299 errNotPlaying,
00300 errNoCodec
00301 };
00302 typedef enum Error Error;
00303
00304
00305 #ifdef CCXX_PACKED
00306 #pragma pack(1)
00307 #endif
00308
00309 typedef struct
00310 {
00311 #if __BYTE_ORDER == __LITTLE_ENDIAN
00312 unsigned char mp_sync1 : 8;
00313 unsigned char mp_crc : 1;
00314 unsigned char mp_layer : 2;
00315 unsigned char mp_ver : 2;
00316 unsigned char mp_sync2 : 3;
00317
00318 unsigned char mp_priv : 1;
00319 unsigned char mp_pad : 1;
00320 unsigned char mp_srate : 2;
00321 unsigned char mp_brate : 4;
00322
00323 unsigned char mp_emp : 2;
00324 unsigned char mp_original : 1;
00325 unsigned char mp_copyright: 1;
00326 unsigned char mp_extend : 2;
00327 unsigned char mp_channels : 2;
00328
00329 #else
00330 unsigned char mp_sync1 : 8;
00331
00332 unsigned char mp_sync2 : 3;
00333 unsigned char mp_ver : 2;
00334 unsigned char mp_layer : 2;
00335 unsigned char mp_crc : 1;
00336
00337 unsigned char mp_brate : 4;
00338 unsigned char mp_srate : 2;
00339 unsigned char mp_pad : 1;
00340 unsigned char mp_priv : 1;
00341
00342 unsigned char mp_channels : 2;
00343 unsigned char mp_extend : 2;
00344 unsigned char mp_copyright : 1;
00345 unsigned char mp_original : 1;
00346 unsigned char mp_emp : 2;
00347 #endif
00348 } mpeg_audio;
00349
00350 typedef struct
00351 {
00352 char tag_id[3];
00353 char tag_title[30];
00354 char tag_artist[30];
00355 char tag_album[30];
00356 char tag_year[4];
00357 char tag_note[30];
00358 unsigned char genre;
00359 } mpeg_tagv1;
00360
00361 #ifdef CCXX_PACKED
00362 #pragma pack()
00363 #endif
00364
00368 class __EXPORT Info
00369 {
00370 public:
00371 Format format;
00372 Encoding encoding;
00373 unsigned long rate;
00374 unsigned long bitrate;
00375 unsigned order;
00376 unsigned framesize, framecount, headersize, padding;
00377 timeout_t framing;
00378 char *annotation;
00379
00380 Info();
00381 void clear(void);
00382 void set(void);
00383 void setFraming(timeout_t frame);
00384 void setRate(Rate rate);
00385 };
00386
00393 static Level tolevel(float dbm);
00394
00401 static float todbm(Level power);
00402
00410 static bool hasDevice(unsigned device = 0);
00411
00422 static AudioDevice *getDevice(unsigned device = 0, DeviceMode mode = PLAY);
00423
00429 static const char *getCodecPath(void);
00430
00438 static const char *getMIME(Info &info);
00439
00447 static const char *getName(Encoding encoding);
00448
00456 static const char *getExtension(Encoding encoding);
00457
00468 static Encoding getEncoding(const char *name);
00469
00476 static Encoding getStereo(Encoding encoding);
00477
00484 static Encoding getMono(Encoding encoding);
00485
00492 static bool isLinear(Encoding encoding);
00493
00502 static bool isBuffered(Encoding encoding);
00503
00510 static bool isMono(Encoding encoding);
00511
00518 static bool isStereo(Encoding encoding);
00519
00527 static Rate getRate(Encoding encoding);
00528
00537 static Rate getRate(Encoding e, Rate request);
00538
00546 static timeout_t getFraming(Encoding encoding, timeout_t timeout = 0);
00547
00555 static timeout_t getFraming(Info &info, timeout_t timeout = 0);
00556
00564 static bool isEndian(Encoding encoding);
00565
00573 static bool isEndian(Info &info);
00574
00584 static bool swapEndian(Encoding encoding, void *buffer, unsigned number);
00585
00594 static void swapEncoded(Info &info, Encoded data, size_t bytes);
00595
00606 static bool swapEndian(Info &info, void *buffer, unsigned number);
00607
00616 static Level getImpulse(Encoding encoding, void *buffer, unsigned number);
00617
00626 static Level getImpulse(Info &info, void *buffer, unsigned number = 0);
00627
00637 static Level getPeak(Encoding encoding, void *buffer, unsigned number);
00638
00648 static Level getPeak(Info &info, void *buffer, unsigned number = 0);
00649
00657 static void toTimestamp(timeout_t duration, char *address, size_t size);
00658
00665 static timeout_t toTimeout(const char *timestamp);
00666
00689 static int getFrame(Encoding encoding, int samples = 0);
00690
00703 static int getCount(Encoding encoding);
00704
00713 static unsigned long toSamples(Encoding encoding, size_t bytes);
00714
00723 static unsigned long toSamples(Info &info, size_t bytes);
00724
00733 static size_t toBytes(Info &info, unsigned long number);
00734
00743 static size_t toBytes(Encoding encoding, unsigned long number);
00744
00753 static void fill(unsigned char *address, int number, Encoding encoding);
00754
00761 static bool loadPlugin(const char *path);
00762
00770 static size_t maxFramesize(Info &info);
00771 };
00772
00780 class __EXPORT AudioResample : public Audio
00781 {
00782 protected:
00783 unsigned mfact, dfact, max;
00784 unsigned gpos, ppos;
00785 Sample last;
00786 Linear buffer;
00787
00788 public:
00789 AudioResample(Rate mul, Rate div);
00790 ~AudioResample();
00791
00792 size_t process(Linear from, Linear to, size_t count);
00793 size_t estimate(size_t count);
00794 };
00795
00804 class __EXPORT AudioTone : public Audio
00805 {
00806 protected:
00807 Rate rate;
00808 unsigned samples;
00809 Linear frame;
00810 double df1, df2, p1, p2;
00811 Level m1, m2;
00812 bool silencer;
00813
00817 void silence(void);
00818
00822 void reset(void);
00823
00827 void cleanup(void);
00828
00835 void single(unsigned freq, Level level);
00836
00845 void dual(unsigned f1, unsigned f2, Level l1, Level l2);
00846
00847 public:
00853 inline Rate getRate(void)
00854 {return rate;};
00855
00861 inline size_t getSamples(void)
00862 {return samples;};
00863
00869 bool isSilent(void);
00870
00878 virtual Linear getFrame(void);
00879
00888 unsigned getFrames(Linear buffer, unsigned number);
00889
00896 virtual bool isComplete(void);
00897
00904 AudioTone(timeout_t duration = 20, Rate rate = rate8khz);
00905
00916 AudioTone(unsigned f1, unsigned f2, Level l1, Level l2,
00917 timeout_t duration = 20, Rate sample = rate8khz);
00918
00927 AudioTone(unsigned freq, Level level, timeout_t duration = 20, Rate sample = rate8khz);
00928
00929 virtual ~AudioTone();
00930 };
00931
00938 class __EXPORT AudioBase : public Audio
00939 {
00940 protected:
00941 Info info;
00942
00943 public:
00947 AudioBase();
00948
00954 AudioBase(Info *info);
00955
00959 virtual ~AudioBase();
00960
00966 inline Encoding getEncoding(void)
00967 {return info.encoding;};
00968
00974 inline unsigned getSampleRate(void)
00975 {return info.rate;};
00976
00984 virtual ssize_t putBuffer(Encoded data, size_t size) = 0;
00985
00994 ssize_t putNative(Encoded data, size_t size);
00995
01003 virtual ssize_t getBuffer(Encoded data, size_t size) = 0;
01004
01011 inline ssize_t getPacket(Encoded data)
01012 {return getBuffer(data, 0);};
01013
01021 ssize_t getNative(Encoded data, size_t size);
01022 };
01023
01031 class __EXPORT AudioBuffer : public AudioBase
01032 {
01033 public:
01034 AudioBuffer(Info *info, size_t size = 4096);
01035 virtual ~AudioBuffer();
01036
01044 ssize_t getBuffer(Encoded data, size_t number);
01045
01053 ssize_t putBuffer(Encoded data, size_t number);
01054
01055 private:
01056 char *buf;
01057 size_t size, start, len;
01058 void *mutexObject;
01059
01060 void enter(void);
01061 void leave(void);
01062 };
01063
01072 class __EXPORT AudioFile: public AudioBase
01073 {
01074 protected:
01075 char *pathname;
01076 Error error;
01077 unsigned long header;
01078 unsigned long minimum;
01079 unsigned long length;
01080
01081 void initialize(void);
01082 void getWaveFormat(int size);
01083 void mp3info(mpeg_audio *mp3);
01084
01085 union
01086 {
01087 int fd;
01088 void *handle;
01089 } file;
01090
01091 Mode mode;
01092 unsigned long iolimit;
01093
01094 virtual bool afCreate(const char *path, bool exclusive = false);
01095 virtual bool afOpen(const char *path, Mode m = modeWrite);
01096 virtual bool afPeek(unsigned char *data, unsigned size);
01097
01098 AudioCodec *getCodec(void);
01099
01112 virtual int afRead(unsigned char *data, unsigned size);
01113
01125 virtual int afWrite(unsigned char *data, unsigned size);
01126
01136 virtual bool afSeek(unsigned long pos);
01137
01141 virtual void afClose(void);
01142
01150 virtual char *getContinuation(void)
01151 {return NULL;};
01152
01161 const char * getErrorStr(Error err);
01162
01163 Error setError(Error err);
01164
01171 inline unsigned long getHeader(void)
01172 {return header;};
01173
01182 unsigned short getShort(unsigned char *data);
01183
01192 void setShort(unsigned char *data, unsigned short value);
01193
01202 unsigned long getLong(unsigned char *data);
01203
01212 void setLong(unsigned char *data, unsigned long value);
01213
01214 public:
01221 AudioFile(const char *name, unsigned long offset = 0);
01222
01230 AudioFile(const char *name, Info *info, unsigned long minimum = 0);
01231
01235 inline AudioFile()
01236 {initialize();};
01237
01238 virtual ~AudioFile();
01239
01250 void open(const char *name, Mode mode = modeWrite, timeout_t framing = 0);
01251
01262 void create(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01263
01270 time_t getAge(void);
01271
01277 inline size_t getSize(void)
01278 {return maxFramesize(info);};
01279
01285 void close(void);
01286
01294 void clear(void);
01295
01307 ssize_t getBuffer(Encoded buffer, size_t len = 0);
01308
01317 unsigned getLinear(Linear buffer, unsigned request = 0);
01318
01330 ssize_t putBuffer(Encoded buffer, size_t len = 0);
01331
01340 unsigned putLinear(Linear buffer, unsigned request = 0);
01341
01356 Error getSamples(void *buffer, unsigned samples = 0);
01357
01371 Error putSamples(void *buffer, unsigned samples = 0);
01372
01380 Error skip(long number);
01381
01389 Error setPosition(unsigned long samples = ~0l);
01390
01398 Error position(const char *timestamp);
01399
01406 void getPosition(char *timestamp, size_t size);
01407
01415 Error setLimit(unsigned long maximum = 0l);
01416
01424 Error getInfo(Info *info);
01425
01434 Error setMinimum(unsigned long minimum);
01435
01445 unsigned long getAbsolutePosition(void);
01446
01458 unsigned long getPosition(void);
01459
01465 virtual bool isOpen(void);
01466
01474 virtual bool hasPositioning(void)
01475 {return true;};
01476
01482 inline Encoding getEncoding(void)
01483 {return info.encoding;};
01484
01490 inline Format getFormat(void)
01491 {return info.format;};
01492
01499 inline unsigned getSampleRate(void)
01500 {return info.rate;};
01501
01507 inline char *getAnnotation(void)
01508 {return info.annotation;};
01509
01515 inline Error getError(void)
01516 {return error;};
01517
01518 inline bool operator!(void)
01519 {return (bool)!isOpen();};
01520
01526 bool isSigned(void);
01527 };
01528
01540 class __EXPORT AudioStream : public AudioFile
01541 {
01542 protected:
01543 AudioCodec *codec;
01544 Encoded framebuf;
01545 bool streamable;
01546 Linear bufferFrame;
01547 unsigned bufferPosition;
01548 unsigned bufferChannels;
01549 Linear encBuffer, decBuffer;
01550 unsigned encSize, decSize;
01551
01552 unsigned bufAudio(Linear samples, unsigned count, unsigned size);
01553
01554 public:
01558 AudioStream();
01559
01567 AudioStream(const char *name, Mode mode = modeRead, timeout_t framing = 0);
01568
01577 AudioStream(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01578
01579 virtual ~AudioStream();
01580
01588 ssize_t getBuffer(Encoded data, size_t count);
01589
01597 void open(const char *name, Mode mode = modeRead, timeout_t framing = 0);
01598
01607 void create(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
01608
01612 void close(void);
01613
01617 void flush(void);
01618
01625 bool isStreamable(void);
01626
01630 unsigned getCount(void);
01631
01641 unsigned getEncoded(AudioCodec *codec, Encoded address, unsigned frames = 1);
01642
01652 unsigned putEncoded(AudioCodec *codec, Encoded address, unsigned frames = 1);
01653
01661 unsigned getEncoded(Encoded address, unsigned frames = 1);
01662
01670 unsigned putEncoded(Encoded address, unsigned frames = 1);
01671
01679 ssize_t getPacket(Encoded data);
01680
01689 unsigned getMono(Linear buffer, unsigned frames = 1);
01690
01699 unsigned getStereo(Linear buffer, unsigned frames = 1);
01700
01709 unsigned putMono(Linear buffer, unsigned frames = 1);
01710
01719 unsigned putStereo(Linear buffer, unsigned frames = 1);
01720
01730 unsigned bufMono(Linear buffer, unsigned count);
01731
01741 unsigned bufStereo(Linear buffer, unsigned count);
01742
01748 inline AudioCodec *getCodec(void)
01749 {return codec;};
01750 };
01751
01764 class __EXPORT AudioCodec : public Audio
01765 {
01766 protected:
01767 static AudioCodec *first;
01768 AudioCodec *next;
01769 Encoding encoding;
01770 const char *name;
01771 Info info;
01772
01773 AudioCodec();
01774
01782 virtual AudioCodec *getByFormat(const char *format)
01783 {return this;};
01784
01791 virtual AudioCodec *getByInfo(Info &info)
01792 {return this;};
01793
01794 public:
01801 AudioCodec(const char *name, Encoding encoding);
01802
01803 virtual ~AudioCodec() {};
01804
01811 static void endCodec(AudioCodec *codec);
01812
01822 static AudioCodec *getCodec(Encoding encoding, const char *format = NULL, bool loaded = false);
01823
01832 static AudioCodec *getCodec(Info &info, bool loaded = false);
01833
01840 static bool load(const char *name);
01841
01849 static bool load(Encoding encoding);
01850
01859 virtual Level getImpulse(void *buffer, unsigned number = 0);
01860
01868 virtual Level getPeak(void *buffer, unsigned number = 0);
01869
01880 virtual bool isSilent(Level threashold, void *buffer, unsigned number = 0);
01881
01890 virtual unsigned encode(Linear buffer, void *dest, unsigned number = 0) = 0;
01891
01900 virtual unsigned encodeBuffered(Linear Buffer, Encoded dest, unsigned number);
01901
01910 virtual unsigned decode(Linear buffer, void *source, unsigned number = 0) = 0;
01911
01921 virtual unsigned decodeBuffered(Linear buffer, Encoded source, unsigned len);
01922
01928 virtual unsigned getEstimated(void);
01929
01935 virtual unsigned getRequired(void);
01936
01946 virtual unsigned getPacket(Encoded destination, Encoded data, unsigned size);
01947
01953 inline Info getInfo(void)
01954 {return info;};
01955 };
01956
01957 class __EXPORT AudioDevice : public AudioBase
01958 {
01959 protected:
01960 bool enabled;
01961
01962 public:
01963 virtual ~AudioDevice() {};
01964
01972 virtual unsigned putSamples(Linear buffer, unsigned count) = 0;
01973
01981 virtual unsigned getSamples(Linear buffer, unsigned count) = 0;
01982
01991 virtual ssize_t putBuffer(Encoded data, size_t count);
01992
02001 virtual ssize_t getBuffer(Encoded data, size_t count);
02002
02010 virtual bool setEncoded(Info &info)
02011 {return false;};
02012
02021 virtual bool setAudio(Rate rate = rate8khz, bool stereo = false, timeout_t framing = 20) = 0;
02022
02029 virtual void sync(void)
02030 {return;};
02031
02035 virtual void flush(void) = 0;
02036
02046 unsigned bufMono(Linear buffer, unsigned count);
02047
02057 unsigned bufStereo(Linear buffer, unsigned count);
02058
02064 inline Info *getInfo(void)
02065 {return &info;};
02066
02075 inline bool isEnabled(void)
02076 {return enabled;};
02077 };
02078
02087 class __EXPORT TelTone : public AudioTone
02088 {
02089 public:
02090 typedef struct _tonedef
02091 {
02092 struct _tonedef *next;
02093 timeout_t duration, silence;
02094 unsigned count;
02095 unsigned short f1, f2;
02096 } tonedef_t;
02097
02098 typedef struct _tonekey
02099 {
02100 struct _tonekey *next;
02101 struct _tonedef *first;
02102 struct _tonedef *last;
02103 char id[1];
02104 } tonekey_t;
02105
02114 TelTone(tonekey_t *key, Level level, timeout_t frame = 20);
02115 ~TelTone();
02116
02123 Linear getFrame(void);
02124
02131 bool isComplete(void);
02132
02133
02141 static bool load(const char *pathname, const char *locale = NULL);
02142
02150 static tonekey_t *find(const char *tone, const char *locale = NULL);
02151
02152 protected:
02153 tonekey_t *tone;
02154 tonedef_t *def;
02155 unsigned remaining, silent, count;
02156 timeout_t framing;
02157 Level level;
02158 bool complete;
02159 };
02160
02170 class __EXPORT DTMFTones : public AudioTone
02171 {
02172 protected:
02173 unsigned remaining, dtmfframes;
02174 timeout_t frametime;
02175 const char *digits;
02176 Level level;
02177 bool complete;
02178
02179 public:
02188 DTMFTones(const char *digits, Level level, timeout_t duration = 20, timeout_t interdigit = 60);
02189
02190 ~DTMFTones();
02191
02192 Linear getFrame(void);
02193 bool isComplete(void);
02194 };
02195
02205 class __EXPORT MFTones : public AudioTone
02206 {
02207 protected:
02208 unsigned remaining, mfframes;
02209 timeout_t frametime;
02210 const char *digits;
02211 Level level;
02212 bool complete, kflag;
02213
02214 public:
02223 MFTones(const char *digits, Level level, timeout_t duration = 20, timeout_t interdigit = 60);
02224
02225 ~MFTones();
02226
02227 Linear getFrame(void);
02228 bool isComplete(void);
02229 };
02230
02231
02236 class __EXPORT DTMFDetect : public Audio
02237 {
02238 public:
02239 DTMFDetect();
02240 ~DTMFDetect();
02241
02250 int putSamples(Linear buffer, int count);
02251
02258 int getResult(char *data, int size);
02259
02260 protected:
02261 void goertzelInit(goertzel_state_t *s, tone_detection_descriptor_t *t);
02262 void goertzelUpdate(goertzel_state_t *s, Sample x[], int samples);
02263 float goertzelResult(goertzel_state_t *s);
02264
02265 private:
02266 dtmf_detect_state_t *state;
02267 tone_detection_descriptor_t dtmf_detect_row[4];
02268 tone_detection_descriptor_t dtmf_detect_col[4];
02269 tone_detection_descriptor_t dtmf_detect_row_2nd[4];
02270 tone_detection_descriptor_t dtmf_detect_col_2nd[4];
02271 tone_detection_descriptor_t fax_detect;
02272 tone_detection_descriptor_t fax_detect_2nd;
02273 };
02274
02275 }
02276
02277 #endif
02278