mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
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. |
||
|---|---|---|
| .. | ||
| examples | ||
| include | ||
| include-private/spa-private | ||
| plugins | ||
| tests | ||
| tools | ||
| meson.build | ||