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 <pulse/timeval.h>
36 #include <pulsecore/log.h>
37 #include <pulsecore/macro.h>
38 #include <pulsecore/g711.h>
40 #include "sample-util.h"
41 #include "endianmacros.h"
43 #define PA_SILENCE_MAX (PA_PAGE_SIZE*16)
45 pa_memblock
*pa_silence_memblock(pa_memblock
* b
, const pa_sample_spec
*spec
) {
51 data
= pa_memblock_acquire(b
);
52 pa_silence_memory(data
, pa_memblock_get_length(b
), spec
);
53 pa_memblock_release(b
);
58 pa_memchunk
* pa_silence_memchunk(pa_memchunk
*c
, const pa_sample_spec
*spec
) {
62 pa_assert(c
->memblock
);
65 data
= pa_memblock_acquire(c
->memblock
);
66 pa_silence_memory((uint8_t*) data
+c
->index
, c
->length
, spec
);
67 pa_memblock_release(c
->memblock
);
72 static uint8_t silence_byte(pa_sample_format_t format
) {
80 case PA_SAMPLE_FLOAT32LE
:
81 case PA_SAMPLE_FLOAT32BE
:
88 pa_assert_not_reached();
92 void* pa_silence_memory(void *p
, size_t length
, const pa_sample_spec
*spec
) {
94 pa_assert(length
> 0);
97 memset(p
, silence_byte(spec
->format
), length
);
101 static void calc_linear_integer_volume(int32_t linear
[], const pa_cvolume
*volume
) {
107 for (channel
= 0; channel
< volume
->channels
; channel
++)
108 linear
[channel
] = (int32_t) lrint(pa_sw_volume_to_linear(volume
->values
[channel
]) * 0x10000);
111 static void calc_linear_float_volume(float linear
[], const pa_cvolume
*volume
) {
117 for (channel
= 0; channel
< volume
->channels
; channel
++)
118 linear
[channel
] = (float) pa_sw_volume_to_linear(volume
->values
[channel
]);
121 static void calc_linear_integer_stream_volumes(pa_mix_info streams
[], unsigned nstreams
, const pa_cvolume
*volume
, const pa_sample_spec
*spec
) {
123 float linear
[PA_CHANNELS_MAX
];
129 calc_linear_float_volume(linear
, volume
);
131 for (k
= 0; k
< nstreams
; k
++) {
133 for (channel
= 0; channel
< spec
->channels
; channel
++) {
134 pa_mix_info
*m
= streams
+ k
;
135 m
->linear
[channel
].i
= (int32_t) lrint(pa_sw_volume_to_linear(m
->volume
.values
[channel
]) * linear
[channel
] * 0x10000);
140 static void calc_linear_float_stream_volumes(pa_mix_info streams
[], unsigned nstreams
, const pa_cvolume
*volume
, const pa_sample_spec
*spec
) {
142 float linear
[PA_CHANNELS_MAX
];
148 calc_linear_float_volume(linear
, volume
);
150 for (k
= 0; k
< nstreams
; k
++) {
152 for (channel
= 0; channel
< spec
->channels
; channel
++) {
153 pa_mix_info
*m
= streams
+ k
;
154 m
->linear
[channel
].f
= (float) (pa_sw_volume_to_linear(m
->volume
.values
[channel
]) * linear
[channel
]);
160 pa_mix_info streams
[],
164 const pa_sample_spec
*spec
,
165 const pa_cvolume
*volume
,
168 pa_cvolume full_volume
;
179 volume
= pa_cvolume_reset(&full_volume
, spec
->channels
);
181 if (mute
|| pa_cvolume_is_muted(volume
) || nstreams
<= 0) {
182 pa_silence_memory(data
, length
, spec
);
186 for (k
= 0; k
< nstreams
; k
++)
187 streams
[k
].ptr
= (uint8_t*) pa_memblock_acquire(streams
[k
].chunk
.memblock
) + streams
[k
].chunk
.index
;
189 for (z
= 0; z
< nstreams
; z
++)
190 if (length
> streams
[z
].chunk
.length
)
191 length
= streams
[z
].chunk
.length
;
193 end
= (uint8_t*) data
+ length
;
195 switch (spec
->format
) {
197 case PA_SAMPLE_S16NE
:{
198 unsigned channel
= 0;
200 calc_linear_integer_stream_volumes(streams
, nstreams
, volume
, spec
);
206 for (i
= 0; i
< nstreams
; i
++) {
207 pa_mix_info
*m
= streams
+ i
;
208 int32_t v
, cv
= m
->linear
[channel
].i
;
210 if (PA_UNLIKELY(cv
<= 0))
213 v
= *((int16_t*) m
->ptr
);
214 v
= (v
* cv
) / 0x10000;
217 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(int16_t);
220 sum
= PA_CLAMP_UNLIKELY(sum
, -0x8000, 0x7FFF);
221 *((int16_t*) data
) = (int16_t) sum
;
223 data
= (uint8_t*) data
+ sizeof(int16_t);
225 if (PA_UNLIKELY(++channel
>= spec
->channels
))
232 case PA_SAMPLE_S16RE
:{
233 unsigned channel
= 0;
235 calc_linear_integer_stream_volumes(streams
, nstreams
, volume
, spec
);
241 for (i
= 0; i
< nstreams
; i
++) {
242 pa_mix_info
*m
= streams
+ i
;
243 int32_t v
, cv
= m
->linear
[channel
].i
;
245 if (PA_UNLIKELY(cv
<= 0))
248 v
= PA_INT16_SWAP(*((int16_t*) m
->ptr
));
249 v
= (v
* cv
) / 0x10000;
252 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(int16_t);
255 sum
= PA_CLAMP_UNLIKELY(sum
, -0x8000, 0x7FFF);
256 *((int16_t*) data
) = PA_INT16_SWAP((int16_t) sum
);
258 data
= (uint8_t*) data
+ sizeof(int16_t);
260 if (PA_UNLIKELY(++channel
>= spec
->channels
))
267 case PA_SAMPLE_S32NE
:{
268 unsigned channel
= 0;
270 calc_linear_integer_stream_volumes(streams
, nstreams
, volume
, spec
);
276 for (i
= 0; i
< nstreams
; i
++) {
277 pa_mix_info
*m
= streams
+ i
;
278 int32_t cv
= m
->linear
[channel
].i
;
281 if (PA_UNLIKELY(cv
<= 0))
284 v
= *((int32_t*) m
->ptr
);
285 v
= (v
* cv
) / 0x10000;
288 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(int32_t);
291 sum
= PA_CLAMP_UNLIKELY(sum
, -0x80000000LL
, 0x7FFFFFFFLL
);
292 *((int32_t*) data
) = (int32_t) sum
;
294 data
= (uint8_t*) data
+ sizeof(int32_t);
296 if (PA_UNLIKELY(++channel
>= spec
->channels
))
303 case PA_SAMPLE_S32RE
:{
304 unsigned channel
= 0;
306 calc_linear_integer_stream_volumes(streams
, nstreams
, volume
, spec
);
312 for (i
= 0; i
< nstreams
; i
++) {
313 pa_mix_info
*m
= streams
+ i
;
314 int32_t cv
= m
->linear
[channel
].i
;
317 if (PA_UNLIKELY(cv
<= 0))
320 v
= PA_INT32_SWAP(*((int32_t*) m
->ptr
));
321 v
= (v
* cv
) / 0x10000;
324 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(int32_t);
327 sum
= PA_CLAMP_UNLIKELY(sum
, -0x80000000LL
, 0x7FFFFFFFLL
);
328 *((int32_t*) data
) = PA_INT32_SWAP((int32_t) sum
);
330 data
= (uint8_t*) data
+ sizeof(int32_t);
332 if (PA_UNLIKELY(++channel
>= spec
->channels
))
340 unsigned channel
= 0;
342 calc_linear_integer_stream_volumes(streams
, nstreams
, volume
, spec
);
348 for (i
= 0; i
< nstreams
; i
++) {
349 pa_mix_info
*m
= streams
+ i
;
350 int32_t v
, cv
= m
->linear
[channel
].i
;
352 if (PA_UNLIKELY(cv
<= 0))
355 v
= (int32_t) *((uint8_t*) m
->ptr
) - 0x80;
356 v
= (v
* cv
) / 0x10000;
359 m
->ptr
= (uint8_t*) m
->ptr
+ 1;
362 sum
= PA_CLAMP_UNLIKELY(sum
, -0x80, 0x7F);
363 *((uint8_t*) data
) = (uint8_t) (sum
+ 0x80);
365 data
= (uint8_t*) data
+ 1;
367 if (PA_UNLIKELY(++channel
>= spec
->channels
))
374 case PA_SAMPLE_ULAW
: {
375 unsigned channel
= 0;
377 calc_linear_integer_stream_volumes(streams
, nstreams
, volume
, spec
);
383 for (i
= 0; i
< nstreams
; i
++) {
384 pa_mix_info
*m
= streams
+ i
;
385 int32_t v
, cv
= m
->linear
[channel
].i
;
387 if (PA_UNLIKELY(cv
<= 0))
390 v
= (int32_t) st_ulaw2linear16(*((uint8_t*) m
->ptr
));
391 v
= (v
* cv
) / 0x10000;
394 m
->ptr
= (uint8_t*) m
->ptr
+ 1;
397 sum
= PA_CLAMP_UNLIKELY(sum
, -0x8000, 0x7FFF);
398 *((uint8_t*) data
) = (uint8_t) st_14linear2ulaw((int16_t) sum
>> 2);
400 data
= (uint8_t*) data
+ 1;
402 if (PA_UNLIKELY(++channel
>= spec
->channels
))
409 case PA_SAMPLE_ALAW
: {
410 unsigned channel
= 0;
412 calc_linear_integer_stream_volumes(streams
, nstreams
, volume
, spec
);
418 for (i
= 0; i
< nstreams
; i
++) {
419 pa_mix_info
*m
= streams
+ i
;
420 int32_t v
, cv
= m
->linear
[channel
].i
;
422 if (PA_UNLIKELY(cv
<= 0))
425 v
= (int32_t) st_alaw2linear16(*((uint8_t*) m
->ptr
));
426 v
= (v
* cv
) / 0x10000;
429 m
->ptr
= (uint8_t*) m
->ptr
+ 1;
432 sum
= PA_CLAMP_UNLIKELY(sum
, -0x8000, 0x7FFF);
433 *((uint8_t*) data
) = (uint8_t) st_13linear2alaw((int16_t) sum
>> 3);
435 data
= (uint8_t*) data
+ 1;
437 if (PA_UNLIKELY(++channel
>= spec
->channels
))
444 case PA_SAMPLE_FLOAT32NE
: {
445 unsigned channel
= 0;
447 calc_linear_float_stream_volumes(streams
, nstreams
, volume
, spec
);
453 for (i
= 0; i
< nstreams
; i
++) {
454 pa_mix_info
*m
= streams
+ i
;
455 float v
, cv
= m
->linear
[channel
].f
;
457 if (PA_UNLIKELY(cv
<= 0))
460 v
= *((float*) m
->ptr
);
464 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(float);
467 *((float*) data
) = sum
;
469 data
= (uint8_t*) data
+ sizeof(float);
471 if (PA_UNLIKELY(++channel
>= spec
->channels
))
478 case PA_SAMPLE_FLOAT32RE
: {
479 unsigned channel
= 0;
480 float linear
[PA_CHANNELS_MAX
];
482 calc_linear_float_stream_volumes(streams
, nstreams
, volume
, spec
);
488 for (i
= 0; i
< nstreams
; i
++) {
489 pa_mix_info
*m
= streams
+ i
;
490 float v
, cv
= m
->linear
[channel
].f
;
492 if (PA_UNLIKELY(cv
<= 0))
495 v
= PA_FLOAT32_SWAP(*(float*) m
->ptr
);
499 m
->ptr
= (uint8_t*) m
->ptr
+ sizeof(float);
502 *((float*) data
) = PA_FLOAT32_SWAP(sum
);
504 data
= (uint8_t*) data
+ sizeof(float);
506 if (PA_UNLIKELY(++channel
>= spec
->channels
))
514 pa_log_error("Unable to mix audio data of format %s.", pa_sample_format_to_string(spec
->format
));
515 pa_assert_not_reached();
518 for (k
= 0; k
< nstreams
; k
++)
519 pa_memblock_release(streams
[k
].chunk
.memblock
);
525 void pa_volume_memchunk(
527 const pa_sample_spec
*spec
,
528 const pa_cvolume
*volume
) {
534 pa_assert(c
->length
% pa_frame_size(spec
) == 0);
537 if (pa_memblock_is_silence(c
->memblock
))
540 if (pa_cvolume_channels_equal_to(volume
, PA_VOLUME_NORM
))
543 if (pa_cvolume_channels_equal_to(volume
, PA_VOLUME_MUTED
)) {
544 pa_silence_memchunk(c
, spec
);
548 ptr
= (uint8_t*) pa_memblock_acquire(c
->memblock
) + c
->index
;
550 switch (spec
->format
) {
552 case PA_SAMPLE_S16NE
: {
555 int32_t linear
[PA_CHANNELS_MAX
];
557 calc_linear_integer_volume(linear
, volume
);
559 e
= (int16_t*) ptr
+ c
->length
/sizeof(int16_t);
561 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
565 t
= (t
* linear
[channel
]) / 0x10000;
566 t
= PA_CLAMP_UNLIKELY(t
, -0x8000, 0x7FFF);
569 if (PA_UNLIKELY(++channel
>= spec
->channels
))
575 case PA_SAMPLE_S16RE
: {
578 int32_t linear
[PA_CHANNELS_MAX
];
580 calc_linear_integer_volume(linear
, volume
);
582 e
= (int16_t*) ptr
+ c
->length
/sizeof(int16_t);
584 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
587 t
= (int32_t) PA_INT16_SWAP(*d
);
588 t
= (t
* linear
[channel
]) / 0x10000;
589 t
= PA_CLAMP_UNLIKELY(t
, -0x8000, 0x7FFF);
590 *d
= PA_INT16_SWAP((int16_t) t
);
592 if (PA_UNLIKELY(++channel
>= spec
->channels
))
599 case PA_SAMPLE_S32NE
: {
602 int32_t linear
[PA_CHANNELS_MAX
];
604 calc_linear_integer_volume(linear
, volume
);
606 e
= (int32_t*) ptr
+ c
->length
/sizeof(int32_t);
608 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
612 t
= (t
* linear
[channel
]) / 0x10000;
613 t
= PA_CLAMP_UNLIKELY(t
, -0x80000000LL
, 0x7FFFFFFFLL
);
616 if (PA_UNLIKELY(++channel
>= spec
->channels
))
622 case PA_SAMPLE_S32RE
: {
625 int32_t linear
[PA_CHANNELS_MAX
];
627 calc_linear_integer_volume(linear
, volume
);
629 e
= (int32_t*) ptr
+ c
->length
/sizeof(int32_t);
631 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
634 t
= (int64_t) PA_INT32_SWAP(*d
);
635 t
= (t
* linear
[channel
]) / 0x10000;
636 t
= PA_CLAMP_UNLIKELY(t
, -0x80000000LL
, 0x7FFFFFFFLL
);
637 *d
= PA_INT32_SWAP((int32_t) t
);
639 if (PA_UNLIKELY(++channel
>= spec
->channels
))
649 int32_t linear
[PA_CHANNELS_MAX
];
651 calc_linear_integer_volume(linear
, volume
);
653 e
= (uint8_t*) ptr
+ c
->length
;
655 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
658 t
= (int32_t) *d
- 0x80;
659 t
= (t
* linear
[channel
]) / 0x10000;
660 t
= PA_CLAMP_UNLIKELY(t
, -0x80, 0x7F);
661 *d
= (uint8_t) (t
+ 0x80);
663 if (PA_UNLIKELY(++channel
>= spec
->channels
))
669 case PA_SAMPLE_ULAW
: {
672 int32_t linear
[PA_CHANNELS_MAX
];
674 calc_linear_integer_volume(linear
, volume
);
676 e
= (uint8_t*) ptr
+ c
->length
;
678 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
681 t
= (int32_t) st_ulaw2linear16(*d
);
682 t
= (t
* linear
[channel
]) / 0x10000;
683 t
= PA_CLAMP_UNLIKELY(t
, -0x8000, 0x7FFF);
684 *d
= (uint8_t) st_14linear2ulaw((int16_t) t
>> 2);
686 if (PA_UNLIKELY(++channel
>= spec
->channels
))
692 case PA_SAMPLE_ALAW
: {
695 int32_t linear
[PA_CHANNELS_MAX
];
697 calc_linear_integer_volume(linear
, volume
);
699 e
= (uint8_t*) ptr
+ c
->length
;
701 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
704 t
= (int32_t) st_alaw2linear16(*d
);
705 t
= (t
* linear
[channel
]) / 0x10000;
706 t
= PA_CLAMP_UNLIKELY(t
, -0x8000, 0x7FFF);
707 *d
= (uint8_t) st_13linear2alaw((int16_t) t
>> 3);
709 if (PA_UNLIKELY(++channel
>= spec
->channels
))
715 case PA_SAMPLE_FLOAT32NE
: {
722 skip
= (int) (spec
->channels
* sizeof(float));
723 n
= (unsigned) (c
->length
/sizeof(float)/spec
->channels
);
725 for (channel
= 0; channel
< spec
->channels
; channel
++) {
728 if (PA_UNLIKELY(volume
->values
[channel
] == PA_VOLUME_NORM
))
731 v
= (float) pa_sw_volume_to_linear(volume
->values
[channel
]);
733 oil_scalarmult_f32(t
, skip
, t
, skip
, &v
, (int) n
);
738 case PA_SAMPLE_FLOAT32RE
: {
741 float linear
[PA_CHANNELS_MAX
];
743 calc_linear_float_volume(linear
, volume
);
745 e
= (float*) ptr
+ c
->length
/sizeof(float);
747 for (channel
= 0, d
= ptr
; d
< e
; d
++) {
750 t
= PA_FLOAT32_SWAP(*d
);
751 t
*= linear
[channel
];
752 *d
= PA_FLOAT32_SWAP(t
);
754 if (PA_UNLIKELY(++channel
>= spec
->channels
))
763 pa_log_warn(" Unable to change volume of format %s.", pa_sample_format_to_string(spec
->format
));
764 /* If we cannot change the volume, we just don't do it */
767 pa_memblock_release(c
->memblock
);
770 size_t pa_frame_align(size_t l
, const pa_sample_spec
*ss
) {
775 fs
= pa_frame_size(ss
);
780 pa_bool_t
pa_frame_aligned(size_t l
, const pa_sample_spec
*ss
) {
785 fs
= pa_frame_size(ss
);
790 void pa_interleave(const void *src
[], unsigned channels
, void *dst
, size_t ss
, unsigned n
) {
795 pa_assert(channels
> 0);
802 for (c
= 0; c
< channels
; c
++) {
808 d
= (uint8_t*) dst
+ c
* ss
;
810 for (j
= 0; j
< n
; j
++) {
811 oil_memcpy(d
, s
, (int) ss
);
812 s
= (uint8_t*) s
+ ss
;
813 d
= (uint8_t*) d
+ fs
;
818 void pa_deinterleave(const void *src
, void *dst
[], unsigned channels
, size_t ss
, unsigned n
) {
824 pa_assert(channels
> 0);
830 for (c
= 0; c
< channels
; c
++) {
835 s
= (uint8_t*) src
+ c
* ss
;
838 for (j
= 0; j
< n
; j
++) {
839 oil_memcpy(d
, s
, (int) ss
);
840 s
= (uint8_t*) s
+ fs
;
841 d
= (uint8_t*) d
+ ss
;
846 static pa_memblock
*silence_memblock_new(pa_mempool
*pool
, uint8_t c
) {
853 length
= PA_MIN(pa_mempool_block_size_max(pool
), PA_SILENCE_MAX
);
855 b
= pa_memblock_new(pool
, length
);
857 data
= pa_memblock_acquire(b
);
858 memset(data
, c
, length
);
859 pa_memblock_release(b
);
861 pa_memblock_set_is_silence(b
, TRUE
);
866 void pa_silence_cache_init(pa_silence_cache
*cache
) {
869 memset(cache
, 0, sizeof(pa_silence_cache
));
872 void pa_silence_cache_done(pa_silence_cache
*cache
) {
873 pa_sample_format_t f
;
876 for (f
= 0; f
< PA_SAMPLE_MAX
; f
++)
877 if (cache
->blocks
[f
])
878 pa_memblock_unref(cache
->blocks
[f
]);
880 memset(cache
, 0, sizeof(pa_silence_cache
));
883 pa_memchunk
* pa_silence_memchunk_get(pa_silence_cache
*cache
, pa_mempool
*pool
, pa_memchunk
* ret
, const pa_sample_spec
*spec
, size_t length
) {
888 pa_assert(pa_sample_spec_valid(spec
));
890 if (!(b
= cache
->blocks
[spec
->format
]))
892 switch (spec
->format
) {
894 cache
->blocks
[PA_SAMPLE_U8
] = b
= silence_memblock_new(pool
, 0x80);
896 case PA_SAMPLE_S16LE
:
897 case PA_SAMPLE_S16BE
:
898 case PA_SAMPLE_S32LE
:
899 case PA_SAMPLE_S32BE
:
900 case PA_SAMPLE_FLOAT32LE
:
901 case PA_SAMPLE_FLOAT32BE
:
902 cache
->blocks
[PA_SAMPLE_S16LE
] = b
= silence_memblock_new(pool
, 0);
903 cache
->blocks
[PA_SAMPLE_S16BE
] = pa_memblock_ref(b
);
904 cache
->blocks
[PA_SAMPLE_S32LE
] = pa_memblock_ref(b
);
905 cache
->blocks
[PA_SAMPLE_S32BE
] = pa_memblock_ref(b
);
906 cache
->blocks
[PA_SAMPLE_FLOAT32LE
] = pa_memblock_ref(b
);
907 cache
->blocks
[PA_SAMPLE_FLOAT32BE
] = pa_memblock_ref(b
);
910 cache
->blocks
[PA_SAMPLE_ALAW
] = b
= silence_memblock_new(pool
, 0xd5);
913 cache
->blocks
[PA_SAMPLE_ULAW
] = b
= silence_memblock_new(pool
, 0xff);
916 pa_assert_not_reached();
921 ret
->memblock
= pa_memblock_ref(b
);
923 l
= pa_memblock_get_length(b
);
924 if (length
> l
|| length
== 0)
927 ret
->length
= pa_frame_align(length
, spec
);
933 void pa_sample_clamp(pa_sample_format_t format
, void *dst
, size_t dstr
, const void *src
, size_t sstr
, unsigned n
) {
939 if (format
== PA_SAMPLE_FLOAT32NE
) {
941 float minus_one
= -1.0, plus_one
= 1.0;
942 oil_clip_f32(d
, (int) dstr
, s
, (int) sstr
, (int) n
, &minus_one
, &plus_one
);
945 pa_assert(format
== PA_SAMPLE_FLOAT32RE
);
950 f
= PA_FLOAT32_SWAP(*s
);
951 f
= PA_CLAMP_UNLIKELY(f
, -1.0f
, 1.0f
);
952 *d
= PA_FLOAT32_SWAP(f
);
954 s
= (const float*) ((const uint8_t*) s
+ sstr
);
955 d
= (float*) ((uint8_t*) d
+ dstr
);
960 /* Similar to pa_bytes_to_usec() but rounds up, not down */
962 pa_usec_t
pa_bytes_to_usec_round_up(uint64_t length
, const pa_sample_spec
*spec
) {
968 fs
= pa_frame_size(spec
);
969 length
= (length
+ fs
- 1) / fs
;
971 usec
= (pa_usec_t
) length
* PA_USEC_PER_SEC
;
973 return (usec
+ spec
->rate
- 1) / spec
->rate
;
976 /* Similar to pa_usec_to_bytes() but rounds up, not down */
978 size_t pa_usec_to_bytes_round_up(pa_usec_t t
, const pa_sample_spec
*spec
) {
982 u
= (uint64_t) t
* (uint64_t) spec
->rate
;
984 u
= (u
+ PA_USEC_PER_SEC
- 1) / PA_USEC_PER_SEC
;
986 u
*= pa_frame_size(spec
);