Mercurial > hg > audiostuff
comparison spandsp-0.0.3/spandsp-0.0.3/tests/dtmf_tx_tests.c @ 5:f762bf195c4b
import spandsp-0.0.3
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 16:00:21 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:26cd8f1ef0b1 | 5:f762bf195c4b |
---|---|
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.11 2006/11/19 14:07:27 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 #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 "dtmf.wav" | |
60 | |
61 int main(int argc, char *argv[]) | |
62 { | |
63 dtmf_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 if ((filesetup = afNewFileSetup()) == AF_NULL_FILESETUP) | |
72 { | |
73 fprintf(stderr, " Failed to create file setup\n"); | |
74 exit(2); | |
75 } | |
76 afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); | |
77 afInitRate(filesetup, AF_DEFAULT_TRACK, 8000.0); | |
78 //afInitCompression(filesetup, AF_DEFAULT_TRACK, AF_COMPRESSION_G711_ALAW); | |
79 afInitFileFormat(filesetup, AF_FILE_WAVE); | |
80 afInitChannels(filesetup, AF_DEFAULT_TRACK, 1); | |
81 | |
82 if ((outhandle = afOpenFile(OUTPUT_FILE_NAME, "w", filesetup)) == AF_NULL_FILEHANDLE) | |
83 { | |
84 fprintf(stderr, " Cannot open wave file '%s'\n", OUTPUT_FILE_NAME); | |
85 exit(2); | |
86 } | |
87 | |
88 dtmf_tx_init(&gen); | |
89 len = dtmf_tx(&gen, amp, 16384); | |
90 printf("Generated %d samples\n", len); | |
91 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
92 if (dtmf_tx_put(&gen, "123")) | |
93 printf("Ooops\n"); | |
94 len = dtmf_tx(&gen, amp, 16384); | |
95 printf("Generated %d samples\n", len); | |
96 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
97 if (dtmf_tx_put(&gen, "456")) | |
98 printf("Ooops\n"); | |
99 len = dtmf_tx(&gen, amp, 160); | |
100 printf("Generated %d samples\n", len); | |
101 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
102 if (dtmf_tx_put(&gen, "789")) | |
103 printf("Ooops\n"); | |
104 len = dtmf_tx(&gen, amp, 160); | |
105 printf("Generated %d samples\n", len); | |
106 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
107 if (dtmf_tx_put(&gen, "*#")) | |
108 printf("Ooops\n"); | |
109 len = dtmf_tx(&gen, amp, 160); | |
110 printf("Generated %d samples\n", len); | |
111 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
112 add_digits = 1; | |
113 do | |
114 { | |
115 len = dtmf_tx(&gen, amp, 160); | |
116 printf("Generated %d samples\n", len); | |
117 if (len > 0) | |
118 { | |
119 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
120 } | |
121 if (add_digits) | |
122 { | |
123 if (dtmf_tx_put(&gen, "1234567890")) | |
124 { | |
125 printf("Digit buffer full\n"); | |
126 add_digits = 0; | |
127 } | |
128 } | |
129 } | |
130 while (len > 0); | |
131 | |
132 dtmf_tx_init(&gen); | |
133 len = dtmf_tx(&gen, amp, 16384); | |
134 printf("Generated %d samples\n", len); | |
135 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
136 if (dtmf_tx_put(&gen, "123")) | |
137 printf("Ooops\n"); | |
138 len = dtmf_tx(&gen, amp, 16384); | |
139 printf("Generated %d samples\n", len); | |
140 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
141 if (dtmf_tx_put(&gen, "456")) | |
142 printf("Ooops\n"); | |
143 len = dtmf_tx(&gen, amp, 160); | |
144 printf("Generated %d samples\n", len); | |
145 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
146 if (dtmf_tx_put(&gen, "789")) | |
147 printf("Ooops\n"); | |
148 len = dtmf_tx(&gen, amp, 160); | |
149 printf("Generated %d samples\n", len); | |
150 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
151 if (dtmf_tx_put(&gen, "0*#")) | |
152 printf("Ooops\n"); | |
153 len = dtmf_tx(&gen, amp, 160); | |
154 printf("Generated %d samples\n", len); | |
155 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
156 if (dtmf_tx_put(&gen, "ABCD")) | |
157 printf("Ooops\n"); | |
158 len = dtmf_tx(&gen, amp, 160); | |
159 printf("Generated %d samples\n", len); | |
160 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
161 add_digits = 1; | |
162 do | |
163 { | |
164 len = dtmf_tx(&gen, amp, 160); | |
165 printf("Generated %d samples\n", len); | |
166 if (len > 0) | |
167 { | |
168 outframes = afWriteFrames(outhandle, AF_DEFAULT_TRACK, amp, len); | |
169 } | |
170 if (add_digits) | |
171 { | |
172 if (dtmf_tx_put(&gen, "1234567890")) | |
173 { | |
174 printf("Digit buffer full\n"); | |
175 add_digits = 0; | |
176 } | |
177 } | |
178 } | |
179 while (len > 0); | |
180 | |
181 if (afCloseFile(outhandle) != 0) | |
182 { | |
183 fprintf(stderr, " Cannot close wave file '%s'\n", OUTPUT_FILE_NAME); | |
184 exit (2); | |
185 } | |
186 afFreeFileSetup(filesetup); | |
187 | |
188 return 0; | |
189 } | |
190 /*- End of function --------------------------------------------------------*/ | |
191 /*- End of file ------------------------------------------------------------*/ |