Mercurial > hg > audiostuff
comparison spandsp-0.0.3/spandsp-0.0.3/tests/v8_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 * v8_tests.c | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2004 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: v8_tests.c,v 1.19 2006/11/23 15:48:09 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \page v8_tests_page V.8 tests | |
29 \section v8_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 <stdio.h> | |
39 #if defined(HAVE_TGMATH_H) | |
40 #include <tgmath.h> | |
41 #endif | |
42 #if defined(HAVE_MATH_H) | |
43 #include <math.h> | |
44 #endif | |
45 #include <fcntl.h> | |
46 #include <string.h> | |
47 #include <audiofile.h> | |
48 #include <tiffio.h> | |
49 | |
50 #include "spandsp.h" | |
51 | |
52 #define FALSE 0 | |
53 #define TRUE (!FALSE) | |
54 | |
55 #define SAMPLES_PER_CHUNK 160 | |
56 | |
57 #define OUTPUT_FILE_NAME "v8.wav" | |
58 | |
59 int negotiations_ok = 0; | |
60 | |
61 static void handler(void *user_data, v8_result_t *result) | |
62 { | |
63 const char *s; | |
64 | |
65 s = (const char *) user_data; | |
66 | |
67 if (result == NULL) | |
68 { | |
69 printf("%s V.8 negotiation failed\n", s); | |
70 return; | |
71 } | |
72 printf("%s V.8 negotiation result:\n", s); | |
73 printf(" Call function '%s'\n", v8_call_function_to_str(result->call_function)); | |
74 printf(" Negotiated modulation '%s'\n", v8_modulation_to_str(result->negotiated_modulation)); | |
75 printf(" Protocol '%s'\n", v8_protocol_to_str(result->protocol)); | |
76 printf(" PSTN access '%s'\n", v8_pstn_access_to_str(result->pstn_access)); | |
77 printf(" PCM modem availability '%s'\n", v8_pcm_modem_availability_to_str(result->pcm_modem_availability)); | |
78 if (result->call_function == V8_CALL_V_SERIES | |
79 && | |
80 result->negotiated_modulation == V8_MOD_V90 | |
81 && | |
82 result->protocol == V8_PROTOCOL_LAPM_V42) | |
83 { | |
84 negotiations_ok++; | |
85 } | |
86 } | |
87 | |
88 int main(int argc, char *argv[]) | |
89 { | |
90 int i; | |
91 int16_t amp[SAMPLES_PER_CHUNK]; | |
92 int16_t out_amp[2*SAMPLES_PER_CHUNK]; | |
93 v8_state_t v8_caller; | |
94 v8_state_t v8_answerer; | |
95 int outframes; | |
96 int samples; | |
97 int remnant; | |
98 int caller_available_modulations; | |
99 int answerer_available_modulations; | |
100 AFfilehandle outhandle; | |
101 AFfilesetup filesetup; | |
102 | |
103 if ((filesetup = afNewFileSetup()) == AF_NULL_FILESETUP) | |
104 { | |
105 fprintf(stderr, " Failed to create file setup\n"); | |
106 exit(2); | |
107 } | |
108 afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); | |
109 afInitRate(filesetup, AF_DEFAULT_TRACK, (float) SAMPLE_RATE); | |
110 afInitFileFormat(filesetup, AF_FILE_WAVE); | |
111 afInitChannels(filesetup, AF_DEFAULT_TRACK, 2); | |
112 if ((outhandle = afOpenFile(OUTPUT_FILE_NAME, "w", filesetup)) == AF_NULL_FILEHANDLE) | |
113 { | |
114 fprintf(stderr, " Cannot create wave file '%s'\n", OUTPUT_FILE_NAME); | |
115 exit(2); | |
116 } | |
117 | |
118 caller_available_modulations = V8_MOD_V17 | |
119 | V8_MOD_V21 | |
120 | V8_MOD_V22 | |
121 | V8_MOD_V23HALF | |
122 | V8_MOD_V23 | |
123 | V8_MOD_V26BIS | |
124 | V8_MOD_V26TER | |
125 | V8_MOD_V27TER | |
126 | V8_MOD_V29 | |
127 | V8_MOD_V32 | |
128 | V8_MOD_V34HALF | |
129 | V8_MOD_V34 | |
130 | V8_MOD_V90 | |
131 | V8_MOD_V92; | |
132 answerer_available_modulations = V8_MOD_V17 | |
133 | V8_MOD_V21 | |
134 | V8_MOD_V22 | |
135 | V8_MOD_V23HALF | |
136 | V8_MOD_V23 | |
137 | V8_MOD_V26BIS | |
138 | V8_MOD_V26TER | |
139 | V8_MOD_V27TER | |
140 | V8_MOD_V29 | |
141 | V8_MOD_V32 | |
142 | V8_MOD_V34HALF | |
143 | V8_MOD_V34 | |
144 | V8_MOD_V90 | |
145 | V8_MOD_V92; | |
146 | |
147 v8_init(&v8_caller, TRUE, caller_available_modulations, handler, (void *) "caller"); | |
148 v8_init(&v8_answerer, FALSE, answerer_available_modulations, handler, (void *) "answerer"); | |
149 span_log_set_level(&v8_caller.logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG); | |
150 span_log_set_tag(&v8_caller.logging, "caller"); | |
151 span_log_set_level(&v8_answerer.logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG); | |
152 span_log_set_tag(&v8_answerer.logging, "answerer"); | |
153 for (i = 0; i < 1000; i++) | |
154 { | |
155 samples = v8_tx(&v8_caller, amp, SAMPLES_PER_CHUNK); | |
156 if (samples < SAMPLES_PER_CHUNK) | |
157 { | |
158 memset(amp + samples, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - samples)); | |
159 samples = SAMPLES_PER_CHUNK; | |
160 } | |
161 remnant = v8_rx(&v8_answerer, amp, samples); | |
162 for (i = 0; i < samples; i++) | |
163 out_amp[2*i] = amp[i]; | |
164 | |
165 samples = v8_tx(&v8_answerer, amp, SAMPLES_PER_CHUNK); | |
166 if (samples < SAMPLES_PER_CHUNK) | |
167 { | |
168 memset(amp + samples, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - samples)); | |
169 samples = SAMPLES_PER_CHUNK; | |
170 } | |
171 if (v8_rx(&v8_caller, amp, samples) && remnant) | |
172 break; | |
173 for (i = 0; i < samples; i++) | |
174 out_amp[2*i + 1] = amp[i]; | |
175 | |
176 outframes = afWriteFrames(outhandle, | |
177 AF_DEFAULT_TRACK, | |
178 out_amp, | |
179 samples); | |
180 if (outframes != samples) | |
181 { | |
182 fprintf(stderr, " Error writing wave file\n"); | |
183 exit(2); | |
184 } | |
185 } | |
186 if (afCloseFile(outhandle)) | |
187 { | |
188 fprintf(stderr, " Cannot close wave file '%s'\n", OUTPUT_FILE_NAME); | |
189 exit(2); | |
190 } | |
191 afFreeFileSetup(filesetup); | |
192 | |
193 v8_release(&v8_caller); | |
194 v8_release(&v8_answerer); | |
195 | |
196 if (negotiations_ok != 2) | |
197 { | |
198 printf("Tests failed.\n"); | |
199 exit(2); | |
200 } | |
201 | |
202 printf("Tests passed.\n"); | |
203 return 0; | |
204 } | |
205 /*- End of function --------------------------------------------------------*/ | |
206 /*- End of file ------------------------------------------------------------*/ |