# HG changeset patch # User Mychaela Falconia # Date 1709798744 28800 # Node ID ff535725e01f7ff2f6b84d7d99ed3625db571162 # Parent eaf0e8f81a229e1f5fecb8348ac24860e74130b3 g711-tone-detect program written diff -r eaf0e8f81a22 -r ff535725e01f .hgignore --- a/.hgignore Wed Mar 06 21:33:49 2024 -0800 +++ b/.hgignore Thu Mar 07 00:05:44 2024 -0800 @@ -4,3 +4,4 @@ ^test-fsk/sipout-test-fsk$ ^test-voice/sipout-test-voice$ +^tone-detect/g711-tone-detect$ diff -r eaf0e8f81a22 -r ff535725e01f Makefile --- a/Makefile Wed Mar 06 21:33:49 2024 -0800 +++ b/Makefile Thu Mar 07 00:05:44 2024 -0800 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 -PROGDIR=test-fsk test-voice +PROGDIR=test-fsk test-voice tone-detect LIBDIR= librtpalloc libsip libutil SUBDIR= ${PROGDIR} ${LIBDIR} diff -r eaf0e8f81a22 -r ff535725e01f tone-detect/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tone-detect/Makefile Thu Mar 07 00:05:44 2024 -0800 @@ -0,0 +1,13 @@ +CC= gcc +CFLAGS= -O2 +PROG= g711-tone-detect + +all: ${PROG} + +${PROG}: ${PROG}.c + ${CC} ${CFLAGS} -o $@ $@.c -lspandsp -lm + +install: + +clean: + rm -f *.o ${PROG} errs diff -r eaf0e8f81a22 -r ff535725e01f tone-detect/g711-tone-detect.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tone-detect/g711-tone-detect.c Thu Mar 07 00:05:44 2024 -0800 @@ -0,0 +1,79 @@ +/* + * This program reads a G.711 sample stream recording (typically extracted + * from an RTP stream pcap with rtp-g711-extr by the same author) and feeds + * it to SpanDSP modem connection tone detector. + */ + +#include +#include +#include +#include +#include +#include +#include "../include/pstn_defs.h" + +static char *data_filename; +static int use_alaw, tone_type_sought; +static g711_state_t *g711_dec_state; +static modem_connect_tones_rx_state_t *tones_rx_state; +static unsigned frame_count; + +static void report_func(void *user_data, int code, int level, int delay) +{ + printf("@%u.%03us: %s\n", frame_count / 50, (frame_count % 50) * 20, + modem_connect_tone_to_str(code)); +} + +main(argc, argv) + char **argv; +{ + FILE *inf; + uint8_t g711_buf[FRAME_20MS]; + int16_t linear[FRAME_20MS]; + int cc; + + switch (argc) { + case 3: + data_filename = argv[1]; + tone_type_sought = atoi(argv[2]); + break; + case 4: + data_filename = argv[1]; + if (strcmp(argv[2], "alaw")) + goto usage; + use_alaw = 1; + tone_type_sought = atoi(argv[3]); + break; + default: + usage: + fprintf(stderr, + "usage: %s data-filename [alaw] tone-type-code\n", + argv[0]); + exit(1); + } + inf = fopen(data_filename, "r"); + if (!inf) { + perror(data_filename); + exit(1); + } + g711_dec_state = g711_init(NULL, use_alaw ? G711_ALAW : G711_ULAW); + if (!g711_dec_state) { + fprintf(stderr, "error: g711_init() failed!\n"); + exit(1); + } + tones_rx_state = modem_connect_tones_rx_init(NULL, tone_type_sought, + report_func, NULL); + if (!tones_rx_state) { + fprintf(stderr, + "error: modem_connect_tones_rx_init() failed!\n"); + exit(1); + } + for (frame_count = 0; ; frame_count++) { + cc = fread(g711_buf, 1, FRAME_20MS, inf); + if (cc == 0) + break; + g711_decode(g711_dec_state, linear, g711_buf, cc); + modem_connect_tones_rx(tones_rx_state, linear, cc); + } + exit(0); +}