Mercurial > hg > audiostuff
comparison spandsp-0.0.3/spandsp-0.0.3/tests/r2_mf_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 * r2_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: r2_mf_tx_tests.c,v 1.4 2006/11/19 14:07:27 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \file */ | |
29 | |
30 /*! \page r2_mf_tx_tests_page R2 MF generation tests | |
31 \section r2_mf_tx_tests_page_sec_1 What does it do? | |
32 ???. | |
33 | |
34 \section r2_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 #include <stdio.h> | |
46 #if defined(HAVE_TGMATH_H) | |
47 #include <tgmath.h> | |
48 #endif | |
49 #if defined(HAVE_MATH_H) | |
50 #include <math.h> | |
51 #endif | |
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 "r2_mf.wav" | |
60 | |
61 int main(int argc, char *argv[]) | |
62 { | |
63 r2_mf_tx_state_t gen; | |
64 int16_t amp[1000]; | |
65 int len; | |
66 AFfilehandle outhandle; | |
67 AFfilesetup filesetup; | |
68 int outframes; | |
69 int fwd; | |
70 int digit; | |
71 const char *digits = "0123456789BCDEF"; | |
72 | |
73 filesetup = afNewFileSetup(); | |
74 if (filesetup == AF_NULL_FILESETUP) | |
75 { | |
76 fprintf(stderr, " Failed to create file setup\n"); | |
77 exit(2); | |
78 } | |
79 afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); | |
80 afInitRate(filesetup, AF_DEFAULT_TRACK, 8000.0); | |
81 //afInitCompression(filesetup, AF_DEFAULT_TRACK, AF_COMPRESSION_G711_ALAW); | |
82 afInitFileFormat(filesetup, AF_FILE_WAVE); | |
83 afInitChannels(filesetup, AF_DEFAULT_TRACK, 1); | |
84 | |
85 outhandle = afOpenFile(OUTPUT_FILE_NAME, "w", filesetup); | |
86 if (outhandle == AF_NULL_FILEHANDLE) | |
87 { | |
88 fprintf(stderr, " Cannot open wave file '%s'\n", OUTPUT_FILE_NAME); | |
89 exit(2); | |
90 } | |
91 | |
92 r2_mf_tx_init(&gen); | |
93 fwd = FALSE; | |
94 for (digit = 0; digits[digit]; digit++) | |
95 { | |
96 len = r2_mf_tx(&gen, amp, 1000, fwd, digits[digit]); | |
97 printf("Generated %d samples of %c\n", len, digits[digit]); | |
98 if (len > 0) | |
99 { | |
100 outframes = afWriteFrames(outhandle, | |
101 AF_DEFAULT_TRACK, | |
102 amp, | |
103 len); | |
104 } | |
105 len = r2_mf_tx(&gen, amp, 1000, fwd, 0); | |
106 printf("Generated %d samples\n", len); | |
107 if (len > 0) | |
108 { | |
109 outframes = afWriteFrames(outhandle, | |
110 AF_DEFAULT_TRACK, | |
111 amp, | |
112 len); | |
113 } | |
114 } | |
115 | |
116 fwd = TRUE; | |
117 for (digit = 0; digits[digit]; digit++) | |
118 { | |
119 len = r2_mf_tx(&gen, amp, 1000, fwd, digits[digit]); | |
120 printf("Generated %d samples of %c\n", len, digits[digit]); | |
121 if (len > 0) | |
122 { | |
123 outframes = afWriteFrames(outhandle, | |
124 AF_DEFAULT_TRACK, | |
125 amp, | |
126 len); | |
127 } | |
128 len = r2_mf_tx(&gen, amp, 1000, fwd, 0); | |
129 printf("Generated %d samples\n", len); | |
130 if (len > 0) | |
131 { | |
132 outframes = afWriteFrames(outhandle, | |
133 AF_DEFAULT_TRACK, | |
134 amp, | |
135 len); | |
136 } | |
137 } | |
138 | |
139 if (afCloseFile(outhandle) != 0) | |
140 { | |
141 fprintf(stderr, " Cannot close wave file '%s'\n", OUTPUT_FILE_NAME); | |
142 exit (2); | |
143 } | |
144 afFreeFileSetup(filesetup); | |
145 | |
146 return 0; | |
147 } | |
148 /*- End of function --------------------------------------------------------*/ | |
149 /*- End of file ------------------------------------------------------------*/ |