Commit graph

171 commits

Author SHA1 Message Date
Wim Taymans
6c5ec409bf audioconvert: Improve buffer params
Scale the default size of the buffer with the sample rate conversion
factor.
2022-08-03 17:21:48 +02:00
Wim Taymans
a23d154952 audioconvert: always use DSP rate on DSP ports
Always use the DSP rate on DSP ports for format conversion, not the
previous used rate.

This avoids some resampler reconfiguration as it negotiates a non-passthrough
rate conversion and then switches to passthrough when the rate correction is
done to match the graph rate.

See #2614
2022-08-03 11:32:10 +02:00
Pauli Virtanen
977d6e2321 audioconvert: fix input remapping
As currently implemented, input format convert channel remap is no-op.
This is because although the out_datas array is permuted, the original
pointer array is not referred to later on, so the only effect is that
the temporary data array is stored in permuted order.

Fix the permutation by permuting the pointers only for the conversion
step.
2022-07-18 20:31:46 +02:00
Wim Taymans
9dbd016f9d audioconvert: fix compilation warnings 2022-07-17 13:15:00 +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
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
74bed47a56 audioconvert: don't leak converter data 2022-07-06 21:06:55 +02: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
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
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
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
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
7701786016 audioconvert: demote a debug log to trace_fp 2022-06-29 17:30:04 +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
0b73fa97d0 audioconvert: use loop for channelmix method enum 2022-06-29 14:05:48 +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
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
Wim Taymans
1c6cb049ce audioconvert: add an option generate silence noise
Add an empty.noise option that specifies the number of bits to
use for noise when the input signal is pure silence.

Some amplifiers can go into suspend mode pretty easily when they
get pure silence. With empty.noise = 1, audioconvert will now generate
a bitpattern that can keep those amplifiers alive, together with
disabling suspend in the session manager.

Fixes #705
2022-06-24 13:45:35 +02:00
Wim Taymans
974ab5348e audioconvert: reset props before parsing config
Or else we undo all settings from the config params.
2022-06-24 13:45:35 +02:00
Wim Taymans
f2dee23085 buffer: add EMPTY chunk flag
Add an EMPTY chunk flag to mark a piece of memory as 'empty'. For audio
this means silence.
Use the empty flag to avoid mixing 0 samples.
Set the empty flag in output buffers on audioconvert.
2022-06-24 11:09:01 +02:00
Wim Taymans
a365b19110 audioconvert: handle too many channels earlier 2022-06-23 11:28:27 +02:00
Pauli Virtanen
6bfe9a362c audioconvert: avoid crash on 64 channels + monitor enabled
this->monitor enabled adds an additional port in reconfigure_mode. If
there was already the maximum 64, this will crash.

Make maximum number of ports one larger than max channels to avoid
problems.
2022-06-23 09:11:25 +00:00
Wim Taymans
a427e602bd audioconvert: in merge mode, flush input
In merge mode we handle 1 quantum and then flush the input and
output. Fixes a case were samples were cut at the start.
2022-06-22 15:48:09 +02:00
Wim Taymans
d13a206866 audioconvert: fix resampler in_offset
Only advance the in_offset with the number of samples that were consumed
by the resampler. In case when the resampler is filling up an old
buffer, this can be less than n_samples.

Fixes a2dp source and possibly others.
2022-06-20 12:33:52 +02:00
Barnabás Pőcze
492a328227 spa: audioconvert: free resampler
resample::free() needs to be called in `impl_clear()` otherwise the
resampler's private data is leaked when the audioconvert instance is destroyed.
2022-06-16 19:49:50 +02:00
Wim Taymans
3cb5fab176 audioconvert: rework the control loop
Use the offset to skip entries in the sequence array.
Use one loop to handle intermediate and trailing samples.
Fixes an issue where the last chunk of a sequence would be ignored.
2022-06-16 16:45:32 +02:00
Wim Taymans
de2e819fec audioconvert2: rename to audioconvert 2022-06-16 09:19:05 +02:00
Wim Taymans
cf04bb573c audioconvert: remove old plugins 2022-06-16 09:16:49 +02:00
Wim Taymans
ad130d0cd6 audioconvert: fix param counter 2022-05-03 10:41:02 +02:00
Wim Taymans
7b9321dea9 audioconvert: don't forward node results
Don't just always forward node results but use port_enum_param_sync.

Avoids duplicate param results in pw-dump for ports.
2022-05-03 10:10:09 +02:00
Wim Taymans
94dd797aa5 audioconvert: remove unused port param 2022-05-03 10:10:09 +02:00
Wim Taymans
3e73f05af4 audioconvert: expose resampler properties
Expose the resampler PropInfo and Props and params as well. Mostly
useful for updating the resample quality at runtime.
2022-01-18 17:43:44 +01:00
Wim Taymans
3666c4810e audioconvert: ignore latency param on monitor ports
Ignore latency params on the monitor ports of merger. They interfere
with the latency reporting set by the adapter.
The adapter will set the latency param from the follower on port 0 in
the converter, so pass this on to the merger as the latency and ignore
all other updates.

Fixes a case where the latency of a sink would become 0 when a monitor
port was recorded from.
2022-01-11 17:52:41 +01:00
Wim Taymans
35cbe4e939 buffers: make alignment optional
Make the alignment parameter optional when negotiating buffers.
Default to a 16 bytes alignment and adjust for the max cpu
alignment.
Remove the useless align buffer parameter in plugins, we always
set it to 16 anyway.
2022-01-03 12:32:26 +01:00
Wim Taymans
62660c1e87 audioconvert: make buffers larger
See #1781
2021-12-21 18:35:53 +01:00
Wim Taymans
401e56699d audioconvert: listen for merger and channelmix for params
List all the params of the merger and resampler.
2021-12-02 11:35:13 +01:00