]>
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_FLOAT32NE
:
77 case PA_SAMPLE_FLOAT32RE
: {
80 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++) {
81 printf("%4.3g ", ss
->format
== PA_SAMPLE_FLOAT32NE
? *u
: PA_FLOAT32_SWAP(*u
));
89 pa_assert_not_reached();
94 pa_memblock_release(chunk
->memblock
);
97 static pa_memblock
* generate_block(pa_mempool
*pool
, const pa_sample_spec
*ss
) {
102 pa_assert_se(r
= pa_memblock_new(pool
, pa_frame_size(ss
) * 10));
103 d
= pa_memblock_acquire(r
);
105 switch (ss
->format
) {
109 case PA_SAMPLE_ALAW
: {
125 case PA_SAMPLE_S16NE
:
126 case PA_SAMPLE_S16RE
: {
142 case PA_SAMPLE_S32NE
:
143 case PA_SAMPLE_S32RE
: {
159 case PA_SAMPLE_FLOAT32NE
:
160 case PA_SAMPLE_FLOAT32RE
: {
174 if (ss
->format
== PA_SAMPLE_FLOAT32RE
)
175 for (i
= 0; i
< 10; i
++)
176 u
[i
] = PA_FLOAT32_SWAP(u
[i
]);
182 pa_assert_not_reached();
185 pa_memblock_release(r
);
190 int main(int argc
, char *argv
[]) {
196 pa_log_set_level(PA_LOG_DEBUG
);
198 pa_assert_se(pool
= pa_mempool_new(FALSE
, 0));
200 a
.channels
= b
.channels
= 1;
201 a
.rate
= b
.rate
= 44100;
203 v
.channels
= a
.channels
;
204 v
.values
[0] = pa_sw_volume_from_linear(0.5);
206 for (a
.format
= 0; a
.format
< PA_SAMPLE_MAX
; a
.format
++) {
207 for (b
.format
= 0; b
.format
< PA_SAMPLE_MAX
; b
.format
++) {
209 pa_resampler
*forth
, *back
;
212 printf("=== %s -> %s -> %s -> /2\n",
213 pa_sample_format_to_string(a
.format
),
214 pa_sample_format_to_string(b
.format
),
215 pa_sample_format_to_string(a
.format
));
217 pa_assert_se(forth
= pa_resampler_new(pool
, &a
, NULL
, &b
, NULL
, PA_RESAMPLER_AUTO
, 0));
218 pa_assert_se(back
= pa_resampler_new(pool
, &b
, NULL
, &a
, NULL
, PA_RESAMPLER_AUTO
, 0));
220 i
.memblock
= generate_block(pool
, &a
);
221 i
.length
= pa_memblock_get_length(i
.memblock
);
223 pa_resampler_run(forth
, &i
, &j
);
224 pa_resampler_run(back
, &j
, &k
);
230 pa_memblock_unref(j
.memblock
);
231 pa_memblock_unref(k
.memblock
);
233 pa_volume_memchunk(&i
, &a
, &v
);
236 pa_memblock_unref(i
.memblock
);
238 pa_resampler_free(forth
);
239 pa_resampler_free(back
);
243 pa_mempool_free(pool
);