Commit graph

3095 commits

Author SHA1 Message Date
Wim Taymans c79fddf007 avb: handle xruns better
Don't stop early, fill gaps with silence.
2022-07-12 12:27:21 +02:00
Wim Taymans 87053365ea avb: handle sink follower
We need to flush out the packets when we are a follower and when we get
data because our timer is not running as a sink.
2022-07-12 12:27:21 +02:00
Wim Taymans 4d6c71bf12 avb: use iovec to read from ringbuffer 2022-07-12 12:27:21 +02:00
Wim Taymans 5c3629a165 avb: add follower mode
As a follower we disable our own timer and produce a buffer from what we
have when _process is called.
2022-07-12 12:27:21 +02:00
Wim Taymans ff5201ef3d avb: check seq
Avoid infinite loops.
Check sequence number and warn
Use 32 frames per pdu in example.
2022-07-12 12:27:21 +02:00
Wim Taymans 200f591a3d avb: add source 2022-07-12 12:27:21 +02:00
Wim Taymans 552a0056b5 avb: more work
Handle properties.
Fix format negotiation.
Wait in underrun.
2022-07-12 12:27:21 +02:00
Wim Taymans 537a38355a avb: more work 2022-07-12 12:27:21 +02:00
Wim Taymans f95b8263e6 avb: more improvements 2022-07-12 12:27:21 +02:00
Wim Taymans 1adc94df11 start of AVB support 2022-07-12 12:27:21 +02:00
Wim Taymans 6a8fd7024e audioconvert: add and use AVX2 clamp macros 2022-07-12 10:45:41 +02:00
Wim Taymans 7745346292 audioconvert: add sse2 s16 dither functions 2022-07-12 10:34:13 +02:00
Wim Taymans c31928c5f0 audioconvert: add and use CLAMP macros 2022-07-12 10:33:37 +02:00
Wim Taymans c35006f040 audioconvert: move scaling to setup 2022-07-11 17:50:20 +02:00
Wim Taymans 68f883ff77 audioconvert: fix dither scale
Rectangular dither should be [-0.5, 0.5]
Triangular dither should be [-1.0, 1.0]
Noise should add extra bits.
2022-07-11 17:19:28 +02:00
Wim Taymans e313149f7f audioconvert: improve SSE2 dither generation 2022-07-11 16:41:12 +02:00
Wim Taymans 277addcca6 audioconvert: add triangular dither 2022-07-11 16:28:51 +02:00
Wim Taymans 9a5a71dda9 tests: add test for noise 2022-07-11 15:49:44 +02:00
Wim Taymans 03f918bf15 udev: prefix vendor.id and product.id with 0x
They are hex strings so prefix them with 0x to make sure they get
handled like that in properties.

Fixes #2527
2022-07-11 11:55:42 +02:00
Wim Taymans cbbc4baa3f json: avoid converting random string to floats
Only allow the json float characters when converting to float.
This avoids NAN, INF, 0xffe4 etc to be seen as a json float.
2022-07-11 11:50:58 +02:00
Wim Taymans bdfde2fdf0 Revert "spa: leave vendor.id and product.id in hex"
This reverts commit 0d33760b71.
2022-07-11 11:23:08 +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 bc1789c3ea Revert "acp: sync with pulseaudio"
This reverts commit 57f0fdf746.

This seems to cause problems and needs to mature a bit more in
pulseaudio it seems.
2022-07-11 10:03:01 +02:00
Wim Taymans 8fe83e5304 audiomixer: optimize avx mixer some more
Add avx mixer to test and benchmark
Rework and unroll the avx mixer some more.
The SSE one is 10 times faster than the C one, The AVX is 20 times
faster. The SSE2 function is 5 times faster than the C one.
2022-07-10 23:13:24 +02:00
Wim Taymans 7a0445cb28 audiomixer: improve sse and sse2 mixer
Add mixer benchmark.
Improve sse and sse2 mixer function by removin some read/write to the
temporary buffer at the expense of more scattered reads.
2022-07-10 21:15:34 +02:00
Wim Taymans 5fbda82cc3 spa: tweak SPA_MIN and SPA_MAX
This generates much better assembler because it can use a cmov in
more cases.
2022-07-09 20:35:47 +02:00
Pauli Virtanen fe7c6bcef9 bluez5: volume changes from headset should be saved
User changing volume via headset buttons should be treated on the same
level as changing from desktop UI.  Also initial headset volume should
be considered saved (even though session managers currently ignore the
initial route values on route restore).

