Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/bell_mf_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 * 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.15 2009/05/30 15:23:13 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 #if defined(HAVE_CONFIG_H) | |
39 #include "config.h" | |
40 #endif | |
41 | |
42 #include <stdlib.h> | |
43 #include <stdio.h> | |
44 #include <fcntl.h> | |
45 #include <string.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 "bell_mf.wav" | |
57 | |
58 int main(int argc, char *argv[]) | |
59 { | |
60 bell_mf_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 = bell_mf_tx_init(NULL); | |
74 len = bell_mf_tx(gen, amp, 16384); | |
75 printf("Generated %d samples\n", len); | |
76 outframes = sf_writef_short(outhandle, amp, len); | |
77 if (bell_mf_tx_put(gen, "123", -1)) | |
78 printf("Ooops\n"); | |
79 len = bell_mf_tx(gen, amp, 16384); | |
80 printf("Generated %d samples\n", len); | |
81 outframes = sf_writef_short(outhandle, amp, len); | |
82 if (bell_mf_tx_put(gen, "456", -1)) | |
83 printf("Ooops\n"); | |
84 len = bell_mf_tx(gen, amp, 160); | |
85 printf("Generated %d samples\n", len); | |
86 outframes = sf_writef_short(outhandle, amp, len); | |
87 if (bell_mf_tx_put(gen, "789", -1)) | |
88 printf("Ooops\n"); | |
89 len = bell_mf_tx(gen, amp, 160); | |
90 printf("Generated %d samples\n", len); | |
91 outframes = sf_writef_short(outhandle, amp, len); | |
92 if (bell_mf_tx_put(gen, "*#", -1)) | |
93 printf("Ooops\n"); | |
94 len = bell_mf_tx(gen, amp, 160); | |
95 printf("Generated %d samples\n", len); | |
96 outframes = sf_writef_short(outhandle, amp, len); | |
97 add_digits = 1; | |
98 do | |
99 { | |
100 len = bell_mf_tx(gen, amp, 160); | |
101 printf("Generated %d samples\n", len); | |
102 if (len > 0) | |
103 { | |
104 outframes = sf_writef_short(outhandle, amp, len); | |
105 } | |
106 if (add_digits) | |
107 { | |
108 if (bell_mf_tx_put(gen, "1234567890", -1)) | |
109 { | |
110 printf("Digit buffer full\n"); | |
111 add_digits = 0; | |
112 } | |
113 } | |
114 } | |
115 while (len > 0); | |
116 | |
117 bell_mf_tx_init(gen); | |
118 len = bell_mf_tx(gen, amp, 16384); | |
119 printf("Generated %d samples\n", len); | |
120 outframes = sf_writef_short(outhandle, amp, len); | |
121 if (bell_mf_tx_put(gen, "123", -1)) | |
122 printf("Ooops\n"); | |
123 len = bell_mf_tx(gen, amp, 16384); | |
124 printf("Generated %d samples\n", len); | |
125 outframes = sf_writef_short(outhandle, amp, len); | |
126 if (bell_mf_tx_put(gen, "456", -1)) | |
127 printf("Ooops\n"); | |
128 len = bell_mf_tx(gen, amp, 160); | |
129 printf("Generated %d samples\n", len); | |
130 outframes = sf_writef_short(outhandle, amp, len); | |
131 if (bell_mf_tx_put(gen, "789", -1)) | |
132 printf("Ooops\n"); | |
133 len = bell_mf_tx(gen, amp, 160); | |
134 printf("Generated %d samples\n", len); | |
135 outframes = sf_writef_short(outhandle, amp, len); | |
136 if (bell_mf_tx_put(gen, "0*#", -1)) | |
137 printf("Ooops\n"); | |
138 len = bell_mf_tx(gen, amp, 160); | |
139 printf("Generated %d samples\n", len); | |
140 outframes = sf_writef_short(outhandle, amp, len); | |
141 if (bell_mf_tx_put(gen, "ABC", -1)) | |
142 printf("Ooops\n"); | |
143 len = bell_mf_tx(gen, amp, 160); | |
144 printf("Generated %d samples\n", len); | |
145 outframes = sf_writef_short(outhandle, amp, len); | |
146 add_digits = 1; | |
147 do | |
148 { | |
149 len = bell_mf_tx(gen, amp, 160); | |
150 printf("Generated %d samples\n", len); | |
151 if (len > 0) | |
152 { | |
153 outframes = sf_writef_short(outhandle, amp, len); | |
154 } | |
155 if (add_digits) | |
156 { | |
157 if (bell_mf_tx_put(gen, "1234567890", -1)) | |
158 { | |
159 printf("Digit buffer full\n"); | |
160 add_digits = 0; | |
161 } | |
162 } | |
163 } | |
164 while (len > 0); | |
165 | |
166 if (sf_close(outhandle) != 0) | |
167 { | |
168 fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); | |
169 exit (2); | |
170 } | |
171 | |
172 return 0; | |
173 } | |
174 /*- End of function --------------------------------------------------------*/ | |
175 /*- End of file ------------------------------------------------------------*/ |