mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
core: Refactor code to multiply s16 by volume
move code to function pa_mult_s16_volume() in sample-util.h use 64 bit integers on 64 bit platforms (it's faster) on i5, 2.5GHz (64-bit) Running suite(s): Mult-s16 32 bit mult: 1272300 usec (avg: 12723, min = 12533, max = 18749, stddev = 620.48). 64 bit mult: 852241 usec (avg: 8522.41, min = 8420, max = 9148, stddev = 109.388). 100%: Checks: 1, Failures: 0, Errors: 0 on Pentium D, 3.4GHz (32-bit) Running suite(s): Mult-s16 32 bit mult: 2228504 usec (avg: 22285, min = 18775, max = 29648, stddev = 3865.59). 64 bit mult: 5546861 usec (avg: 55468.6, min = 55028, max = 64924, stddev = 978.981). 100%: Checks: 1, Failures: 0, Errors: 0 on TI DM3730, Cortex-A8, 800MHz (32-bit) Running suite(s): Mult-s16 32 bit mult: 23708900 usec (avg: 237089, min = 191864, max = 557312, stddev = 77503.6). 64 bit mult: 22190039 usec (avg: 221900, min = 177978, max = 480469, stddev = 68520.5). 100%: Checks: 1, Failures: 0, Errors: 0 there is a test program called mult-s16-test which checks that the functions compute the same results, and compares runtime Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
This commit is contained in:
parent
b123cfa7c9
commit
8fa81a93c9
3 changed files with 37 additions and 92 deletions
|
|
@ -23,6 +23,9 @@
|
|||
USA.
|
||||
***/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <pulse/gccmacro.h>
|
||||
#include <pulse/sample.h>
|
||||
#include <pulse/volume.h>
|
||||
|
|
@ -53,6 +56,23 @@ void pa_deinterleave(const void *src, void *dst[], unsigned channels, size_t ss,
|
|||
|
||||
void pa_sample_clamp(pa_sample_format_t format, void *dst, size_t dstr, const void *src, size_t sstr, unsigned n);
|
||||
|
||||
static inline int32_t pa_mult_s16_volume(int16_t v, int32_t cv) {
|
||||
#if __WORDSIZE == 64 || ((ULONG_MAX) > (UINT_MAX))
|
||||
/* Multiply with 64 bit integers on 64 bit platforms */
|
||||
return (v * (int64_t) cv) >> 16;
|
||||
#else
|
||||
/* Multiplying the 32 bit volume factor with the
|
||||
* 16 bit sample might result in an 48 bit value. We
|
||||
* want to do without 64 bit integers and hence do
|
||||
* the multiplication independently for the HI and
|
||||
* LO part of the volume. */
|
||||
|
||||
int32_t hi = cv >> 16;
|
||||
int32_t lo = cv & 0xFFFF;
|
||||
return ((v * lo) >> 16) + (v * hi);
|
||||
#endif
|
||||
}
|
||||
|
||||
pa_usec_t pa_bytes_to_usec_round_up(uint64_t length, const pa_sample_spec *spec);
|
||||
size_t pa_usec_to_bytes_round_up(pa_usec_t t, const pa_sample_spec *spec);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue