mirror of
https://git.freebsd.org/ports.git
synced 2025-06-07 05:40:30 -04:00
67 lines
1.5 KiB
Text
67 lines
1.5 KiB
Text
--- 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;
|