]>
code.delx.au - pulseaudio/blob - src/tests/mix-test.c
1 /* $Id: resampler-test.c 2037 2007-11-09 02:45:07Z lennart $ */
4 This file is part of PulseAudio.
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <pulse/sample.h>
29 #include <pulse/volume.h>
31 #include <pulsecore/resampler.h>
32 #include <pulsecore/macro.h>
33 #include <pulsecore/endianmacros.h>
34 #include <pulsecore/memblock.h>
35 #include <pulsecore/sample-util.h>
37 #include <liboil/liboil.h>
39 static float swap_float(float a
) {
40 uint32_t *b
= (uint32_t*) &a
;
41 *b
= PA_UINT32_SWAP(*b
);
45 static void dump_block(const pa_sample_spec
*ss
, const pa_memchunk
*chunk
) {
49 d
= pa_memblock_acquire(chunk
->memblock
);
55 case PA_SAMPLE_ALAW
: {
58 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++)
59 printf("0x%02x ", *(u
++));
65 case PA_SAMPLE_S16RE
: {
68 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++)
69 printf("0x%04x ", *(u
++));
75 case PA_SAMPLE_S32RE
: {
78 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++)
79 printf("0x%08x ", *(u
++));
84 case PA_SAMPLE_FLOAT32NE
:
85 case PA_SAMPLE_FLOAT32RE
: {
88 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++) {
89 printf("%1.5f ", ss
->format
== PA_SAMPLE_FLOAT32NE
? *u
: swap_float(*u
));
97 pa_assert_not_reached();
102 pa_memblock_release(chunk
->memblock
);
105 static pa_memblock
* generate_block(pa_mempool
*pool
, const pa_sample_spec
*ss
) {
110 pa_assert_se(r
= pa_memblock_new(pool
, pa_frame_size(ss
) * 10));
111 d
= pa_memblock_acquire(r
);
113 switch (ss
->format
) {
117 case PA_SAMPLE_ALAW
: {
133 case PA_SAMPLE_S16NE
:
134 case PA_SAMPLE_S16RE
: {
150 case PA_SAMPLE_S32NE
:
151 case PA_SAMPLE_S32RE
: {
167 case PA_SAMPLE_FLOAT32NE
:
168 case PA_SAMPLE_FLOAT32RE
: {
182 if (ss
->format
== PA_SAMPLE_FLOAT32RE
)
183 for (i
= 0; i
< 10; i
++)
184 u
[i
] = swap_float(u
[i
]);
190 pa_assert_not_reached();
193 pa_memblock_release(r
);
198 int main(int argc
, char *argv
[]) {
204 pa_log_set_maximal_level(PA_LOG_DEBUG
);
206 pa_assert_se(pool
= pa_mempool_new(FALSE
));
211 v
.channels
= a
.channels
;
212 v
.values
[0] = pa_sw_volume_from_linear(0.9);
214 for (a
.format
= 0; a
.format
< PA_SAMPLE_MAX
; a
.format
++) {
219 printf("=== mixing: %s\n", pa_sample_format_to_string(a
.format
));
222 i
.memblock
= generate_block(pool
, &a
);
223 i
.length
= pa_memblock_get_length(i
.memblock
);
228 pa_memblock_ref(j
.memblock
);
229 pa_memchunk_make_writable(&j
, 0);
231 /* Adjust volume of the copy */
232 pa_volume_memchunk(&j
, &a
, &v
);
235 m
[0].volume
.values
[0] = PA_VOLUME_NORM
;
236 m
[0].volume
.channels
= a
.channels
;
238 m
[1].volume
.values
[0] = PA_VOLUME_NORM
;
239 m
[1].volume
.channels
= a
.channels
;
241 k
.memblock
= pa_memblock_new(pool
, i
.length
);
245 ptr
= (uint8_t*) pa_memblock_acquire(k
.memblock
) + k
.index
;
246 pa_mix(m
, 2, ptr
, k
.length
, &a
, NULL
, FALSE
);
247 pa_memblock_release(k
.memblock
);
253 pa_memblock_unref(i
.memblock
);
254 pa_memblock_unref(j
.memblock
);
255 pa_memblock_unref(k
.memblock
);
258 pa_mempool_free(pool
);