pipewire/spa/plugins/audioconvert
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
..
audioadapter.c stream: improve async handling 2024-04-18 15:20:07 +02:00
audioconvert.c impl-port: add port.group property 2024-06-24 13:38:09 +02:00
benchmark-fmt-ops.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
benchmark-resample.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
biquad.c Fix compilation with -Werror=float-conversion 2024-06-18 12:17:56 +02:00
biquad.h Fix typos 2021-04-30 16:27:34 +00:00
channelmix-ops-c.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
channelmix-ops-sse.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
channelmix-ops.c Fix compilation with -Werror=float-conversion 2024-06-18 12:17:56 +02:00
channelmix-ops.h treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
crossover.c filter-chain: simplify biquads 2023-06-30 17:49:29 +02:00
crossover.h channelmix: improve corssover processing 2022-03-01 09:08:17 +01:00
delay.h treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
fmt-ops-avx2.c audioconvert: avoid even more precision loss in F32 to S32 conversion 2024-06-27 19:41:20 +03:00
fmt-ops-c.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
fmt-ops-neon.c audioconvert: fix typo in neon function 2023-08-24 13:45:11 +02:00
fmt-ops-sse2.c audioconvert: avoid even more precision loss in F32 to S32 conversion 2024-06-27 19:41:20 +03:00
fmt-ops-sse41.c audioconvert: avoid unaligned read 2023-10-15 22:20:54 +02:00
fmt-ops-ssse3.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
fmt-ops.c doc: clarify the dither.noise 2024-06-13 11:38:26 +02:00
fmt-ops.h audioconvert: avoid even more precision loss in F32 to S32 conversion 2024-06-27 19:41:20 +03:00
hilbert.h fix compilation some more 2024-06-18 15:41:12 +02:00
law.h treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
meson.build spa: deduplicate test-helper.h 2023-10-15 16:20:17 +00:00
peaks-ops-c.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
peaks-ops-sse.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
peaks-ops.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
peaks-ops.h treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
plugin.c spa: export log topic enumerations 2024-01-04 10:02:55 +00:00
resample-native-avx.c audioconvert: remove unnecessary casts 2024-01-16 15:33:13 +01:00
resample-native-c.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
resample-native-impl.h Fix compilation with -Werror=float-conversion 2024-06-18 12:17:56 +02:00
resample-native-neon.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
resample-native-sse.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
resample-native-ssse3.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
resample-native.c Fix compilation with -Werror=float-conversion 2024-06-18 12:17:56 +02:00
resample-peaks.c audioconvert: implement resample_out_len() 2024-01-16 13:28:37 +01:00
resample.h treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
spa-resample.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-audioadapter.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-audioconvert.c audioconvert: fix test 2023-03-22 15:41:06 +01:00
test-channelmix.c Fix compilation with -Werror=float-conversion 2024-06-18 12:17:56 +02:00
test-fmt-ops.c audioconvert: avoid even more precision loss in F32 to S32 conversion 2024-06-27 19:41:20 +03:00
test-peaks.c Fix compilation with -Werror=float-conversion 2024-06-18 12:17:56 +02:00
test-resample.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-source.c spa: use log topics everywhere 2024-03-11 18:45:21 +02:00
volume-ops-c.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
volume-ops-sse.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
volume-ops.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
volume-ops.h treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
wavfile.c wav: fix build 2023-03-09 17:09:47 +01:00
wavfile.h wav: fix build 2023-03-09 17:09:47 +01:00