Mark route as saved on volume events.
2022-07-09 18:19:45 +00:00
Pauli Virtanen 77959a2c1c bluez5: get initial node volume from transport
When emitting node, get initial volumes from transport hardware volume,
if available.

The session manager usually overrides these immediately with saved
values, but it's better to show the HW volume when the node first
appears.
2022-07-09 18:19:45 +00:00
Pauli Virtanen d82b3d6479 bluez5: backend-native: set HFP/HSP volume when connecting
The HFP/HSP HW volume on the device is not necessarily what we think it
is.

Sync the device volume to our value at connect time.
2022-07-09 18:19:45 +00:00
Pauli Virtanen 276c4bc554 bluez5: use separate routes for HFP and A2DP
The A2DP and HFP profiles may have different volume curves, so trying to
convert volumes between the two can produce undesirable volume spikes.
For example, when one of them is using hardware volume and the other
software.

Fix by separating HFP and A2DP routes.
2022-07-09 18:19:45 +00:00
Wim Taymans bb2f054d43 tests: add missing file 2022-07-09 20:16:15 +02:00
Wim Taymans abd6806d71 tests: add sse and sse2 versions to tests 2022-07-09 20:11:46 +02:00
Wim Taymans 371b5a1836 audiomixer: rewrite the mixer functions
Let the mixer functions accumulate the intermediate results into a
larger size variable and then clamp to the final precission. This avoids
distortions because of intermediate clamping.

Although the access pattern of the reads are no longer sequential, the
writes are sequential and we don't need to read intermediate values.
Together with the avoided clamping this is probably faster overall.

Add a unit test for the various cases.
2022-07-09 18:11:13 +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 20172bfbe6 spa: add comment about prefetch 2022-07-08 17:02:46 +02:00
Lucas Holt 4c3f5a7655 When adding MidnightBSD support, I inversed the condition here. 2022-07-08 12:25:58 +02:00
Wim Taymans a1fac201e3 audioconvert: don't use uninitialized max_out
Move the calculation of the expected max output size before collecting
the buffers and doing the monitor ports so that we can get the size
correct.
2022-07-08 11:31:22 +02:00
Wim Taymans e53eefef0d stream: implement prefetch
When the audioconverter needs more data, let it return NEED_DATA. This
can happen before the ports actually have consumed all the input data.
For example, then the next cycle would require 1024 samples but there
are currently only 16 samples queued, the next cycle will consume the
16 samples and then need another buffer to produce output.

For rt streams, this is not a problem because a new buffer will be
fetched in the next cycle synchronously.

When the stream is async, we can use this NEED_DATA to prefetch a
new buffer so that we have one in the next cycle.

This fixes hickups with async streams that provide random sized
buffers.
2022-07-08 10:48:29 +02:00
Wim Taymans 9714ce83d4 audioconvert: only consume what is needed
Move the setup of the output buffers first.
Then figure out how many samples we need to produce and consume.
Make sure we use the resampler to only convert the input samples that
are needed to produce the output samples.

Fixes some muddled sound with mpv when upmixing.
2022-07-08 10:45:44 +02:00
Wim Taymans 7b01068837 audioconvert: consume right amount of input samples
When we are not using the resampler, we consume the same amount of
input samples as output samples.

Fixes #2519
2022-07-08 09:23:31 +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 0343e0da73 fmt-ops: fix some missing shifts and min/max 2022-07-07 18:57:03 +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
Wim Taymans f9660f5e8f audiomixer: clean up mixer functions
Use the same limits as the format converter.
Use a struct for 24bits.
Use macros to generate the mixers.
2022-07-07 13:12:50 +02:00
Wim Taymans 4a82cb74e8 resample: switch to cosh window function 2022-07-07 12:26:45 +02:00
Wim Taymans 57f0fdf746 acp: sync with pulseaudio 2022-07-07 12:23:28 +02:00
Wim Taymans 273c95d71b resample: tweak cosh parameter, this look really good 2022-07-07 10:18:52 +02:00
Wim Taymans 74bed47a56 audioconvert: don't leak converter data 2022-07-06 21:06:55 +02:00
Wim Taymans 08d918432f tests: add more audioconvert remap test
Add tests for all permutations of input/output remappings.
2022-07-06 20:57:04 +02:00
Wim Taymans 4036b8a3f0 tests: add audioconvert test
Add a little test framework for writing end-to-end audioconvert tests.
2022-07-06 19:20:16 +02:00
Pauli Virtanen df2c5d6a14 alsa: fix uninitialized variable 2022-07-06 14:36:22 +00:00
Pauli Virtanen 783fbc507b bluez5: fix minor error handling/warning issues 2022-07-06 14:36:22 +00:00
Wim Taymans 84d2b2ce3a audioconvert: optimize remapping paths
Remove the redundant remap array.
First set up the array with remapped output pointers in case we
can do passthrough output. Make sure stages write to the remapped
array in passthrough.
Remap the input array after unpack/convert.
This avoid an input and output memcpy in the common case of
remapping.
2022-07-06 15:20:13 +02:00
Wim Taymans 0b351aab99 audioconvert: use blackman window again
I'm not convinced the cosh window is better and it causes some weird
nan numbers in some cases.

