pipewire/spa
Roman Lebedev 7c40cafa7c
audioconvert: avoid even more precision loss in F32 to S32 conversion
This is somewhat similar to the S32->F32 conversion improvements,
but here things a bit more tricky...

The main consideration is that the limits to which we clamp
must be valid 32-bit signed integers, but not all such integers
are exactly losslessly representable in `float32_t`.

For example it we'd clamp to `2147483647`,
that is actually a `2147483648.0f`,
and `2147483648` is not a valid 32-bit signed integer,
so the post-clamp conversion would basically be UB.
We don't have this problem for negative bound, though.

But as we know, any 25-bit signed integer is losslessly
round-trippable through float32_t, and since multiplying by 2
only changes the float's exponent, we can clamp to `2147483520`!
The algorithm of selection of the pre-clamping scale is unaffected.

This additionally avoids right-shift, and thus is even faster.

As `test_lossless_s32_lossless_subset` shows,
if the integer is in the form of s25+shift,
the maximal absolute error is finally zero.

Without going through `float`->`double`->`int`,
i'm not sure if the `float`->`int` conversion
can be improved further.
2024-06-27 19:41:20 +03:00
..
examples examples: fix mapoffset in examples 2024-06-13 10:11:29 +02:00
include impl-port: add port.group property 2024-06-24 13:38:09 +02:00
include-private/spa-private spa: move dbus helpers out of bluez plugin 2024-02-05 13:03:20 +00:00
plugins audioconvert: avoid even more precision loss in F32 to S32 conversion 2024-06-27 19:41:20 +03:00
tests Add GNU/Hurd support 2023-09-24 15:11:52 +00:00
tools spa: improve JSON error reporting in spa-json-dump 2024-03-27 15:57:39 +01:00
meson.build meson: fix compilation when spa-plugins is disabled 2024-02-06 11:50:54 +01:00