]>
code.delx.au - pulseaudio/blob - src/tests/resampler-test.c
2 This file is part of PulseAudio.
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License,
7 or (at your option) any later version.
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with PulseAudio; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <pulse/sample.h>
27 #include <pulse/volume.h>
29 #include <pulsecore/resampler.h>
30 #include <pulsecore/macro.h>
31 #include <pulsecore/endianmacros.h>
32 #include <pulsecore/memblock.h>
33 #include <pulsecore/sample-util.h>
35 #include <liboil/liboil.h>
37 static void dump_block(const pa_sample_spec
*ss
, const pa_memchunk
*chunk
) {
41 d
= pa_memblock_acquire(chunk
->memblock
);
47 case PA_SAMPLE_ALAW
: {
50 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++)
51 printf(" 0x%02x ", *(u
++));
57 case PA_SAMPLE_S16RE
: {
60 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++)
61 printf(" 0x%04x ", *(u
++));
67 case PA_SAMPLE_S32RE
: {
70 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++)
71 printf("0x%08x ", *(u
++));
76 case PA_SAMPLE_S24_32NE
:
77 case PA_SAMPLE_S24_32RE
: {
80 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++)
81 printf("0x%08x ", *(u
++));
86 case PA_SAMPLE_FLOAT32NE
:
87 case PA_SAMPLE_FLOAT32RE
: {
90 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++) {
91 printf("%4.3g ", ss
->format
== PA_SAMPLE_FLOAT32NE
? *u
: PA_FLOAT32_SWAP(*u
));
99 case PA_SAMPLE_S24BE
: {
102 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++) {
103 printf(" 0x%06x ", PA_READ24NE(u
));
104 u
+= pa_frame_size(ss
);
111 pa_assert_not_reached();
116 pa_memblock_release(chunk
->memblock
);
119 static pa_memblock
* generate_block(pa_mempool
*pool
, const pa_sample_spec
*ss
) {
124 pa_assert_se(r
= pa_memblock_new(pool
, pa_frame_size(ss
) * 10));
125 d
= pa_memblock_acquire(r
);
127 switch (ss
->format
) {
131 case PA_SAMPLE_ALAW
: {
147 case PA_SAMPLE_S16NE
:
148 case PA_SAMPLE_S16RE
: {
164 case PA_SAMPLE_S32NE
:
165 case PA_SAMPLE_S32RE
: {
181 case PA_SAMPLE_S24_32NE
:
182 case PA_SAMPLE_S24_32RE
: {
198 case PA_SAMPLE_FLOAT32NE
:
199 case PA_SAMPLE_FLOAT32RE
: {
213 if (ss
->format
== PA_SAMPLE_FLOAT32RE
)
214 for (i
= 0; i
< 10; i
++)
215 u
[i
] = PA_FLOAT32_SWAP(u
[i
]);
220 case PA_SAMPLE_S24NE
:
221 case PA_SAMPLE_S24RE
: {
224 PA_WRITE24NE(u
, 0x000001);
225 PA_WRITE24NE(u
+3, 0xFF0002);
226 PA_WRITE24NE(u
+6, 0x7F0003);
227 PA_WRITE24NE(u
+9, 0x800004);
228 PA_WRITE24NE(u
+12, 0x9f0005);
229 PA_WRITE24NE(u
+15, 0x3f0006);
230 PA_WRITE24NE(u
+18, 0x107);
231 PA_WRITE24NE(u
+21, 0xF00008);
232 PA_WRITE24NE(u
+24, 0x2009);
233 PA_WRITE24NE(u
+27, 0x210A);
238 pa_assert_not_reached();
241 pa_memblock_release(r
);
246 int main(int argc
, char *argv
[]) {
252 pa_log_set_level(PA_LOG_DEBUG
);
254 pa_assert_se(pool
= pa_mempool_new(FALSE
, 0));
256 a
.channels
= b
.channels
= 1;
257 a
.rate
= b
.rate
= 44100;
259 v
.channels
= a
.channels
;
260 v
.values
[0] = pa_sw_volume_from_linear(0.5);
262 for (a
.format
= 0; a
.format
< PA_SAMPLE_MAX
; a
.format
++) {
263 for (b
.format
= 0; b
.format
< PA_SAMPLE_MAX
; b
.format
++) {
264 pa_resampler
*forth
, *back
;
267 printf("=== %s -> %s -> %s -> /2\n",
268 pa_sample_format_to_string(a
.format
),
269 pa_sample_format_to_string(b
.format
),
270 pa_sample_format_to_string(a
.format
));
272 pa_assert_se(forth
= pa_resampler_new(pool
, &a
, NULL
, &b
, NULL
, PA_RESAMPLER_AUTO
, 0));
273 pa_assert_se(back
= pa_resampler_new(pool
, &b
, NULL
, &a
, NULL
, PA_RESAMPLER_AUTO
, 0));
275 i
.memblock
= generate_block(pool
, &a
);
276 i
.length
= pa_memblock_get_length(i
.memblock
);
278 pa_resampler_run(forth
, &i
, &j
);
279 pa_resampler_run(back
, &j
, &k
);
288 pa_memblock_unref(j
.memblock
);
289 pa_memblock_unref(k
.memblock
);
291 pa_volume_memchunk(&i
, &a
, &v
);
295 pa_memblock_unref(i
.memblock
);
297 pa_resampler_free(forth
);
298 pa_resampler_free(back
);
302 pa_mempool_free(pool
);