aboutsummaryrefslogtreecommitdiff
path: root/devel/pwlib/files/patch-src_ptclib_dtmf_cxx
blob: 828ee564e1d6d1c2b8e239df45d1ad353723a0e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--- src/ptclib/dtmf.cxx.old	2007-10-19 02:22:33.000000000 -0400
+++ src/ptclib/dtmf.cxx	2008-01-05 21:17:37.000000000 -0500
@@ -121,6 +121,64 @@
 }
 
 
+PString PDTMFDecoder::Decode(const void *buf, PINDEX bytes)
+{
+  int x;
+  int s, kk;
+  int c, d, f, n;
+  short *buffer = (short *)buf;
+
+  PINDEX numSamples = bytes >> 1;
+
+  PString keyString;
+
+  PINDEX pos;
+  for (pos = 0; pos < numSamples; pos++) {
+
+    /* Read (and scale) the next 16 bit sample */
+    x = ((int)(*buffer++)) / (32768/FSC);
+
+    /* Input amplitude */
+    if (x > 0)
+      ia += (x - ia) / 128;
+    else
+      ia += (-x - ia) / 128;
+
+    /* For each tone */
+    s = 0;
+    for(kk = 0; kk < 8; kk++) {
+
+      /* Turn the crank */
+      c = (P2 * (x - k[kk])) / FSC;
+      d = x + c;
+      f = (p1[kk] * (d - h[kk])) / FSC;
+      n = x - k[kk] - c;
+      k[kk] = h[kk] + f;
+      h[kk] = f + d;
+
+      /* Detect and Average */
+      if (n > 0)
+        y[kk] += (n - y[kk]) / 64;
+      else
+        y[kk] += (-n - y[kk]) / 64;
+
+      /* Threshold */
+      if (y[kk] > FSC/10 && y[kk] > ia)
+        s |= 1 << kk;
+    }
+
+    /* Hysteresis and noise supressor */
+    if (s != so) {
+      nn = 0;
+      so = s;
+    } else if (nn++ == 520 && s < 256 && key[s] != '?') {
+      PTRACE(3,"DTMF\tDetected '" << key[s] << "' in PCM-16 stream");
+      keyString += key[s];
+    }
+  }
+  return keyString;
+}
+
 PString PDTMFDecoder::Decode(const short * sampleData, PINDEX numSamples)
 {
   int x;