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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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
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
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.
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.
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.
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.
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.
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
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
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")