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
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifndef _DTMF_H
00055 #define _DTMF_H
00056
00057 #ifdef P_USE_PRAGMA
00058 #pragma interface
00059 #endif
00060
00061 #ifndef _PTLIB_H
00062 #include <ptlib.h>
00063 #endif
00064
00065 class PDTMFDecoder : public PObject
00066 {
00067 PCLASSINFO(PDTMFDecoder, PObject)
00068
00069 public:
00070 PDTMFDecoder();
00071 PString Decode(const short * sampleData, PINDEX numSamples);
00072
00073 protected:
00074 enum {
00075 NumTones = 9
00076 };
00077
00078
00079 char key[256];
00080
00081
00082 int p1[NumTones];
00083
00084
00085 int h[NumTones], k[NumTones], y[NumTones];
00086 int nn, so, ia;
00087 };
00088
00089
00133 class PTones : public PShortArray
00134 {
00135 PCLASSINFO(PTones, PShortArray)
00136
00137 public:
00138 enum {
00139 MaxVolume = 100,
00140 SampleRate = 8000,
00141 MaxFrequency = (SampleRate/4),
00142 MinFrequency = 30,
00143 MinModulation = 5,
00144 SineScale = 1000
00145 };
00146
00150 PTones(
00151 unsigned masterVolume = MaxVolume
00152 );
00153
00156 PTones(
00157 const PString & descriptor,
00158 unsigned masterVolume = MaxVolume
00159 );
00160
00164 bool Generate(
00165 const PString & descriptor
00166 );
00167
00174 bool Generate(
00175 char operation,
00176 unsigned frequency1,
00177 unsigned frequency2,
00178 unsigned milliseconds,
00179 unsigned volume = MaxVolume
00180 );
00181
00182 protected:
00183 bool Juxtapose(unsigned frequency1, unsigned frequency2, unsigned milliseconds, unsigned volume);
00184 bool Modulate (unsigned frequency, unsigned modulate, unsigned milliseconds, unsigned volume);
00185 bool PureTone (unsigned frequency, unsigned milliseconds, unsigned volume);
00186 bool Silence (unsigned milliseconds);
00187
00188 unsigned CalcSamples(unsigned milliseconds, unsigned frequency1, unsigned frequency2 = 0);
00189
00190 void AddSample(int sample, unsigned volume);
00191
00192 unsigned masterVolume;
00193 char lastOperation;
00194 unsigned lastFrequency1, lastFrequency2;
00195 int angle1, angle2;
00196 };
00197
00198
00203 class PDTMFEncoder : public PTones
00204 {
00205 PCLASSINFO(PDTMFEncoder, PTones)
00206
00207 public:
00208 enum { DefaultToneLen = 100 };
00209
00213 PDTMFEncoder(
00214 const char * dtmf = NULL,
00215 unsigned milliseconds = DefaultToneLen
00216 );
00217
00221 PDTMFEncoder(
00222 char key,
00223 unsigned milliseconds = DefaultToneLen
00224 );
00225
00229 void AddTone(
00230 const char * str,
00231 unsigned milliseconds = DefaultToneLen
00232 );
00233
00237 void AddTone(
00238 char ch,
00239 unsigned milliseconds = DefaultToneLen
00240 );
00241
00246 void AddTone(
00247 double frequency1,
00248 double frequency2 = 0,
00249 unsigned milliseconds = DefaultToneLen
00250 );
00251
00256 void GenerateRingBackTone()
00257 {
00258 Generate("440+480:2-4");
00259 }
00260
00265 void GenerateDialTone()
00266 {
00267 Generate("350+440:1");
00268 }
00269
00274 void GenerateBusyTone()
00275 {
00276 Generate("480+620:0.5-0.5");
00277 }
00278
00286 char DtmfChar(
00287 PINDEX i
00288 );
00289
00290 };
00291
00292 #endif