comparison spandsp-0.0.3/spandsp-0.0.3/tests/tone_generate_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 * 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.13 2006/11/23 15:32:23 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 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <stdlib.h>
37 #include <inttypes.h>
38 #include <string.h>
39 #include <stdio.h>
40 #if defined(HAVE_TGMATH_H)
41 #include <tgmath.h>
42 #endif
43 #if defined(HAVE_MATH_H)
44 #include <math.h>
45 #endif
46 #include <time.h>
47 #include <fcntl.h>
48 #include <audiofile.h>
49 #include <tiffio.h>
50
51 #include "spandsp.h"
52
53 #define OUTPUT_FILE_NAME "tone_generate.wav"
54
55 int main(int argc, char *argv[])
56 {
57 tone_gen_descriptor_t tone_desc;
58 tone_gen_state_t tone_state;
59 int i;
60 int16_t amp[16384];
61 int len;
62 AFfilehandle outhandle;
63 AFfilesetup filesetup;
64 int outframes;
65
66 filesetup = afNewFileSetup ();
67 if (filesetup == AF_NULL_FILESETUP)
68 {
69 fprintf(stderr, " Failed to create file setup\n");
70 exit(2);
71 }
72 afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
73 afInitRate(filesetup, AF_DEFAULT_TRACK, 8000.0);
74 //afInitCompression(filesetup, AF_DEFAULT_TRACK, AF_COMPRESSION_G711_ALAW);
75 afInitFileFormat(filesetup, AF_FILE_WAVE);
76 afInitChannels(filesetup, AF_DEFAULT_TRACK, 1);
77
78 outhandle = afOpenFile(OUTPUT_FILE_NAME, "w", filesetup);
79 if (outhandle == AF_NULL_FILEHANDLE)
80 {
81 fprintf(stderr, " Cannot open wave file '%s'\n", OUTPUT_FILE_NAME);
82 exit(2);
83 }
84
85 make_tone_gen_descriptor(&tone_desc,
86 440,
87 -10,
88 620,
89 -15,
90 100,
91 200,
92 300,
93 400,
94 FALSE);
95 tone_gen_init(&tone_state, &tone_desc);
96
97 for (i = 0; i < 1000; i++)
98 {
99 len = tone_gen(&tone_state, amp, 160);
100 printf("Generated %d samples\n", len);
101 if (len <= 0)
102 break;
103 outframes = afWriteFrames(outhandle,
104 AF_DEFAULT_TRACK,
105 amp,
106 len);
107 }
108
109 make_tone_gen_descriptor(&tone_desc,
110 350,
111 -10,
112 440,
113 -15,
114 100,
115 200,
116 300,
117 400,
118 TRUE);
119 tone_gen_init(&tone_state, &tone_desc);
120
121 for (i = 0; i < 1000; i++)
122 {
123 len = tone_gen(&tone_state, amp, 160);
124 printf("Generated %d samples\n", len);
125 if (len <= 0)
126 break;
127 outframes = afWriteFrames(outhandle,
128 AF_DEFAULT_TRACK,
129 amp,
130 len);
131 }
132
133 make_tone_gen_descriptor(&tone_desc,
134 400,
135 -10,
136 450,
137 -10,
138 100,
139 200,
140 300,
141 400,
142 TRUE);
143 tone_gen_init(&tone_state, &tone_desc);
144
145 for (i = 0; i < 1000; i++)
146 {
147 len = tone_gen(&tone_state, amp, 160);
148 printf("Generated %d samples\n", len);
149 if (len <= 0)
150 break;
151 outframes = afWriteFrames(outhandle,
152 AF_DEFAULT_TRACK,
153 amp,
154 len);
155 }
156
157 make_tone_gen_descriptor(&tone_desc,
158 425,
159 -10,
160 -50,
161 100,
162 100,
163 200,
164 300,
165 400,
166 TRUE);
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 = afWriteFrames(outhandle,
176 AF_DEFAULT_TRACK,
177 amp,
178 len);
179 }
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 ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.