Commit graph

51 commits

Author SHA1 Message Date
Wim Taymans
d22feab92a spa: add macro to simplify array iterations some more
uint32_t i;
	for (i = 0; i < SPA_N_ELEMENTS(some_array); i++)
		.. stuff with some_array[i].foo ...

   becomes:

	SPA_FOR_EACH_ELEMENT_VAR(some_array, p)
		.. stuff with p->foo ..
2022-09-30 16:24:26 +02:00
Wim Taymans
a145c42ec4 audioconvert: make separate noise functions
So that we can reuse optimized versions in unoptimized noise
functions.
Do allocation a little different so that we can align everything
from the start.
2022-09-29 21:36:06 +02:00
Wim Taymans
38b3d027ec audioconvert: remove S32_SCALE
We don't use it, we use S24_SCALE and then shift. Also adjust the
S32_MIN and S32_MAX values, based on S24 values.
2022-07-20 17:45:34 +02:00
Wim Taymans
5a8af97a40 audioconvert: use SPA_CLAMPF to clamp floats
It generates better assembler.
2022-07-19 17:59:14 +02:00
Wim Taymans
ada39f3048 audioconvert: improve noise bits
Make a new noise method called PATTERN and use it to add a slow (every
1024 samples) repeating pattern of -1, 0.
Only use this method when we don't already use triangular dither.

See #2540
2022-07-18 11:41:57 +02:00
Wim Taymans
57f63feb92 audioconvert: Fix Wannamaker name 2022-07-18 10:22:21 +02:00
Wim Taymans
a4db745a7e audioconvert: improve noise shaping
Reorganize things a little so we can add more noise shapers.
Add sloped triangular noise.
Add wanamaker3 noise shaping.
2022-07-15 12:36:15 +02:00
Wim Taymans
0ba3e7c5db audioconvert: round instead of truncate, to reduce distortion
See #2543
2022-07-13 20:56:13 +02:00
Wim Taymans
d18428f8bb audiconvert: make macros for conversions
Make a common macro for float to int and int to float so that we can
change the algorithms easily.
2022-07-13 18:10:25 +02:00
Wim Taymans
7745346292 audioconvert: add sse2 s16 dither functions 2022-07-12 10:34:13 +02:00
Wim Taymans
dd1d5960b4 audioconvert: implement f64s
Add swapping functions for f64s.
Fix the awkward interleave/deinterleave names for 32s.
2022-07-11 10:58:51 +02:00
Wim Taymans
3ffb9f4b26 audioconvert: improve s24_32 and u24_32 conversion
We should ignore the upper 8 bits, so first shift them out and then
use the s32/u32 conversion functions.
Add a test for this.
2022-07-09 18:07:49 +02:00
Wim Taymans
df40c9bf6a fmt-ops: express 32 bits formats in terms of 32_24 bits formats 2022-07-07 20:11:08 +02:00
Wim Taymans
b8a4bf880f audioconvert: use 24 bits for 32 formats
The float only preserves 24 bits so use this. Otherwise we get overflows
and errors in clang.
2022-07-07 18:38:32 +02:00
Frédéric Danis
036bb13474 audioconvert: Fix s24/u24 byte swapping 2022-07-05 14:06:31 +00:00
Wim Taymans
c4cc13c094 audioconvert: use right scale value
Disable assert, it seems to fail on clang.
2022-07-05 16:02:24 +02:00
Wim Taymans
f62244d7a9 audioconvert: tweak more conversion constants
Tweak some more constants to make lossless conversions work.
Add some tests for lossless conversion.
Add some more tests.
2022-07-05 15:50:05 +02:00
Wim Taymans
22317da685 audioconvert: tweak conversion constants
Tweak the conversion constants a bit so that they handle the
extreme ranges a bit better.
Align the C and vector instructions.
Reactivate the unit test asserts when a conversion fails.
2022-07-05 12:20:02 +02:00
Wim Taymans
e3951cc1f1 audioconvert: fix pack/unpack of s24/u24
Copy the values into the right place in the struct.
2022-07-05 12:18:57 +02:00
Wim Taymans
e0b3e06bea audioconvert: remove unused field 2022-07-01 12:40:19 +02:00
Wim Taymans
817d5bd7a4 audioconvert: simplify 24 bits handling
Make a new uint42_t and int24_t type and use that to handle 24 bits
samples. This makes it easier because we can iterate and copy the
structs like other types.
2022-07-01 12:25:58 +02:00
Wim Taymans
06b1cf8663 audioconvert: implement (de)interleave with existing functions 2022-06-30 18:24:05 +02:00
Wim Taymans
9b37142ef6 audioconvert: implement noise shaping
To compare the results:

  pw-cat -r test.wav --format=u8 -P '{ dither.method=none }'

vs:

  pw-cat -r test.wav --format=u8 -P '{ dither.method=shaped5 }'
2022-06-29 17:33:37 +02:00
Wim Taymans
938f2b123e audioconvert: improve format conversion
Make dither noise as a value between -0.5 and 0.5 and add this
to the scaled samples.
For this, we first need to do the scaling and then the CLAMP to
the target depth. This optimizes to the same code but allows us
to avoid under and overflows when we add the dither noise.

