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 static void dump_block(const pa_sample_spec
*ss
, const pa_memchunk
*chunk
) {
39 d
= pa_memblock_acquire(chunk
->memblock
);
45 case PA_SAMPLE_ALAW
: {
48 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++)
49 printf(" 0x%02x ", *(u
++));
55 case PA_SAMPLE_S16RE
: {
58 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++)
59 printf(" 0x%04x ", *(u
++));
65 case PA_SAMPLE_S32RE
: {
68 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++)
69 printf("0x%08x ", *(u
++));
74 case PA_SAMPLE_S24_32NE
:
75 case PA_SAMPLE_S24_32RE
: {
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("%4.3g ", ss
->format
== PA_SAMPLE_FLOAT32NE
? *u
: PA_FLOAT32_SWAP(*u
));
97 case PA_SAMPLE_S24BE
: {
100 for (i
= 0; i
< chunk
->length
/ pa_frame_size(ss
); i
++) {
101 printf(" 0x%06x ", PA_READ24NE(u
));
102 u
+= pa_frame_size(ss
);
109 pa_assert_not_reached();
114 pa_memblock_release(chunk
->memblock
);
117 static pa_memblock
* generate_block(pa_mempool
*pool
, const pa_sample_spec
*ss
) {
122 pa_assert_se(r
= pa_memblock_new(pool
, pa_frame_size(ss
) * 10));
123 d
= pa_memblock_acquire(r
);
125 switch (ss
->format
) {
129 case PA_SAMPLE_ALAW
: {
145 case PA_SAMPLE_S16NE
:
146 case PA_SAMPLE_S16RE
: {
162 case PA_SAMPLE_S32NE
:
163 case PA_SAMPLE_S32RE
: {
179 case PA_SAMPLE_S24_32NE
:
180 case PA_SAMPLE_S24_32RE
: {
196 case PA_SAMPLE_FLOAT32NE
:
197 case PA_SAMPLE_FLOAT32RE
: {
211 if (ss
->format
== PA_SAMPLE_FLOAT32RE
)
212 for (i
= 0; i
< 10; i
++)
213 u
[i
] = PA_FLOAT32_SWAP(u
[i
]);
218 case PA_SAMPLE_S24NE
:
219 case PA_SAMPLE_S24RE
: {
222 PA_WRITE24NE(u
, 0x000001);
223 PA_WRITE24NE(u
+3, 0xFF0002);
224 PA_WRITE24NE(u
+6, 0x7F0003);
225 PA_WRITE24NE(u
+9, 0x800004);
226 PA_WRITE24NE(u
+12, 0x9f0005);
227 PA_WRITE24NE(u
+15, 0x3f0006);
228 PA_WRITE24NE(u
+18, 0x107);
229 PA_WRITE24NE(u
+21, 0xF00008);
230 PA_WRITE24NE(u
+24, 0x2009);
231 PA_WRITE24NE(u
+27, 0x210A);
236 pa_assert_not_reached();
239 pa_memblock_release(r
);
244 int main(int argc
, char *argv
[]) {
249 pa_log_set_level(PA_LOG_DEBUG
);
251 pa_assert_se(pool
= pa_mempool_new(FALSE
, 0));
253 a
.channels
= b
.channels
= 1;
254 a
.rate
= b
.rate
= 44100;
256 v
.channels
= a
.channels
;
257 v
.values
[0] = pa_sw_volume_from_linear(0.5);
259 for (a
.format
= 0; a
.format
< PA_SAMPLE_MAX
; a
.format
++) {
260 for (b
.format
= 0; b
.format
< PA_SAMPLE_MAX
; b
.format
++) {
261 pa_resampler
*forth
, *back
;
264 printf("=== %s -> %s -> %s -> /2\n",
265 pa_sample_format_to_string(a
.format
),
266 pa_sample_format_to_string(b
.format
),
267 pa_sample_format_to_string(a
.format
));
269 pa_assert_se(forth
= pa_resampler_new(pool
, &a
, NULL
, &b
, NULL
, PA_RESAMPLER_AUTO
, 0));
270 pa_assert_se(back
= pa_resampler_new(pool
, &b
, NULL
, &a
, NULL
, PA_RESAMPLER_AUTO
, 0));
272 i
.memblock
= generate_block(pool
, &a
);
273 i
.length
= pa_memblock_get_length(i
.memblock
);
275 pa_resampler_run(forth
, &i
, &j
);
276 pa_resampler_run(back
, &j
, &k
);
285 pa_memblock_unref(j
.memblock
);
286 pa_memblock_unref(k
.memblock
);
288 pa_volume_memchunk(&i
, &a
, &v
);
292 pa_memblock_unref(i
.memblock
);
294 pa_resampler_free(forth
);
295 pa_resampler_free(back
);
299 pa_mempool_free(pool
);