See #2483
2022-07-06 09:57:52 +02:00
Wim Taymans 76350cebef audioconvert: fix PROP_INFO
The description needs to be set. The name is the unique name of the
property and the id the predefined property id.

Fixes #2488
2022-07-05 20:41:01 +02:00
Carlos Rafael Giani 7e44909741 alsa: add lower rate bound for DSD playback
This prevents errors when trying to play at a rate
that's lower than DSD64 (the lowest rate available).
2022-07-05 16:56:50 +00:00
Wim Taymans 651f4af0ae audioadapter: ask more data when converter empty
When we are actively driving the stream and the converter needs more
data, call the stream process function again to get it so that we
don't underrun.

Fixes #2494
2022-07-05 17:54:44 +02:00
Wim Taymans 987784b629 tests: add test for s24/u24 swap 2022-07-05 16:34:22 +02:00
Pauli Virtanen e1cb7c6fb2 bluez5: sco-source: implement sco-source the same way as a2dp-source 2022-07-05 14:21:04 +00:00
Pauli Virtanen 51356ea3d0 bluez5: a2dp-source: separate clock from recv + handle buffering
a2dp-source as driver does not produce regularly spaced graph cycles,
because A2DP is not isochronous. This causes e.g. crackling for alsa
etc. that expect regular timings. It also does not rate match.

Change a2dp-source to trigger graph on regular intervals. Change recv to
only accumulate data to a buffer, and put data to buffers in process().

Rate match with DLL, keeping average buffer level constant.  Keep track
of jitter to determine a safe target value.
2022-07-05 14:21:04 +00:00
Pauli Virtanen 459a1114f1 bluez5: sco-io: we should always read from socket
Not reading from the socket appears to cause messages to pile up to some
limit, which causes problems if we start the source after some point.
2022-07-05 14:21:04 +00:00
Pauli Virtanen 02bdfcb115 bluez5: ad2p-sink: adjust debug log message
timeout -> timer, since "timeout" looks like error to users
2022-07-05 14:21:04 +00: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 12bee0edf8 audioconvert: fix channel remapping
Do the channel remapping to the cannonical format when we
deinterleave/interleave instead. Otherwise we would completely skip
the remapping when we have interleaved input.

Fixes #2502, #2490
2022-07-04 17:38:20 +02:00
Wim Taymans ffedc2d1e8 null-sink: add option to debug memory 2022-07-04 13:38:07 +02:00
Wim Taymans 67f648cc66 audioconvert: handle NAN from window function
The window function can generate NAN, convert those to 0.0.

Fixes #2491
2022-07-03 20:37:48 +02:00
Wim Taymans a2521bb3e0 audioconvert: fix draining
When we get something else that a drain status as input, bring us back
to the non-drained state.

When we are draining, don't remove the drained flag on the input
io status. This needs to be cleared by the host when the draining is
finished.

Fixes speaker-test
2022-07-01 21:49:13 +02:00
Wim Taymans 9af9450888 audioconvert: ensure temp buffers are large enough
Ensure that our temporary buffers can hold at least quantum_limit
samples. When no output or input is connected, we can generate up
to a quantum_limit of silence, which requires all the buffers to
be scaled correctly.

Fixes a segfault in mpv.
2022-07-01 15:25:37 +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 afd8e8823e audioconvert: use macros to generate code
Most of the outer loops are all the same.
2022-06-30 17:49:44 +02:00
Wim Taymans 0d33760b71 spa: leave vendor.id and product.id in hex
There is no reason to store this as anything other than the original
hex string. Especially for compatibility with pulseaudio.

