2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #include <liboil/liboilfuncs.h>
32 #include <liboil/liboil.h>
34 #include <pulsecore/log.h>
35 #include <pulsecore/macro.h>
36 #include <pulsecore/g711.h>
38 #include "sample-util.h"
39 #include "endianmacros.h"
41 #define PA_SILENCE_MAX (PA_PAGE_SIZE*16)
43 pa_memblock
*pa_silence_memblock(pa_memblock
* b
, const pa_sample_spec
*spec
) {
49 data
= pa_memblock_acquire(b
);
50 pa_silence_memory(data
, pa_memblock_get_length(b
), spec
);
51 pa_memblock_release(b
);
56 pa_memchunk
* pa_silence_memchunk(pa_memchunk
*c
, const pa_sample_spec
*spec
) {
60 pa_assert(c
->memblock
);
63 data
= pa_memblock_acquire(c
->memblock
);
64 pa_silence_memory((uint8_t*) data
+c
->index
, c
->length
, spec
);
65 pa_memblock_release(c
->memblock
);
70 static uint8_t silence_byte(pa_sample_format_t format
) {
78 case PA_SAMPLE_FLOAT32LE
:
79 case PA_SAMPLE_FLOAT32BE
:
86 pa_assert_not_reached();
91 void* pa_silence_memory(void *p
, size_t length
, const pa_sample_spec
*spec
) {
93 pa_assert(length
> 0);
96 memset(p
, silence_byte(spec
->format
), length
);
100 static void calc_linear_integer_stream_volumes(pa_mix_info streams
[], unsigned nstreams
, const pa_sample_spec
*spec
) {
106 for (k
= 0; k
< nstreams
; k
++) {
109 for (channel
= 0; channel
< spec
->channels
; channel
++) {
110 pa_mix_info
*m
= streams
+ k
;
111 m
->linear
[channel
].i
= (int32_t) (pa_sw_volume_to_linear(m
->volume
.values
[channel
]) * 0x10000);
116 static void calc_linear_integer_volume(int32_t linear
[], const pa_cvolume
*volume
) {
122 for (channel
= 0; channel
< volume
->channels
; channel
++)
123 linear
[channel
] = (int32_t) (pa_sw_volume_to_linear(volume
->values
[channel
]) * 0x10000);
126 static void calc_linear_float_stream_volumes(pa_mix_info streams
[], unsigned nstreams
, const pa_sample_spec
*spec
) {
132 for (k
= 0; k
< nstreams
; k
++) {
135 for (channel
= 0; channel
< spec
->channels
; channel
++) {
136 pa_mix_info
*m
= streams
+ k
;
137 m
->linear
[channel
].f
= pa_sw_volume_to_linear(m
->volume
.values
[channel
]);
142 static void calc_linear_float_volume(float linear
[], const pa_cvolume
*volume
) {
148 for (channel
= 0; channel
< volume
->channels
; channel
++)
149 linear
[channel
] = pa_sw_volume_to_linear(volume
->values
[channel
]);
153 pa_mix_info streams
[],
157 const pa_sample_spec
*spec
,
158 const pa_cvolume
*volume
,
161 pa_cvolume full_volume
;
172 volume
= pa_cvolume_reset(&full_volume
, spec
->channels
);
174 if (mute
|| pa_cvolume_is_muted(volume
) || nstreams
<= 0) {
175 pa_silence_memory(data
, length
, spec
);
179 for (k
= 0; k
< nstreams
; k
++)
180 streams
[k
].ptr
= (uint8_t*) pa_memblock_acquire(streams
[k
].chunk
.memblock
) + streams
[k
].chunk
.index
;
182 for (z
= 0; z
< nstreams
; z
++)
183 if (length
> streams
[z
].chunk
.length
)
184 length
= streams
[z
].chunk
.length
;
186 end
= (uint8_t*) data
+ length
;
188 switch (spec
->format
) {
190 case PA_SAMPLE_S16NE
:{
191 unsigned channel
= 0;
192 int32_t linear
[PA_CHANNELS_MAX
];
194 calc_linear_integer_stream_volumes(streams
, nstreams
, spec
);
195 calc_linear_integer_volume(linear
, volume
);
201 for (i
= 0; i
< nstreams
; i
++) {
202 pa_mix_info
*m
= streams
+ i
;
203 int32_t v
, cv
= m
->linear
[channel
].i
;
205 if (PA_UNLIKELY(cv
<= 0) || PA_UNLIKELY(linear
[channel
] <= 0))
208 v
= *((int16_t*) m
->ptr
);
209 v
= (v
* cv
) / 0x10000;
213 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(int16_t);
216 sum
= (sum
* linear
[channel
]) / 0x10000;
217 sum
= PA_CLAMP_UNLIKELY(sum
, -0x8000, 0x7FFF);
218 *((int16_t*) data
) = (int16_t) sum
;
220 data
= (uint8_t*) data
+ sizeof(int16_t);
222 if (PA_UNLIKELY(++channel
>= spec
->channels
))
229 case PA_SAMPLE_S16RE
:{
230 unsigned channel
= 0;
231 int32_t linear
[PA_CHANNELS_MAX
];
233 calc_linear_integer_stream_volumes(streams
, nstreams
, spec
);
234 calc_linear_integer_volume(linear
, volume
);
240 for (i
= 0; i
< nstreams
; i
++) {
241 pa_mix_info
*m
= streams
+ i
;
242 int32_t v
, cv
= m
->linear
[channel
].i
;
244 if (PA_UNLIKELY(cv
<= 0) || PA_UNLIKELY(linear
[channel
] <= 0))
247 v
= PA_INT16_SWAP(*((int16_t*) m
->ptr
));
248 v
= (v
* cv
) / 0x10000;
252 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(int16_t);
255 sum
= (sum
* linear
[channel
]) / 0x10000;
256 sum
= PA_CLAMP_UNLIKELY(sum
, -0x8000, 0x7FFF);
257 *((int16_t*) data
) = PA_INT16_SWAP((int16_t) sum
);
259 data
= (uint8_t*) data
+ sizeof(int16_t);
261 if (PA_UNLIKELY(++channel
>= spec
->channels
))
268 case PA_SAMPLE_S32NE
:{
269 unsigned channel
= 0;
270 int32_t linear
[PA_CHANNELS_MAX
];
272 calc_linear_integer_stream_volumes(streams
, nstreams
, spec
);
273 calc_linear_integer_volume(linear
, volume
);
279 for (i
= 0; i
< nstreams
; i
++) {
280 pa_mix_info
*m
= streams
+ i
;
282 int32_t cv
= m
->linear
[channel
].i
;
284 if (PA_UNLIKELY(cv
<= 0) || PA_UNLIKELY(linear
[channel
] <= 0))
287 v
= *((int32_t*) m
->ptr
);
288 v
= (v
* cv
) / 0x10000;
292 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(int32_t);
295 sum
= (sum
* linear
[channel
]) / 0x10000;
296 sum
= PA_CLAMP_UNLIKELY(sum
, -0x80000000LL
, 0x7FFFFFFFLL
);
297 *((int32_t*) data
) = (int32_t) sum
;
299 data
= (uint8_t*) data
+ sizeof(int32_t);
301 if (PA_UNLIKELY(++channel
>= spec
->channels
))
308 case PA_SAMPLE_S32RE
:{
309 unsigned channel
= 0;
310 int32_t linear
[PA_CHANNELS_MAX
];
312 calc_linear_integer_stream_volumes(streams
, nstreams
, spec
);
313 calc_linear_integer_volume(linear
, volume
);
319 for (i
= 0; i
< nstreams
; i
++) {
320 pa_mix_info
*m
= streams
+ i
;
322 int32_t cv
= m
->linear
[channel
].i
;
324 if (PA_UNLIKELY(cv
<= 0) || PA_UNLIKELY(linear
[channel
] <= 0))
327 v
= PA_INT32_SWAP(*((int32_t*) m
->ptr
));
328 v
= (v
* cv
) / 0x10000;
332 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(int32_t);
335 sum
= (sum
* linear
[channel
]) / 0x10000;
336 sum
= PA_CLAMP_UNLIKELY(sum
, -0x80000000LL
, 0x7FFFFFFFLL
);
337 *((int32_t*) data
) = PA_INT32_SWAP((int32_t) sum
);
339 data
= (uint8_t*) data
+ sizeof(int32_t);
341 if (PA_UNLIKELY(++channel
>= spec
->channels
))
349 unsigned channel
= 0;
350 int32_t linear
[PA_CHANNELS_MAX
];
352 calc_linear_integer_stream_volumes(streams
, nstreams
, spec
);
353 calc_linear_integer_volume(linear
, volume
);
359 for (i
= 0; i
< nstreams
; i
++) {
360 pa_mix_info
*m
= streams
+ i
;
361 int32_t v
, cv
= m
->linear
[channel
].i
;
363 if (PA_UNLIKELY(cv
<= 0) || PA_UNLIKELY(linear
[channel
] <= 0))
366 v
= (int32_t) *((uint8_t*) m
->ptr
) - 0x80;
367 v
= (v
* cv
) / 0x10000;
371 m
->ptr
= (uint8_t*) m
->ptr
+ 1;
374 sum
= (sum
* linear
[channel
]) / 0x10000;
375 sum
= PA_CLAMP_UNLIKELY(sum
, -0x80, 0x7F);
376 *((uint8_t*) data
) = (uint8_t) (sum
+ 0x80);
378 data
= (uint8_t*) data
+ 1;
380 if (PA_UNLIKELY(++channel
>= spec
->channels
))
387 case PA_SAMPLE_ULAW
: {
388 unsigned channel
= 0;
389 int32_t linear
[PA_CHANNELS_MAX
];
391 calc_linear_integer_stream_volumes(streams
, nstreams
, spec
);
392 calc_linear_integer_volume(linear
, volume
);
398 for (i
= 0; i
< nstreams
; i
++) {
399 pa_mix_info
*m
= streams
+ i
;
400 int32_t v
, cv
= m
->linear
[channel
].i
;
402 if (PA_UNLIKELY(cv
<= 0) || PA_UNLIKELY(linear
[channel
] <= 0))
405 v
= (int32_t) st_ulaw2linear16(*((uint8_t*) m
->ptr
));
406 v
= (v
* cv
) / 0x10000;
410 m
->ptr
= (uint8_t*) m
->ptr
+ 1;
413 sum
= (sum
* linear
[channel
]) / 0x10000;
414 sum
= PA_CLAMP_UNLIKELY(sum
, -0x8000, 0x7FFF);
415 *((uint8_t*) data
) = (uint8_t) st_14linear2ulaw(sum
>> 2);
417 data
= (uint8_t*) data
+ 1;
419 if (PA_UNLIKELY(++channel
>= spec
->channels
))
426 case PA_SAMPLE_ALAW
: {
427 unsigned channel
= 0;
428 int32_t linear
[PA_CHANNELS_MAX
];
430 calc_linear_integer_stream_volumes(streams
, nstreams
, spec
);
431 calc_linear_integer_volume(linear
, volume
);
437 for (i
= 0; i
< nstreams
; i
++) {
438 pa_mix_info
*m
= streams
+ i
;
439 int32_t v
, cv
= m
->linear
[channel
].i
;
441 if (PA_UNLIKELY(cv
<= 0) || PA_UNLIKELY(linear
[channel
] <= 0))
444 v
= (int32_t) st_alaw2linear16(*((uint8_t*) m
->ptr
));
445 v
= (v
* cv
) / 0x10000;
449 m
->ptr
= (uint8_t*) m
->ptr
+ 1;
452 sum
= (sum
* linear
[channel
]) / 0x10000;
453 sum
= PA_CLAMP_UNLIKELY(sum
, -0x8000, 0x7FFF);
454 *((uint8_t*) data
) = (uint8_t) st_13linear2alaw(sum
>> 3);
456 data
= (uint8_t*) data
+ 1;
458 if (PA_UNLIKELY(++channel
>= spec
->channels
))
465 case PA_SAMPLE_FLOAT32NE
: {
466 unsigned channel
= 0;
467 float linear
[PA_CHANNELS_MAX
];
469 calc_linear_float_stream_volumes(streams
, nstreams
, spec
);
470 calc_linear_float_volume(linear
, volume
);
476 for (i
= 0; i
< nstreams
; i
++) {
477 pa_mix_info
*m
= streams
+ i
;
478 float v
, cv
= m
->linear
[channel
].f
;
480 if (PA_UNLIKELY(cv
<= 0) || PA_UNLIKELY(linear
[channel
] <= 0))
483 v
= *((float*) m
->ptr
);
488 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(float);
491 sum
*= linear
[channel
];
492 *((float*) data
) = sum
;
494 data
= (uint8_t*) data
+ sizeof(float);
496 if (PA_UNLIKELY(++channel
>= spec
->channels
))
503 case PA_SAMPLE_FLOAT32RE
: {
504 unsigned channel
= 0;
505 float linear
[PA_CHANNELS_MAX
];
507 calc_linear_float_stream_volumes(streams
, nstreams
, spec
);
508 calc_linear_float_volume(linear
, volume
);
514 for (i
= 0; i
< nstreams
; i
++) {
515 pa_mix_info
*m
= streams
+ i
;
516 float v
, cv
= m
->linear
[channel
].f
;
518 if (PA_UNLIKELY(cv
<= 0) || PA_UNLIKELY(linear
[channel
] <= 0))
521 v
= PA_FLOAT32_SWAP(*(float*) m
->ptr
) *cv
;
524 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(float);
527 sum
*= linear
[channel
];
528 *((float*) data
) = PA_FLOAT32_SWAP(sum
);
530 data
= (uint8_t*) data
+ sizeof(float);
532 if (PA_UNLIKELY(++channel
>= spec
->channels
))
540 pa_log_error("Unable to mix audio data of format %s.", pa_sample_format_to_string(spec
->format
));
541 pa_assert_not_reached();
544 for (k
= 0; k
< nstreams
; k
++)
545 pa_memblock_release(streams
[k
].chunk
.memblock
);
551 void pa_volume_memchunk(
553 const pa_sample_spec
*spec
,
554 const pa_cvolume
*volume
) {
560 pa_assert(c
->length
% pa_frame_size(spec
) == 0);
563 if (pa_memblock_is_silence(c
->memblock
))
566 if (pa_cvolume_channels_equal_to(volume
, PA_VOLUME_NORM
))
569 if (pa_cvolume_channels_equal_to(volume
, PA_VOLUME_MUTED
)) {
570 pa_silence_memchunk(c
, spec
);
574 ptr
= (uint8_t*) pa_memblock_acquire(c
->memblock
) + c
->index
;
576 switch (spec
->format
) {
578 case PA_SAMPLE_S16NE
: {
581 int32_t linear
[PA_CHANNELS_MAX
];
583 calc_linear_integer_volume(linear
, volume
);
585 e
= (int16_t*) ptr
+ c
->length
/sizeof(int16_t);
587 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
591 t
= (t
* linear
[channel
]) / 0x10000;
592 t
= PA_CLAMP_UNLIKELY(t
, -0x8000, 0x7FFF);
595 if (PA_UNLIKELY(++channel
>= spec
->channels
))
601 case PA_SAMPLE_S16RE
: {
604 int32_t linear
[PA_CHANNELS_MAX
];
606 calc_linear_integer_volume(linear
, volume
);
608 e
= (int16_t*) ptr
+ c
->length
/sizeof(int16_t);
610 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
613 t
= (int32_t) PA_INT16_SWAP(*d
);
614 t
= (t
* linear
[channel
]) / 0x10000;
615 t
= PA_CLAMP_UNLIKELY(t
, -0x8000, 0x7FFF);
616 *d
= PA_INT16_SWAP((int16_t) t
);
618 if (PA_UNLIKELY(++channel
>= spec
->channels
))
625 case PA_SAMPLE_S32NE
: {
628 int32_t linear
[PA_CHANNELS_MAX
];
630 calc_linear_integer_volume(linear
, volume
);
632 e
= (int32_t*) ptr
+ c
->length
/sizeof(int32_t);
634 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
638 t
= (t
* linear
[channel
]) / 0x10000;
639 t
= PA_CLAMP_UNLIKELY(t
, -0x80000000LL
, 0x7FFFFFFFLL
);
642 if (PA_UNLIKELY(++channel
>= spec
->channels
))
648 case PA_SAMPLE_S32RE
: {
651 int32_t linear
[PA_CHANNELS_MAX
];
653 calc_linear_integer_volume(linear
, volume
);
655 e
= (int32_t*) ptr
+ c
->length
/sizeof(int32_t);
657 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
660 t
= (int64_t) PA_INT32_SWAP(*d
);
661 t
= (t
* linear
[channel
]) / 0x10000;
662 t
= PA_CLAMP_UNLIKELY(t
, -0x80000000LL
, 0x7FFFFFFFLL
);
663 *d
= PA_INT32_SWAP((int32_t) t
);
665 if (PA_UNLIKELY(++channel
>= spec
->channels
))
675 int32_t linear
[PA_CHANNELS_MAX
];
677 calc_linear_integer_volume(linear
, volume
);
679 e
= (uint8_t*) ptr
+ c
->length
;
681 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
684 t
= (int32_t) *d
- 0x80;
685 t
= (t
* linear
[channel
]) / 0x10000;
686 t
= PA_CLAMP_UNLIKELY(t
, -0x80, 0x7F);
687 *d
= (uint8_t) (t
+ 0x80);
689 if (PA_UNLIKELY(++channel
>= spec
->channels
))
695 case PA_SAMPLE_ULAW
: {
698 int32_t linear
[PA_CHANNELS_MAX
];
700 calc_linear_integer_volume(linear
, volume
);
702 e
= (uint8_t*) ptr
+ c
->length
;
704 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
707 t
= (int32_t) st_ulaw2linear16(*d
);
708 t
= (t
* linear
[channel
]) / 0x10000;
709 t
= PA_CLAMP_UNLIKELY(t
, -0x8000, 0x7FFF);
710 *d
= (uint8_t) st_14linear2ulaw(t
>> 2);
712 if (PA_UNLIKELY(++channel
>= spec
->channels
))
718 case PA_SAMPLE_ALAW
: {
721 int32_t linear
[PA_CHANNELS_MAX
];
723 calc_linear_integer_volume(linear
, volume
);
725 e
= (uint8_t*) ptr
+ c
->length
;
727 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
730 t
= (int32_t) st_alaw2linear16(*d
);
731 t
= (t
* linear
[channel
]) / 0x10000;
732 t
= PA_CLAMP_UNLIKELY(t
, -0x8000, 0x7FFF);
733 *d
= (uint8_t) st_13linear2alaw(t
>> 3);
735 if (PA_UNLIKELY(++channel
>= spec
->channels
))
741 case PA_SAMPLE_FLOAT32NE
: {
748 skip
= spec
->channels
* sizeof(float);
749 n
= c
->length
/sizeof(float)/spec
->channels
;
751 for (channel
= 0; channel
< spec
->channels
; channel
++) {
754 if (PA_UNLIKELY(volume
->values
[channel
] == PA_VOLUME_NORM
))
757 v
= (float) pa_sw_volume_to_linear(volume
->values
[channel
]);
759 oil_scalarmult_f32(t
, skip
, t
, skip
, &v
, n
);
764 case PA_SAMPLE_FLOAT32RE
: {
767 float linear
[PA_CHANNELS_MAX
];
769 calc_linear_float_volume(linear
, volume
);
771 e
= (float*) ptr
+ c
->length
/sizeof(float);
773 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
776 t
= PA_FLOAT32_SWAP(*d
);
777 t
*= linear
[channel
];
778 *d
= PA_FLOAT32_SWAP(t
);
780 if (PA_UNLIKELY(++channel
>= spec
->channels
))
789 pa_log_warn(" Unable to change volume of format %s.", pa_sample_format_to_string(spec
->format
));
790 /* If we cannot change the volume, we just don't do it */
793 pa_memblock_release(c
->memblock
);
796 size_t pa_frame_align(size_t l
, const pa_sample_spec
*ss
) {
801 fs
= pa_frame_size(ss
);
806 int pa_frame_aligned(size_t l
, const pa_sample_spec
*ss
) {
811 fs
= pa_frame_size(ss
);
816 void pa_interleave(const void *src
[], unsigned channels
, void *dst
, size_t ss
, unsigned n
) {
821 pa_assert(channels
> 0);
828 for (c
= 0; c
< channels
; c
++) {
834 d
= (uint8_t*) dst
+ c
* ss
;
836 for (j
= 0; j
< n
; j
++) {
837 oil_memcpy(d
, s
, ss
);
838 s
= (uint8_t*) s
+ ss
;
839 d
= (uint8_t*) d
+ fs
;
844 void pa_deinterleave(const void *src
, void *dst
[], unsigned channels
, size_t ss
, unsigned n
) {
850 pa_assert(channels
> 0);
856 for (c
= 0; c
< channels
; c
++) {
861 s
= (uint8_t*) src
+ c
* ss
;
864 for (j
= 0; j
< n
; j
++) {
865 oil_memcpy(d
, s
, ss
);
866 s
= (uint8_t*) s
+ fs
;
867 d
= (uint8_t*) d
+ ss
;
872 static pa_memblock
*silence_memblock_new(pa_mempool
*pool
, uint8_t c
) {
879 length
= PA_MIN(pa_mempool_block_size_max(pool
), PA_SILENCE_MAX
);
881 b
= pa_memblock_new(pool
, length
);
883 data
= pa_memblock_acquire(b
);
884 memset(data
, c
, length
);
885 pa_memblock_release(b
);
887 pa_memblock_set_is_silence(b
, TRUE
);
892 void pa_silence_cache_init(pa_silence_cache
*cache
) {
895 memset(cache
, 0, sizeof(pa_silence_cache
));
898 void pa_silence_cache_done(pa_silence_cache
*cache
) {
899 pa_sample_format_t f
;
902 for (f
= 0; f
< PA_SAMPLE_MAX
; f
++)
903 if (cache
->blocks
[f
])
904 pa_memblock_unref(cache
->blocks
[f
]);
906 memset(cache
, 0, sizeof(pa_silence_cache
));
909 pa_memchunk
* pa_silence_memchunk_get(pa_silence_cache
*cache
, pa_mempool
*pool
, pa_memchunk
* ret
, const pa_sample_spec
*spec
, size_t length
) {
914 pa_assert(pa_sample_spec_valid(spec
));
916 if (!(b
= cache
->blocks
[spec
->format
]))
918 switch (spec
->format
) {
920 cache
->blocks
[PA_SAMPLE_U8
] = b
= silence_memblock_new(pool
, 0x80);
922 case PA_SAMPLE_S16LE
:
923 case PA_SAMPLE_S16BE
:
924 case PA_SAMPLE_S32LE
:
925 case PA_SAMPLE_S32BE
:
926 case PA_SAMPLE_FLOAT32LE
:
927 case PA_SAMPLE_FLOAT32BE
:
928 cache
->blocks
[PA_SAMPLE_S16LE
] = b
= silence_memblock_new(pool
, 0);
929 cache
->blocks
[PA_SAMPLE_S16BE
] = pa_memblock_ref(b
);
930 cache
->blocks
[PA_SAMPLE_S32LE
] = pa_memblock_ref(b
);
931 cache
->blocks
[PA_SAMPLE_S32BE
] = pa_memblock_ref(b
);
932 cache
->blocks
[PA_SAMPLE_FLOAT32LE
] = pa_memblock_ref(b
);
933 cache
->blocks
[PA_SAMPLE_FLOAT32BE
] = pa_memblock_ref(b
);
936 cache
->blocks
[PA_SAMPLE_ALAW
] = b
= silence_memblock_new(pool
, 0xd5);
939 cache
->blocks
[PA_SAMPLE_ULAW
] = b
= silence_memblock_new(pool
, 0xff);
942 pa_assert_not_reached();
947 ret
->memblock
= pa_memblock_ref(b
);
949 l
= pa_memblock_get_length(b
);
950 if (length
> l
|| length
== 0)
953 ret
->length
= pa_frame_align(length
, spec
);
959 void pa_sample_clamp(pa_sample_format_t format
, void *dst
, size_t dstr
, const void *src
, size_t sstr
, unsigned n
) {
965 if (format
== PA_SAMPLE_FLOAT32NE
) {
967 float minus_one
= -1.0, plus_one
= 1.0;
968 oil_clip_f32(d
, dstr
, s
, sstr
, n
, &minus_one
, &plus_one
);
971 pa_assert(format
== PA_SAMPLE_FLOAT32RE
);
976 f
= PA_FLOAT32_SWAP(*s
);
977 f
= PA_CLAMP_UNLIKELY(f
, -1.0, 1.0);
978 *d
= PA_FLOAT32_SWAP(f
);
980 s
= (const float*) ((const uint8_t*) s
+ sstr
);
981 d
= (float*) ((uint8_t*) d
+ dstr
);