Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/dtmf_tx_tests.c @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 15:50:58 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * dtmf_tx_tests.c - Test the DTMF generator. | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2003 Steve Underwood | |
9 * | |
10 * All rights reserved. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License version 2, as | |
14 * published by the Free Software Foundation. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 * $Id: dtmf_tx_tests.c,v 1.23 2009/05/30 15:23:13 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \file */ | |
29 | |
30 /*! \page dtmf_tx_tests_page DTMF generation tests | |
31 \section dtmf_tx_tests_page_sec_1 What does it do? | |
32 ???. | |
33 | |
34 \section dtmf_tx_tests_page_sec_2 How does it work? | |
35 ???. | |
36 */ | |
37 | |
38 #if defined(HAVE_CONFIG_H) | |
39 #include "config.h" | |
40 #endif | |
41 | |
42 #include <stdlib.h> | |
43 #include <string.h> | |
44 #include <stdio.h> | |
45 #include <fcntl.h> | |
46 #include <time.h> | |
47 #include <sndfile.h> | |
48 | |
49 //#if defined(WITH_SPANDSP_INTERNALS) | |
50 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES | |
51 //#endif | |
52 | |
53 #include "spandsp.h" | |
54 #include "spandsp-sim.h" | |
55 | |
56 #define OUTPUT_FILE_NAME "dtmf.wav" | |
57 | |
58 int main(int argc, char *argv[]) | |
59 { | |
60 dtmf_tx_state_t *gen; | |
61 int16_t amp[16384]; | |
62 int len; | |
63 SNDFILE *outhandle; | |
64 int outframes; | |
65 int add_digits; | |
66 | |
67 if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 1)) == NULL) | |
68 { | |
69 fprintf(stderr, " Cannot open audio file '%s'\n", OUTPUT_FILE_NAME); | |
70 exit(2); | |
71 } | |
72 | |
73 gen = dtmf_tx_init(NULL); | |
74 len = dtmf_tx(gen, amp, 16384); | |
75 printf("Generated %d samples\n", len); | |
76 outframes = sf_writef_short(outhandle, amp, len); | |
77 if (dtmf_tx_put(gen, "123", -1)) | |
78 { | |
79 printf("Ooops\n"); | |
80 exit(2); | |
81 } | |
82 len = dtmf_tx(gen, amp, 16384); | |
83 printf("Generated %d samples\n", len); | |
84 outframes = sf_writef_short(outhandle, amp, len); | |
85 if (dtmf_tx_put(gen, "456", -1)) | |
86 { | |
87 printf("Ooops\n"); | |
88 exit(2); | |
89 } | |
90 len = dtmf_tx(gen, amp, 160); | |
91 printf("Generated %d samples\n", len); | |
92 outframes = sf_writef_short(outhandle, amp, len); | |
93 if (dtmf_tx_put(gen, "789", -1)) | |
94 { | |
95 printf("Ooops\n"); | |
96 exit(2); | |
97 } | |
98 len = dtmf_tx(gen, amp, 160); | |
99 printf("Generated %d samples\n", len); | |
100 outframes = sf_writef_short(outhandle, amp, len); | |
101 if (dtmf_tx_put(gen, "*#", -1)) | |
102 { | |
103 printf("Ooops\n"); | |
104 exit(2); | |
105 } | |
106 len = dtmf_tx(gen, amp, 160); | |
107 printf("Generated %d samples\n", len); | |
108 outframes = sf_writef_short(outhandle, amp, len); | |
109 add_digits = 1; | |
110 do | |
111 { | |
112 len = dtmf_tx(gen, amp, 160); | |
113 printf("Generated %d samples\n", len); | |
114 if (len > 0) | |
115 { | |
116 outframes = sf_writef_short(outhandle, amp, len); | |
117 } | |
118 if (add_digits) | |
119 { | |
120 if (dtmf_tx_put(gen, "1234567890", -1)) | |
121 { | |
122 printf("Digit buffer full\n"); | |
123 add_digits = 0; | |
124 } | |
125 } | |
126 } | |
127 while (len > 0); | |
128 | |
129 dtmf_tx_init(gen); | |
130 len = dtmf_tx(gen, amp, 16384); | |
131 printf("Generated %d samples\n", len); | |
132 outframes = sf_writef_short(outhandle, amp, len); | |
133 if (dtmf_tx_put(gen, "123", -1)) | |
134 { | |
135 printf("Ooops\n"); | |
136 exit(2); | |
137 } | |
138 len = dtmf_tx(gen, amp, 16384); | |
139 printf("Generated %d samples\n", len); | |
140 outframes = sf_writef_short(outhandle, amp, len); | |
141 if (dtmf_tx_put(gen, "456", -1)) | |
142 { | |
143 printf("Ooops\n"); | |
144 exit(2); | |
145 } | |
146 len = dtmf_tx(gen, amp, 160); | |
147 printf("Generated %d samples\n", len); | |
148 outframes = sf_writef_short(outhandle, amp, len); | |
149 if (dtmf_tx_put(gen, "789", -1)) | |
150 { | |
151 printf("Ooops\n"); | |
152 exit(2); | |
153 } | |
154 len = dtmf_tx(gen, amp, 160); | |
155 printf("Generated %d samples\n", len); | |
156 outframes = sf_writef_short(outhandle, amp, len); | |
157 if (dtmf_tx_put(gen, "0*#", -1)) | |
158 { | |
159 printf("Ooops\n"); | |
160 exit(2); | |
161 } | |
162 len = dtmf_tx(gen, amp, 160); | |
163 printf("Generated %d samples\n", len); | |
164 outframes = sf_writef_short(outhandle, amp, len); | |
165 if (dtmf_tx_put(gen, "ABCD", -1)) | |
166 { | |
167 printf("Ooops\n"); | |
168 exit(2); | |
169 } | |
170 len = dtmf_tx(gen, amp, 160); | |
171 printf("Generated %d samples\n", len); | |
172 outframes = sf_writef_short(outhandle, amp, len); | |
173 | |
174 /* Try modifying the level and length of the digits */ | |
175 printf("Try different levels and timing\n"); | |
176 dtmf_tx_set_level(gen, -20, 5); | |
177 dtmf_tx_set_timing(gen, 100, 200); | |
178 if (dtmf_tx_put(gen, "123", -1)) | |
179 { | |
180 printf("Ooops\n"); | |
181 exit(2); | |
182 } | |
183 do | |
184 { | |
185 len = dtmf_tx(gen, amp, 160); | |
186 printf("Generated %d samples\n", len); | |
187 if (len > 0) | |
188 outframes = sf_writef_short(outhandle, amp, len); | |
189 } | |
190 while (len > 0); | |
191 printf("Restore normal levels and timing\n"); | |
192 dtmf_tx_set_level(gen, -10, 0); | |
193 dtmf_tx_set_timing(gen, 50, 55); | |
194 if (dtmf_tx_put(gen, "A", -1)) | |
195 { | |
196 printf("Ooops\n"); | |
197 exit(2); | |
198 } | |
199 | |
200 add_digits = TRUE; | |
201 do | |
202 { | |
203 len = dtmf_tx(gen, amp, 160); | |
204 printf("Generated %d samples\n", len); | |
205 if (len > 0) | |
206 { | |
207 outframes = sf_writef_short(outhandle, amp, len); | |
208 } | |
209 if (add_digits) | |
210 { | |
211 if (dtmf_tx_put(gen, "1234567890", -1)) | |
212 { | |
213 printf("Digit buffer full\n"); | |
214 add_digits = FALSE; | |
215 } | |
216 } | |
217 } | |
218 while (len > 0); | |
219 | |
220 if (sf_close(outhandle) != 0) | |
221 { | |
222 fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); | |
223 exit(2); | |
224 } | |
225 | |
226 return 0; | |
227 } | |
228 /*- End of function --------------------------------------------------------*/ | |
229 /*- End of file ------------------------------------------------------------*/ |