/* originally from http://www.repairfaq.org/filipg/LINK/F_DTMF.html */ /* changed by Chris Williams */ #include #include #include "telephone.h" #define TON 0.100 /* tone duration */ #define TOFF 0.100 /* silence duration */ static const char key[4][4] = { { '1', '2', '3', 'A' }, { '4', '5', '6', 'B' }, { '7', '8', '9', 'C' }, { '*', '0', '#', 'D' }, }; static const struct { int row[4]; int col[4]; } freq = { { 697, 770, 852, 941 }, /* rows (lower band) */ { 1209, 1336, 1477, 1633 }, /* columns (upper band) */ }; int main(void) { int ch; int r, c; while ((ch = getchar()) != EOF) { ch = toupper(ch); if (ch == ',') /* pause 2 seconds (same as ATD modem command) */ add_silence(stdout, 2. - TOFF); /* less prev tone off */ else for (r = 0; r < 4; ++r) for (c = 0; c < 4; ++c) if (ch == key[r][c]) { add_dtmf(stdout, freq.row[r], freq.col[c], TON); add_silence(stdout, TOFF); } fflush(stdout); } return 0; }