notes and code for my payphone project
1# initially adapted from https://github.com/saizai/wumpusphone/blob/master/asterisk-1.8.0.patch#L251
2# less invastive version from https://github.com/hharte/1dcoinctrl/blob/master/asterisk/main/dsp.c-patch
3# updated for asterisk 20.2.0
4
5--- main/dsp.c.orig Mon Apr 10 11:39:45 2023
6+++ main/dsp.c Mon Apr 10 11:43:18 2023
7@@ -165,7 +165,7 @@
8
9 #define MAX_DTMF_DIGITS 128
10
11-#define DTMF_MATRIX_SIZE 4
12+#define DTMF_MATRIX_SIZE 5
13
14 /* Basic DTMF (AT&T) specs:
15 *
16@@ -317,15 +317,15 @@
17 } digit_detect_state_t;
18
19 static const float dtmf_row[] = {
20- 697.0, 770.0, 852.0, 941.0
21+ 697.0, 770.0, 852.0, 941.0, 1700.0,
22 };
23 static const float dtmf_col[] = {
24- 1209.0, 1336.0, 1477.0, 1633.0
25+ 1209.0, 1336.0, 1477.0, 1633.0, 2200.0,
26 };
27 static const float mf_tones[] = {
28 700.0, 900.0, 1100.0, 1300.0, 1500.0, 1700.0
29 };
30-static const char dtmf_positions[] = "123A" "456B" "789C" "*0#D";
31+static const char dtmf_positions[] = "123A-" "456B-" "789C-" "*0#D-" "----$";
32 static const char bell_mf_positions[] = "1247C-358A--69*---0B----#";
33 static int thresholds[THRESHOLD_MAX];
34 static float dtmf_normal_twist; /* AT&T = 8dB */
35@@ -734,6 +734,8 @@
36 goertzel_sample(s->td.dtmf.col_out + 2, samp);
37 goertzel_sample(s->td.dtmf.row_out + 3, samp);
38 goertzel_sample(s->td.dtmf.col_out + 3, samp);
39+ goertzel_sample(s->td.dtmf.row_out + 4, samp);
40+ goertzel_sample(s->td.dtmf.col_out + 4, samp);
41 /* go up to DTMF_MATRIX_SIZE - 1 */
42 }
43 s->td.dtmf.current_sample += (limit - sample);
44@@ -776,9 +778,9 @@
45 }
46 /* ... and fraction of total energy test */
47 if (i >= DTMF_MATRIX_SIZE &&
48- (row_energy[best_row] + col_energy[best_col]) > DTMF_TO_TOTAL_ENERGY * s->td.dtmf.energy) {
49+ (row_energy[best_row] + col_energy[best_col]) > (DTMF_TO_TOTAL_ENERGY / (relax ? 2 : 1)) * s->td.dtmf.energy) {
50 /* Got a hit */
51- hit = dtmf_positions[(best_row << 2) + best_col];
52+ hit = dtmf_positions[(best_row * DTMF_MATRIX_SIZE) + best_col];
53 ast_debug(10, "DTMF hit '%c'\n", hit);
54 }
55 }