Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/tone_generate_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 * tone_generate_tests.c | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2001 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: tone_generate_tests.c,v 1.22 2009/05/30 15:23:14 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \page tone_generate_tests_page Tone generation tests | |
29 \section tone_generate_tests_page_sec_1 What does it do? | |
30 */ | |
31 | |
32 #if defined(HAVE_CONFIG_H) | |
33 #include "config.h" | |
34 #endif | |
35 | |
36 #include <stdlib.h> | |
37 #include <stdio.h> | |
38 #include <fcntl.h> | |
39 #include <string.h> | |
40 #include <time.h> | |
41 #include <sndfile.h> | |
42 | |
43 //#if defined(WITH_SPANDSP_INTERNALS) | |
44 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES | |
45 //#endif | |
46 | |
47 #include "spandsp.h" | |
48 #include "spandsp-sim.h" | |
49 | |
50 #define OUTPUT_FILE_NAME "tone_generate.wav" | |
51 | |
52 int main(int argc, char *argv[]) | |
53 { | |
54 tone_gen_descriptor_t tone_desc; | |
55 tone_gen_state_t tone_state; | |
56 int i; | |
57 int16_t amp[16384]; | |
58 int len; | |
59 SNDFILE *outhandle; | |
60 int outframes; | |
61 | |
62 if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 1)) == NULL) | |
63 { | |
64 fprintf(stderr, " Cannot open audio file '%s'\n", OUTPUT_FILE_NAME); | |
65 exit(2); | |
66 } | |
67 | |
68 /* Try a tone pair */ | |
69 make_tone_gen_descriptor(&tone_desc, | |
70 440, | |
71 -10, | |
72 620, | |
73 -15, | |
74 100, | |
75 200, | |
76 300, | |
77 400, | |
78 FALSE); | |
79 tone_gen_init(&tone_state, &tone_desc); | |
80 | |
81 for (i = 0; i < 1000; i++) | |
82 { | |
83 len = tone_gen(&tone_state, amp, 160); | |
84 printf("Generated %d samples\n", len); | |
85 if (len <= 0) | |
86 break; | |
87 outframes = sf_writef_short(outhandle, amp, len); | |
88 } | |
89 | |
90 /* Try a different tone pair */ | |
91 make_tone_gen_descriptor(&tone_desc, | |
92 350, | |
93 -10, | |
94 440, | |
95 -15, | |
96 400, | |
97 300, | |
98 200, | |
99 100, | |
100 TRUE); | |
101 tone_gen_init(&tone_state, &tone_desc); | |
102 | |
103 for (i = 0; i < 1000; i++) | |
104 { | |
105 len = tone_gen(&tone_state, amp, 160); | |
106 printf("Generated %d samples\n", len); | |
107 if (len <= 0) | |
108 break; | |
109 outframes = sf_writef_short(outhandle, amp, len); | |
110 } | |
111 | |
112 /* Try a different tone pair */ | |
113 make_tone_gen_descriptor(&tone_desc, | |
114 400, | |
115 -10, | |
116 450, | |
117 -10, | |
118 100, | |
119 200, | |
120 300, | |
121 400, | |
122 TRUE); | |
123 tone_gen_init(&tone_state, &tone_desc); | |
124 | |
125 for (i = 0; i < 1000; i++) | |
126 { | |
127 len = tone_gen(&tone_state, amp, 160); | |
128 printf("Generated %d samples\n", len); | |
129 if (len <= 0) | |
130 break; | |
131 outframes = sf_writef_short(outhandle, amp, len); | |
132 } | |
133 | |
134 /* Try a single tone */ | |
135 make_tone_gen_descriptor(&tone_desc, | |
136 400, | |
137 -10, | |
138 0, | |
139 0, | |
140 100, | |
141 200, | |
142 300, | |
143 400, | |
144 TRUE); | |
145 tone_gen_init(&tone_state, &tone_desc); | |
146 | |
147 for (i = 0; i < 1000; i++) | |
148 { | |
149 len = tone_gen(&tone_state, amp, 160); | |
150 printf("Generated %d samples\n", len); | |
151 if (len <= 0) | |
152 break; | |
153 outframes = sf_writef_short(outhandle, amp, len); | |
154 } | |
155 | |
156 /* Try a single non-repeating tone */ | |
157 make_tone_gen_descriptor(&tone_desc, | |
158 820, | |
159 -10, | |
160 0, | |
161 0, | |
162 2000, | |
163 0, | |
164 0, | |
165 0, | |
166 FALSE); | |
167 tone_gen_init(&tone_state, &tone_desc); | |
168 | |
169 for (i = 0; i < 1000; i++) | |
170 { | |
171 len = tone_gen(&tone_state, amp, 160); | |
172 printf("Generated %d samples\n", len); | |
173 if (len <= 0) | |
174 break; | |
175 outframes = sf_writef_short(outhandle, amp, len); | |
176 } | |
177 | |
178 /* Try a single non-repeating tone at 0dBm0 */ | |
179 make_tone_gen_descriptor(&tone_desc, | |
180 820, | |
181 0, | |
182 0, | |
183 0, | |
184 2000, | |
185 0, | |
186 0, | |
187 0, | |
188 FALSE); | |
189 tone_gen_init(&tone_state, &tone_desc); | |
190 | |
191 for (i = 0; i < 1000; i++) | |
192 { | |
193 len = tone_gen(&tone_state, amp, 160); | |
194 printf("Generated %d samples\n", len); | |
195 if (len <= 0) | |
196 break; | |
197 outframes = sf_writef_short(outhandle, amp, len); | |
198 } | |
199 | |
200 /* Try an AM modulated tone at a modest modulation level (25%) */ | |
201 make_tone_gen_descriptor(&tone_desc, | |
202 425, | |
203 -10, | |
204 -50, | |
205 25, | |
206 100, | |
207 200, | |
208 300, | |
209 400, | |
210 TRUE); | |
211 tone_gen_init(&tone_state, &tone_desc); | |
212 | |
213 for (i = 0; i < 1000; i++) | |
214 { | |
215 len = tone_gen(&tone_state, amp, 160); | |
216 printf("Generated %d samples\n", len); | |
217 if (len <= 0) | |
218 break; | |
219 outframes = sf_writef_short(outhandle, amp, len); | |
220 } | |
221 | |
222 /* Try an AM modulated tone at maximum modulation level (100%) */ | |
223 make_tone_gen_descriptor(&tone_desc, | |
224 425, | |
225 -10, | |
226 -50, | |
227 100, | |
228 100, | |
229 200, | |
230 300, | |
231 400, | |
232 TRUE); | |
233 tone_gen_init(&tone_state, &tone_desc); | |
234 | |
235 for (i = 0; i < 1000; i++) | |
236 { | |
237 len = tone_gen(&tone_state, amp, 160); | |
238 printf("Generated %d samples\n", len); | |
239 if (len <= 0) | |
240 break; | |
241 outframes = sf_writef_short(outhandle, amp, len); | |
242 } | |
243 | |
244 if (sf_close(outhandle) != 0) | |
245 { | |
246 fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); | |
247 exit (2); | |
248 } | |
249 | |
250 return 0; | |
251 } | |
252 /*- End of function --------------------------------------------------------*/ | |
253 /*- End of file ------------------------------------------------------------*/ |