FreeCalypso > hg > sipout-test-utils
comparison tone-detect/g711-tone-detect.c @ 9:ff535725e01f
g711-tone-detect program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 07 Mar 2024 00:05:44 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
8:eaf0e8f81a22 | 9:ff535725e01f |
---|---|
1 /* | |
2 * This program reads a G.711 sample stream recording (typically extracted | |
3 * from an RTP stream pcap with rtp-g711-extr by the same author) and feeds | |
4 * it to SpanDSP modem connection tone detector. | |
5 */ | |
6 | |
7 #include <stdio.h> | |
8 #include <stdint.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <strings.h> | |
12 #include <spandsp.h> | |
13 #include "../include/pstn_defs.h" | |
14 | |
15 static char *data_filename; | |
16 static int use_alaw, tone_type_sought; | |
17 static g711_state_t *g711_dec_state; | |
18 static modem_connect_tones_rx_state_t *tones_rx_state; | |
19 static unsigned frame_count; | |
20 | |
21 static void report_func(void *user_data, int code, int level, int delay) | |
22 { | |
23 printf("@%u.%03us: %s\n", frame_count / 50, (frame_count % 50) * 20, | |
24 modem_connect_tone_to_str(code)); | |
25 } | |
26 | |
27 main(argc, argv) | |
28 char **argv; | |
29 { | |
30 FILE *inf; | |
31 uint8_t g711_buf[FRAME_20MS]; | |
32 int16_t linear[FRAME_20MS]; | |
33 int cc; | |
34 | |
35 switch (argc) { | |
36 case 3: | |
37 data_filename = argv[1]; | |
38 tone_type_sought = atoi(argv[2]); | |
39 break; | |
40 case 4: | |
41 data_filename = argv[1]; | |
42 if (strcmp(argv[2], "alaw")) | |
43 goto usage; | |
44 use_alaw = 1; | |
45 tone_type_sought = atoi(argv[3]); | |
46 break; | |
47 default: | |
48 usage: | |
49 fprintf(stderr, | |
50 "usage: %s data-filename [alaw] tone-type-code\n", | |
51 argv[0]); | |
52 exit(1); | |
53 } | |
54 inf = fopen(data_filename, "r"); | |
55 if (!inf) { | |
56 perror(data_filename); | |
57 exit(1); | |
58 } | |
59 g711_dec_state = g711_init(NULL, use_alaw ? G711_ALAW : G711_ULAW); | |
60 if (!g711_dec_state) { | |
61 fprintf(stderr, "error: g711_init() failed!\n"); | |
62 exit(1); | |
63 } | |
64 tones_rx_state = modem_connect_tones_rx_init(NULL, tone_type_sought, | |
65 report_func, NULL); | |
66 if (!tones_rx_state) { | |
67 fprintf(stderr, | |
68 "error: modem_connect_tones_rx_init() failed!\n"); | |
69 exit(1); | |
70 } | |
71 for (frame_count = 0; ; frame_count++) { | |
72 cc = fread(g711_buf, 1, FRAME_20MS, inf); | |
73 if (cc == 0) | |
74 break; | |
75 g711_decode(g711_dec_state, linear, g711_buf, cc); | |
76 modem_connect_tones_rx(tones_rx_state, linear, cc); | |
77 } | |
78 exit(0); | |
79 } |