#include #include #include #define MF_TONES 15 #define MAX_SAMPLES 8000 typedef struct { teletone_process_t low; teletone_process_t high; } r2_mf_tone_t; static r2_mf_tone_t r2_mf_fwd_tones[MF_TONES] = { { 1380.0f, 1500.0f }, { 1380.0f, 1620.0f }, { 1500.0f, 1620.0f }, { 1380.0f, 1740.0f }, { 1500.0f, 1740.0f }, { 1620.0f, 1740.0f }, { 1380.0f, 1860.0f }, { 1500.0f, 1860.0f }, { 1620.0f, 1860.0f }, { 1740.0f, 1860.0f }, { 1380.0f, 1980.0f }, { 1500.0f, 1980.0f }, { 1620.0f, 1980.0f }, { 1740.0f, 1980.0f }, { 1860.0f, 1980.0f } }; static const char signals[] = "1234567890BCDEF"; static void init_forward_tones(teletone_multi_tone_t tones[]) { int t; teletone_tone_map_t map; for (t = 0; t < sizeof(r2_mf_fwd_tones)/sizeof(r2_mf_tone_t); t++) { map.freqs[0] = r2_mf_fwd_tones[t].low; map.freqs[1] = r2_mf_fwd_tones[t].high; map.freqs[2] = 0; memset(&tones[t], 0x0, sizeof(teletone_multi_tone_t)); tones[t].min_samples = 122; tones[t].hit_factor = 1; tones[t].negative_factor = 100; tones[t].positive_factor = 0; teletone_multi_tone_init(&tones[t], &map); } } int main() { int16_t tone_buf[160]; int samples, i, t, ret, total_samples; r2_mf_tx_state_t fwd_tx_state; r2_mf_rx_state_t fwd_rx_state; teletone_multi_tone_t fwd_tones[MF_TONES]; int span_tones = 0; int tele_tones = 0; r2_mf_tx_init(&fwd_tx_state, 1); r2_mf_rx_init(&fwd_rx_state, 1); init_forward_tones(fwd_tones); for (i = 0; i < sizeof(signals)-1; i++) { ret = r2_mf_tx_put(&fwd_tx_state, signals[i]); if (0 != ret) { fprintf(stderr, "failed to put tone %c\n", signals[i]); return -1; } total_samples = 0; do { samples = r2_mf_tx(&fwd_tx_state, tone_buf, sizeof(tone_buf)/sizeof(int16_t)); total_samples += samples; ret = r2_mf_rx(&fwd_rx_state, tone_buf, samples); } while (ret != signals[i] && total_samples < MAX_SAMPLES); if (ret == signals[i]) { printf("detected tone %c with spandsp using %d samples\n", ret, total_samples); span_tones++; } else { printf("tone %c not detected with spandsp after generating %d samples\n", signals[i], total_samples); } ret = 0; total_samples = 0; do { samples = r2_mf_tx(&fwd_tx_state, tone_buf, sizeof(tone_buf)/sizeof(int16_t)); total_samples += samples; for (t = 0; t < MF_TONES; t++) { if (teletone_multi_tone_detect(&fwd_tones[t], tone_buf, samples)) { ret = signals[t]; if (ret != signals[i]) { printf("detected incorrect tone %c with teletone expecting %c\n", ret, signals[i]); } goto done; } } } while (total_samples < 100000); done: if (ret == signals[i]) { printf("detected tone %c with teletone using %d samples\n\n", ret, total_samples); tele_tones++; } else { printf("tone %c not detected with teletone after generating %d samples\n\n", signals[i], total_samples); exit(0); } } printf("spandsp detected: %d\n", span_tones); printf("teletone detected: %d\n", tele_tones); return 0; }