See !1298
2022-06-30 08:38:52 +02:00
Wim Taymans a44c600ade resample: use cosh window function
Seem to produce a little sharper cutoff.

Fixes #2483
2022-06-29 18:03:40 +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 7701786016 audioconvert: demote a debug log to trace_fp 2022-06-29 17:30:04 +02:00
Wim Taymans 0b62cea4f9 audioconvert: use faster noise generator 2022-06-29 14:33:58 +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 d23b96b033 audioconvert: fix some compiler warnings 2022-06-29 14:08:30 +02:00
Wim Taymans 0b73fa97d0 audioconvert: use loop for channelmix method enum 2022-06-29 14:05:48 +02:00
Wim Taymans 22d02a7891 audioconvert: dither in 24 bits
This saves some shifts.
2022-06-28 17:15:27 +02:00
Wim Taymans 7a0f201dc7 audioconvert: set right flags for functions 2022-06-28 17:02: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
Wim Taymans 51f4f1fb69 audioconvert: expose the selected function names
And debug them.
2022-06-28 16:50:14 +02:00
Wim Taymans 048e10ee3b audioconvert: expose upmix-method in PROP_INFO 2022-06-28 11:32:05 +02:00
Wim Taymans a84bf672e8 audioconvert: add dither passthrough flag 2022-06-28 11:31:40 +02:00
Wim Taymans b5e0151cc0 audioconvert: add dither noise setting in dither struct
Move the noise setting in the dither struct so that it can be
handled separately.
Setup dither separately.
Set used cpu_flags in structures after setup.
2022-06-28 10:52:31 +02:00
Wim Taymans b7e26002be audiocovert: improve dither setup
The quantize is the amount of bits we want to keep from the original
signal, subtract the amount of bits for noise. Clamp this to 0 (all
noise).
Calculate the scale factor better with powf() and avoid overflows.

Fixes #2479
2022-06-28 10:11:46 +02:00
Wim Taymans 67c2202044 audioconvert: improve setup of quantization
Use the quantize value to specify how many bits to quantize to.
2022-06-27 20:03:30 +02:00
Wim Taymans 916050aacd audioconvert: handle errors 2022-06-27 20:03:30 +02:00
Wim Taymans 00998ffd7e audioconvert: ensure alignment
Allocate a little bit more data to ensure alignment and overread of the
dither data.
Ensure sse2 can load aligned data in all cases.
2022-06-27 17:18:23 +02:00
Wim Taymans b41d52cfd1 audioconvert: optimize dither
Add sse2 dither optimization
2022-06-27 14:15:01 +02:00
Wim Taymans 9f55708e9d audioconvert: Always apply noise when asked
Rename empty.noise -> dither.noise and always add this amount of noise
when > 0. This also adds the noise to silent sounds, not only when
nothing is connected because that would also be a problem when an amp
needs to be kept alive with an non-0 signal.

Rename noise -> dither because we can use this also for dithering later.

See #705
2022-06-27 11:19:01 +02:00
Wim Taymans abcf7cb8d8 add some SPA_LIKELY 2022-06-27 09:37:33 +02:00
Takashi Sakamoto e3b6534872 acp: avoid assertion at alsa-lib mixer API when element removal
PipeWire v0.3.7 or later hits assertion at alsa-lib mixer API due to
wrong handling of removal event for mixer element.

wireplumber: mixer.c:149: hctl_elem_event_handler: Assertion `bag_empty(bag)' failed.

The removal event is defined as '~0U', thus it's not distinguished from
the other type of event just by bitwise operator.

At the removal event, class implementator for mixer API should detach
mixer element from hcontrol element in callback handler since alsa-lib
has assertion to check the list of mixer elements for a hcontrol element
is empty or not after calling all of handlers. In detail, please refer to
MR to alsa-lib:

 * https://github.com/alsa-project/alsa-lib/pull/244

This commit fixes the above two issues. The issue can be regenerated by
`samples/ctl` Python 3 script of alsa-gobject.

 * https://github.com/alsa-project/alsa-gobject/

It adds some user-defined elements into sound card 0. When terminated by
SIGINT signal, it removes the elements. Then PulseAudio dies due to the
assertion.

Fixes: 1612f5e4d2 ("alsa-acp: Add libacp based card device")
2022-06-27 10:17:30 +09:00
Barnabás Pőcze 1ac02db6a9 spa: audioconvert: ensure that noise::intesity is not too big
Shifting by 64 or more would not fit into `uint64_t`.
2022-06-24 16:27:43 +02:00