Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

dtmf.h

Go to the documentation of this file.
00001 /*
00002  * ----------------------------------------------------------------------------
00003  * "THE BEER-WARE LICENSE" (Revision 42):
00004  * <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
00005  * can do whatever you want with this stuff. If we meet some day, and you think
00006  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
00007  * ----------------------------------------------------------------------------
00008  *
00009  * Extract DTMF signals from 16 bit PCM audio
00010  *
00011  * Originally written by Poul-Henning Kamp <phk@freebsd.org>
00012  * Made into a C++ class by Roger Hardiman <roger@freebsd.org>, January 2002
00013  *
00014  * $Log: dtmf.h,v $
00015  * Revision 1.6  2004/11/11 07:34:50  csoutheren
00016  * Added #include <ptlib.h>
00017  *
00018  * Revision 1.5  2004/09/09 23:50:48  csoutheren
00019  * Fixed problem with duplicate definition of sinetab causing problems
00020  *
00021  * Revision 1.4  2004/09/09 05:23:37  dereksmithies
00022  * Add utility function to report on dtmf characters used.
00023  *
00024  * Revision 1.3  2004/09/09 04:00:00  csoutheren
00025  * Added DTMF encoding functions
00026  *
00027  * Revision 1.2  2002/09/16 01:08:59  robertj
00028  * Added #define so can select if #pragma interface/implementation is used on
00029  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00030  *
00031  * Revision 1.1  2002/01/23 11:43:26  rogerh
00032  * Add DTMF Decoder class. This can be passed PCM audio data
00033  * (at 16 bit, 8 KHz) and returns any DTMF codes detected.
00034  * Tested with NetMeeting sending DTMF over a G.711 stream.
00035  *
00036  */
00037  
00038 #ifndef _DTMF_H
00039 #define _DTMF_H
00040 
00041 #ifdef P_USE_PRAGMA
00042 #pragma interface
00043 #endif
00044 
00045 #include <ptlib.h>
00046 
00047 class PDTMFDecoder : public PObject
00048 {
00049   PCLASSINFO(PDTMFDecoder, PObject)
00050 
00051   public:
00052     PDTMFDecoder();
00053     PString Decode(const void *buf, PINDEX bytes);
00054 
00055   protected:
00056     // key lookup table (initialised once)
00057     char key[256];
00058 
00059     // frequency table (initialised once)
00060     int p1[8];
00061 
00062     // variables to be retained on each cycle of the decode function
00063     int h[8], k[8], y[8];
00064     int nn, so, ia;
00065 };
00066 
00072 class PDTMFEncoder : public PBYTEArray
00073 {
00074   PCLASSINFO(PDTMFEncoder, PBYTEArray)
00075 
00076   public:
00077     enum { DefaultToneLen = 100 };
00078 
00082     inline PDTMFEncoder(const char * dtmf = NULL, unsigned len = DefaultToneLen)
00083     { if (dtmf != NULL) AddTone(dtmf, len); }
00084 
00085 
00089     void AddTone(char ch, unsigned len = DefaultToneLen);
00090 
00094     void AddTone(const PString & str, unsigned len = DefaultToneLen);
00095 
00100     void AddTone(double freq1, double freq2 = 0, unsigned len = DefaultToneLen);
00101 
00106     void GenerateRingBackTone()
00107     {
00108       AddTone(440, 480, 2000);
00109       AddTone(0,   0,   4000);
00110     }
00111 
00116     void GenerateDialTone()
00117     {
00118       AddTone(350, 440, 1000);
00119     }
00120 
00125     void GenerateBusyTone()
00126     {
00127       AddTone(480, 620, 500);
00128       AddTone(0,   0,   500);
00129     }
00130 
00136     char DtmfChar(PINDEX i);
00137 
00138   protected:
00139     static PMutex & GetMutex();
00140     static BOOL sineTabInit;
00141     static void MakeSineTable();
00142     static inline double sine(unsigned int ptr)
00143     { return sinetab[ptr >> (32-11)]; }
00144     static double sinetab[1 << 11];
00145 };
00146 
00147 #endif /* _DTMF_H */

Generated on Sat Dec 22 16:46:50 2007 for PWLib by  doxygen 1.4.2