103 #define LOW_ENG 10000000 110 static float dtmf_row[] = {697.0f, 770.0f, 852.0f, 941.0f};
111 static float dtmf_col[] = {1209.0f, 1336.0f, 1477.0f, 1633.0f};
116 goertzel_state->
v2 = goertzel_state->
v3 = 0.0;
117 goertzel_state->
fac = tdesc->
fac;
121 int16_t sample_buffer[],
127 for (i = 0; i < samples; i++) {
128 v1 = goertzel_state->
v2;
129 goertzel_state->
v2 = goertzel_state->
v3;
130 goertzel_state->
v3 = (float)(goertzel_state->
fac*goertzel_state->
v2 - v1 + sample_buffer[i]);
134 #pragma warning(disable:4244) 137 #define teletone_goertzel_result(gs) (double)(((gs)->v3 * (gs)->v3 + (gs)->v2 * (gs)->v2 - (gs)->v2 * (gs)->v3 * (gs)->fac)) 148 dtmf_detect_state->
hit1 = dtmf_detect_state->
hit2 = 0;
152 dtmf_detect_row[i].
fac = (float)(2.0*cos(theta));
155 dtmf_detect_col[i].
fac = (float)(2.0*cos(theta));
158 dtmf_detect_row_2nd[i].
fac = (float)(2.0*cos(theta));
161 dtmf_detect_col_2nd[i].
fac = (float)(2.0*cos(theta));
168 dtmf_detect_state->
energy = 0.0;
173 dtmf_detect_state->
digit = 0;
174 dtmf_detect_state->
dur = 0;
205 if ((
int) map->
freqs[x] == 0) {
210 mt->
tdd[x].
fac = (float)(2.0 * cos(theta));
218 int16_t sample_buffer[],
221 int sample, limit = 0, j, x = 0;
224 int gtest = 0, see_hit = 0;
226 for (sample = 0; sample >= 0 && sample < samples; sample = limit) {
234 if (limit < 0 || limit > samples) {
238 for (j = sample; j < limit; j++) {
239 famp = sample_buffer[j];
246 mt->
gs[x].
v3 = (float)(mt->
gs[x].
fac * mt->
gs[x].
v2 - v1 + famp);
262 eng_sum += eng_all[x];
270 if ((gtest >= 2 || gtest == mt->
tone_count) && eng_sum > 42.0 * mt->
energy) {
308 int16_t sample_buffer[],
324 for (sample = 0; sample < samples; sample = limit) {
332 for (j = sample; j < limit; j++) {
334 famp = sample_buffer[j];
336 dtmf_detect_state->
energy += famp*famp;
358 if (dtmf_detect_state->
zc > 0) {
360 if (!--dtmf_detect_state->
zc) {
362 dtmf_detect_state->
hit1 = dtmf_detect_state->
hit2 = 0;
369 dtmf_detect_state->
dur -= samples;
374 dtmf_detect_state->
dur += samples;
376 dtmf_detect_state->
energy = 0.0;
379 }
else if (dtmf_detect_state->
digit) {
393 for (best_row = best_col = 0, i = 1; i <
GRID_FACTOR; i++) {
395 if (row_energy[i] > row_energy[best_row]) {
399 if (col_energy[i] > col_energy[best_col]) {
417 if (i >= GRID_FACTOR && (row_energy[best_row] + col_energy[best_col]) > 42.0*dtmf_detect_state->
energy &&
428 if (! r && hit == dtmf_detect_state->
hit3 && dtmf_detect_state->
hit3 != dtmf_detect_state->
hit2) {
429 dtmf_detect_state->
digit_hits[(best_row << 2) + best_col]++;
432 dtmf_detect_state->
digit = hit;
437 if (!dtmf_detect_state->
zc) {
438 dtmf_detect_state->
zc =
ZC;
439 dtmf_detect_state->
dur = 0;
448 dtmf_detect_state->
hit1 = dtmf_detect_state->
hit2;
449 dtmf_detect_state->
hit2 = dtmf_detect_state->
hit3;
450 dtmf_detect_state->
hit3 = hit;
452 dtmf_detect_state->
energy = 0.0;
463 if (!dtmf_detect_state->
digit) {
467 *buf = dtmf_detect_state->
digit;
469 *dur = dtmf_detect_state->
dur;
471 if (!dtmf_detect_state->
zc) {
472 dtmf_detect_state->
dur = 0;
473 dtmf_detect_state->
digit = 0;
static teletone_detection_descriptor_t dtmf_detect_row[GRID_FACTOR]
teletone_goertzel_state_t row_out[GRID_FACTOR]
#define TELETONE_MAX_TONES
A container for a single multi-tone detection TELETONE_MAX_TONES dictates the maximum simultaneous to...
An abstraction to store a tone mapping.
A container for a DTMF detection state.
teletone_goertzel_state_t gs[TELETONE_MAX_TONES]
A continer for the elements of a Goertzel Algorithm (The names are from his formula) ...
#define TELETONE_API(type)
#define DTMF_RELATIVE_PEAK_COL
teletone_goertzel_state_t row_out2nd[GRID_FACTOR]
void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *map)
Initilize a multi-frequency tone detector.
teletone_goertzel_state_t col_out2nd[GRID_FACTOR]
#define TELETONE_MAX_DTMF_DIGITS
static teletone_detection_descriptor_t dtmf_detect_row_2nd[GRID_FACTOR]
switch_byte_t switch_byte_t * buf
teletone_process_t freqs[TELETONE_MAX_TONES]
teletone_hit_type_t teletone_dtmf_detect(teletone_dtmf_detect_state_t *dtmf_detect_state, int16_t sample_buffer[], int samples)
Check a sample buffer for the presence of DTMF digits.
teletone_goertzel_state_t gs2[TELETONE_MAX_TONES]
static char dtmf_positions[]
int teletone_dtmf_get(teletone_dtmf_detect_state_t *dtmf_detect_state, char *buf, unsigned int *dur)
retrieve any collected digits into a string buffer
#define DTMF_RELATIVE_PEAK_ROW
#define DTMF_NORMAL_TWIST
int teletone_multi_tone_detect(teletone_multi_tone_t *mt, int16_t sample_buffer[], int samples)
Check a sample buffer for the presence of the mulit-frequency tone described by mt.
An abstraction to store the coefficient of a tone frequency.
#define teletone_goertzel_result(gs)
static teletone_detection_descriptor_t dtmf_detect_col_2nd[GRID_FACTOR]
static void goertzel_init(teletone_goertzel_state_t *goertzel_state, teletone_detection_descriptor_t *tdesc)
#define DTMF_2ND_HARMONIC_COL
static teletone_detection_descriptor_t dtmf_detect_col[GRID_FACTOR]
teletone_goertzel_state_t col_out[GRID_FACTOR]
#define DTMF_2ND_HARMONIC_ROW
#define DTMF_REVERSE_TWIST
void teletone_goertzel_update(teletone_goertzel_state_t *goertzel_state, int16_t sample_buffer[], int samples)
Step through the Goertzel Algorithm for each sample in a buffer.
teletone_detection_descriptor_t tdd[TELETONE_MAX_TONES]
void teletone_dtmf_detect_init(teletone_dtmf_detect_state_t *dtmf_detect_state, int sample_rate)
Initilize a DTMF detection state object.