5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * bell_mf_tx_tests.c - Test the Bell MF 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: bell_mf_tx_tests.c,v 1.4 2006/11/19 14:07:26 steveu Exp $
|
|
26 */
|
|
27
|
|
28 /*! \file */
|
|
29
|
|
30 /*! \page bell_mf_tx_tests_page Bell MF generation tests
|
|
31 \section bell_mf_tx_tests_page_sec_1 What does it do?
|
|
32 ???.
|
|
33
|
|
34 \section bell_mf_tx_tests_page_sec_2 How does it work?
|
|
35 ???.
|
|
36 */
|
|
37
|
|
38 #ifdef HAVE_CONFIG_H
|
|
39 #include "config.h"
|
|
40 #endif
|
|
41
|
|
42 #include <stdlib.h>
|
|
43 #include <inttypes.h>
|
|
44 #include <string.h>
|
|
45 #if defined(HAVE_TGMATH_H)
|
|
46 #include <tgmath.h>
|
|
47 #endif
|
|
48 #if defined(HAVE_MATH_H)
|
|
49 #include <math.h>
|
|
50 #endif
|
|
51 #include <stdio.h>
|
|
52 #include <time.h>
|
|
53 #include <fcntl.h>
|
|
54 #include <audiofile.h>
|
|
55 #include <tiffio.h>
|
|
56
|
|
57 #include "spandsp.h"
|
|
58
|
|
59 #define OUTPUT_FILE_NAME "bell_mf.wav"
|
|
60
|
|
61 int main(int argc, char *argv[])
|
|
62 {
|
|
63 bell_mf_tx_state_t gen;
|
|
64 int16_t amp[16384];
|
|
65 int len;
|
|
66 AFfilehandle outhandle;
|
|
67 AFfilesetup filesetup;
|
|
68 int outframes;
|
|
69 int add_digits;
|
|
70
|
|
71 filesetup = afNewFileSetup();
|
|
72 if (filesetup == AF_NULL_FILESETUP)
|
|
73 {
|
|
74 fprintf(stderr, " Failed to create file setup\n");
|
|
75 exit(2);
|
|
76 }
|
|
77 afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
|
|
78 afInitRate(filesetup, AF_DEFAULT_TRACK, 8000.0);
|
|
79 //afInitCompression(filesetup, AF_DEFAULT_TRACK, AF_COMPRESSION_G711_ALAW);
|
|
80 afInitFileFormat(filesetup, AF_FILE_WAVE);
|
|
81 afInitChannels(filesetup, AF_DEFAULT_TRACK, 1);
|
|
82
|
|
83 outhandle = afOpenFile(OUTPUT_FILE_NAME, "w", filesetup);
|
|
84 if (outhandle == AF_NULL_FILEHANDLE)
|
|
85 {
|
|
86 fprintf(stderr, " Cannot open wave file '%s'\n", OUTPUT_FILE_NAME);
|
|
87 exit(2);
|
|
88 }
|
|
89
|
|
90 bell_mf_tx_init(&gen);
|
|
91 len = bell_mf_tx(&gen, amp, 16384);
|
|
92 printf("Generated %d samples\n", len);
|
|
93 outframes = afWriteFrames(outhandle,
|
|
94 AF_DEFAULT_TRACK,
|
|
95 amp,
|
|
96 len);
|
|
97 if (bell_mf_tx_put(&gen, "123"))
|
|
98 printf("Ooops\n");
|
|
99 len = bell_mf_tx(&gen, amp, 16384);
|
|
100 printf("Generated %d samples\n", len);
|
|
101 outframes = afWriteFrames(outhandle,
|
|
102 AF_DEFAULT_TRACK,
|
|
103 amp,
|
|
104 len);
|
|
105 if (bell_mf_tx_put(&gen, "456"))
|
|
106 printf("Ooops\n");
|
|
107 len = bell_mf_tx(&gen, amp, 160);
|
|
108 printf("Generated %d samples\n", len);
|
|
109 outframes = afWriteFrames(outhandle,
|
|
110 AF_DEFAULT_TRACK,
|
|
111 amp,
|
|
112 len);
|
|
113 if (bell_mf_tx_put(&gen, "789"))
|
|
114 printf("Ooops\n");
|
|
115 len = bell_mf_tx(&gen, amp, 160);
|
|
116 printf("Generated %d samples\n", len);
|
|
117 outframes = afWriteFrames(outhandle,
|
|
118 AF_DEFAULT_TRACK,
|
|
119 amp,
|
|
120 len);
|
|
121 if (bell_mf_tx_put(&gen, "*#"))
|
|
122 printf("Ooops\n");
|
|
123 len = bell_mf_tx(&gen, amp, 160);
|
|
124 printf("Generated %d samples\n", len);
|
|
125 outframes = afWriteFrames(outhandle,
|
|
126 AF_DEFAULT_TRACK,
|
|
127 amp,
|
|
128 len);
|
|
129 add_digits = 1;
|
|
130 do
|
|
131 {
|
|
132 len = bell_mf_tx(&gen, amp, 160);
|
|
133 printf("Generated %d samples\n", len);
|
|
134 if (len > 0)
|
|
135 {
|
|
136 outframes = afWriteFrames(outhandle,
|
|
137 AF_DEFAULT_TRACK,
|
|
138 amp,
|
|
139 len);
|
|
140 }
|
|
141 if (add_digits)
|
|
142 {
|
|
143 if (bell_mf_tx_put(&gen, "1234567890"))
|
|
144 {
|
|
145 printf("Digit buffer full\n");
|
|
146 add_digits = 0;
|
|
147 }
|
|
148 }
|
|
149 }
|
|
150 while (len > 0);
|
|
151
|
|
152 bell_mf_tx_init(&gen);
|
|
153 len = bell_mf_tx(&gen, amp, 16384);
|
|
154 printf("Generated %d samples\n", len);
|
|
155 outframes = afWriteFrames(outhandle,
|
|
156 AF_DEFAULT_TRACK,
|
|
157 amp,
|
|
158 len);
|
|
159 if (bell_mf_tx_put(&gen, "123"))
|
|
160 printf("Ooops\n");
|
|
161 len = bell_mf_tx(&gen, amp, 16384);
|
|
162 printf("Generated %d samples\n", len);
|
|
163 outframes = afWriteFrames(outhandle,
|
|
164 AF_DEFAULT_TRACK,
|
|
165 amp,
|
|
166 len);
|
|
167 if (bell_mf_tx_put(&gen, "456"))
|
|
168 printf("Ooops\n");
|
|
169 len = bell_mf_tx(&gen, amp, 160);
|
|
170 printf("Generated %d samples\n", len);
|
|
171 outframes = afWriteFrames(outhandle,
|
|
172 AF_DEFAULT_TRACK,
|
|
173 amp,
|
|
174 len);
|
|
175 if (bell_mf_tx_put(&gen, "789"))
|
|
176 printf("Ooops\n");
|
|
177 len = bell_mf_tx(&gen, amp, 160);
|
|
178 printf("Generated %d samples\n", len);
|
|
179 outframes = afWriteFrames(outhandle,
|
|
180 AF_DEFAULT_TRACK,
|
|
181 amp,
|
|
182 len);
|
|
183 if (bell_mf_tx_put(&gen, "0*#"))
|
|
184 printf("Ooops\n");
|
|
185 len = bell_mf_tx(&gen, amp, 160);
|
|
186 printf("Generated %d samples\n", len);
|
|
187 outframes = afWriteFrames(outhandle,
|
|
188 AF_DEFAULT_TRACK,
|
|
189 amp,
|
|
190 len);
|
|
191 if (bell_mf_tx_put(&gen, "ABC"))
|
|
192 printf("Ooops\n");
|
|
193 len = bell_mf_tx(&gen, amp, 160);
|
|
194 printf("Generated %d samples\n", len);
|
|
195 outframes = afWriteFrames(outhandle,
|
|
196 AF_DEFAULT_TRACK,
|
|
197 amp,
|
|
198 len);
|
|
199 add_digits = 1;
|
|
200 do
|
|
201 {
|
|
202 len = bell_mf_tx(&gen, amp, 160);
|
|
203 printf("Generated %d samples\n", len);
|
|
204 if (len > 0)
|
|
205 {
|
|
206 outframes = afWriteFrames(outhandle,
|
|
207 AF_DEFAULT_TRACK,
|
|
208 amp,
|
|
209 len);
|
|
210 }
|
|
211 if (add_digits)
|
|
212 {
|
|
213 if (bell_mf_tx_put(&gen, "1234567890"))
|
|
214 {
|
|
215 printf("Digit buffer full\n");
|
|
216 add_digits = 0;
|
|
217 }
|
|
218 }
|
|
219 }
|
|
220 while (len > 0);
|
|
221
|
|
222 if (afCloseFile(outhandle) != 0)
|
|
223 {
|
|
224 fprintf(stderr, " Cannot close wave file '%s'\n", OUTPUT_FILE_NAME);
|
|
225 exit (2);
|
|
226 }
|
|
227 afFreeFileSetup(filesetup);
|
|
228
|
|
229 return 0;
|
|
230 }
|
|
231 /*- End of function --------------------------------------------------------*/
|
|
232 /*- End of file ------------------------------------------------------------*/
|