1 /*
2 * Copyright (c) 2002 Fabrice Bellard
3 * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
4 *
5 * This file is part of Libav.
6 *
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <stdint.h>
23 #include <stdio.h>
24
34
36 {
37 return 2.0 * (
av_lfg_get(lfg) / (double)UINT_MAX) - 1.0;
38 }
39
40 #define PUT_FUNC(name, fmt, type, expr) \
41 static void put_sample_ ## name(void **data, enum AVSampleFormat sample_fmt,\
42 int channels, int sample, int ch, \
43 double v_dbl) \
44 { \
45 type v = expr; \
46 type **out = (type **)data; \
47 if (av_sample_fmt_is_planar(sample_fmt)) \
48 out[ch][sample] = v; \
49 else \
50 out[0][sample * channels + ch] = v; \
51 }
52
58
60 int channels,
int sample,
int ch,
double v_dbl)
61 {
64 put_sample_u8(data, sample_fmt, channels, sample, ch, v_dbl);
65 break;
66 case AV_SAMPLE_FMT_S16:
67 put_sample_s16(data, sample_fmt, channels, sample, ch, v_dbl);
68 break;
69 case AV_SAMPLE_FMT_S32:
70 put_sample_s32(data, sample_fmt, channels, sample, ch, v_dbl);
71 break;
72 case AV_SAMPLE_FMT_FLT:
73 put_sample_flt(data, sample_fmt, channels, sample, ch, v_dbl);
74 break;
75 case AV_SAMPLE_FMT_DBL:
76 put_sample_dbl(data, sample_fmt, channels, sample, ch, v_dbl);
77 break;
78 }
79 }
80
83 {
84 int i, ch, k;
89
90 #define PUT_SAMPLE put_sample(data, sample_fmt, channels, k, ch, v);
91
92 k = 0;
93
94 /* 1 second of single freq sinus at 1000 Hz */
95 a = 0;
96 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
97 v = sin(a) * 0.30;
98 for (ch = 0; ch < channels; ch++)
100 a +=
M_PI * 1000.0 * 2.0 / sample_rate;
101 }
102
103 /* 1 second of varying frequency between 100 and 10000 Hz */
104 a = 0;
105 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
106 v = sin(a) * 0.30;
107 for (ch = 0; ch < channels; ch++)
109 f = 100.0 + (((10000.0 - 100.0) * i) / sample_rate);
111 }
112
113 /* 0.5 second of low amplitude white noise */
114 for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
116 for (ch = 0; ch < channels; ch++)
118 }
119
120 /* 0.5 second of high amplitude white noise */
121 for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
123 for (ch = 0; ch < channels; ch++)
125 }
126
127 /* 1 second of unrelated ramps for each channel */
128 for (ch = 0; ch < channels; ch++) {
129 taba[ch] = 0;
132 }
133 for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
134 for (ch = 0; ch < channels; ch++) {
135 v = sin(taba[ch]) * 0.30;
137 f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) * i) /
sample_rate);
139 }
140 }
141
142 /* 2 seconds of 500 Hz with varying volume */
143 a = 0;
144 ampa = 0;
145 for (i = 0; i < 2 * sample_rate && k < nb_samples; i++, k++) {
146 for (ch = 0; ch < channels; ch++) {
147 double amp = (1.0 + sin(ampa)) * 0.15;
148 if (ch & 1)
149 amp = 0.30 - amp;
150 v = sin(a) * amp;
154 }
155 }
156 }
157
158 /* formats, rates, and layouts are ordered for priority in testing.
159 e.g. 'avresample-test 4 2 2' will test all input/output combinations of
160 S16/FLTP/S16P/FLT, 48000/44100, and stereo/mono */
161
173 };
174
176 48000,
177 44100,
178 16000
179 };
180
186 };
187
188 int main(
int argc,
char **argv)
189 {
195 unsigned int in_buf_size;
196 unsigned int out_buf_size;
199 int in_linesize;
200 int out_linesize;
201 uint64_t in_ch_layout;
202 int in_channels;
204 int in_rate;
205 uint64_t out_ch_layout;
206 int out_channels;
208 int out_rate;
209 int num_formats, num_rates, num_layouts;
210 int i, j, k, l,
m,
n;
211
212 num_formats = 2;
213 num_rates = 2;
214 num_layouts = 2;
215 if (argc > 1) {
218 "[<num sample rates> [<num channel layouts>]]]\n"
219 "Default is 2 2 2\n");
220 return 0;
221 }
222 num_formats = strtol(argv[1], NULL, 0);
224 }
225 if (argc > 2) {
226 num_rates = strtol(argv[2], NULL, 0);
228 }
229 if (argc > 3) {
230 num_layouts = strtol(argv[3], NULL, 0);
232 }
233
235
237
240 out_buf_size = in_buf_size;
241
243 if (!in_buf)
246 if (!out_buf)
248
250 if (!s) {
252 ret = 1;
254 }
255
256 for (i = 0; i < num_formats; i++) {
257 in_fmt = formats[i];
258 for (k = 0; k < num_layouts; k++) {
259 in_ch_layout = layouts[k];
261 for (m = 0; m < num_rates; m++) {
263
265 in_channels, in_rate * 6,
266 in_fmt, 0);
267 if (ret < 0) {
270 }
271 audiogen(&rnd, (
void **)in_data, in_fmt, in_channels, in_rate, in_rate * 6);
272
273 for (j = 0; j < num_formats; j++) {
274 out_fmt = formats[j];
275 for (l = 0; l < num_layouts; l++) {
276 out_ch_layout = layouts[l];
278 for (n = 0; n < num_rates; n++) {
280
283 in_channels, out_channels, in_rate, out_rate);
284
286 out_buf, out_channels,
287 out_rate * 6, out_fmt, 0);
288 if (ret < 0) {
291 }
292
299
301
303 if (ret < 0) {
306 }
307
309 in_data, in_linesize, in_rate * 6);
310 if (ret < 0) {
311 char errbuf[256];
315 }
317 in_rate * 6, ret);
325
327 }
328 }
329 }
330 }
331 }
332 }
333
334 ret = 0;
335
341 }