Add more dithering methods.

Expose a dither.method property on audioconvert. Disable dither when
the target depth > 16.
2022-06-29 14:10:15 +02:00
Wim Taymans
6b49bded3a audioconvert: move dither and noise to fmt-ops
We need to do dithering and noise when converting f32 to the
target format. This is more natural because we can work in 32 bits
integers instead of floats.

This will also make it possible to actually calculate the error between
source and target values and implement some sort of feedback and
noise shaping later.
2022-06-28 16:55:50 +02:00
Lucas Holt
6a15a02ec2 Add support for MidnightBSD
Fix build issue

Fix build issue
2022-06-19 18:22:47 +00:00
Wim Taymans
734470f0cd audioconvert: add SSE (de)interleave_32(s) versions 2022-03-11 15:02:02 +01:00
Wim Taymans
92198e4d0d spa: clamp required alignment to cpu alignment
pipewire will allocate buffers aligned to the max alignment required for
the CPU. Take this into account and don't expect larger alignment.

Fixes a warning in mixer-dsp when the CPU max alignment is 16 but the
plugin requires 32 bytes alignment for the AVX2 path (that would never
be chosen on the CPU).

See #2074
2022-01-28 11:49:06 +01:00
Gleb Popov
44b18b86cd Fix build on FreeBSD by defining bswap_64. 2022-01-26 14:37:19 +03:00
Wim Taymans
9f5caa6358 audioconvert: add f64 conversion
See #1990
2022-01-10 13:04:31 +01:00
Wim Taymans
0ace131d72 audioconvert: add stereo deinterleave neon asm
This can take some shortcuts and convert twice as many samples in one
iteration as the strided stereo deinterleave one.
2021-10-28 11:30:04 +02:00
Gleb Popov
e94adaac24 Don't include byteswap.h on FreeBSD, use sys/endian.h instead 2021-10-22 17:50:42 +03:00
Julian Bouzas
20e64b39da fmtconvert: add support for U16, U24, U32 and U24_32 formats 2021-09-08 14:24:26 -04:00
Wim Taymans
df9f79d869 audioconvert: add converstion to and from alaw/ulaw 2021-08-17 17:32:25 +02:00
Wim Taymans
fd82da938a audioconvert: add more format support
Add support to endian conversion as well.
2021-08-17 15:03:03 +02:00
Wim Taymans
a5e2e955d2 audioconvert: add more conversions
Add the other endian conversions.
2021-08-17 14:45:00 +02:00
Wim Taymans
3a879e8b1a audioconvert: fix s24_32 to float
s24_32 needs to be sign extended before converting to float because the
upper bits are undefined and might be anything.

Fixes #1393
2021-07-06 12:42:39 +02:00
George Kiagiadakis
bc1f9d304f audioconvert: handle S8/S8P raw audio formats 2021-05-05 08:56:59 +03:00
Wim Taymans
6249b00b9a audioconvert: add volume ops
Add volume helpers and use this for the monitor output ports so
that we can add volumes to the monitor output signal as well.
2021-02-05 15:08:26 +01:00
Wim Taymans
a8faad9f17 fmt: support f32p -> s24s conversion
As used by MAudio Fasttrack Pro

See rhbz#916017
2021-01-14 17:58:54 +01:00
Wim Taymans
a520335581 fmt-ops: add sse2 version of f32 to s16 planar/interleaved 2020-07-03 11:05:26 +02:00
Wim Taymans
527dc89365 fmt-ops: add neon optimizations for format conversion 2020-03-30 10:59:21 -04:00
Wim Taymans
949dba7bfc fmt-ops: flesh out avx optimizations 2020-03-17 17:27:47 +01:00
Wim Taymans
3a911dfe3b fmt-ops: add avx2 optimized version
Only one optimized version but the sse2 version are compiled with
the avx2 flags so that they get optimized better.
2020-03-16 16:11:29 +01:00
Wim Taymans
fd3dd14ebe fmt-ops: add optimized f32 to s16 stereo conversion 2020-03-16 13:04:21 +01:00
Wim Taymans
f4387e0568 fmt-ops: add support for s24 with endian conversion 2020-01-27 15:46:25 +01:00
Wim Taymans
3c9aa2e96c fmt: add sse2 optimized s32->f32d 2019-10-24 11:06:04 +02:00
Wim Taymans
092a0c660d make bitfields unsigned
Remove driver property from client-node of client-stream.
2019-04-10 17:52:42 +02:00
Wim Taymans
d8e399dee9 audioconvert: pass state to functions
Pass some state to convert and channelmix functions. This makes it
possible to select per channel optimized convert functions but
also makes it possible to implement noise shaping later.
Pass the channelmix matrix and volume in the state.
Handle specialized 2 channel s16 -> f32 conversion
2019-03-29 17:39:59 +01:00
Wim Taymans
d260cb19be audioconvert: compile c version separately
Also compile the c versions in a separate module with their own
flags.
2019-03-28 21:07:53 +01:00