Commit graph

193 commits

Author SHA1 Message Date
Wim Taymans
bb558b7d95 audioconvert: don't overwrite port
Make a new variable to iterate the other ports so that we can use the
original port to emit notifications.

Fixes Latency and other params set on DSP ports.
2022-11-18 13:21:14 +01:00
Wim Taymans
90f5b4a4bf audioconvert: improve renegotiation
When the follower updates EnumFormat, it probably wants to renegotiate
to a new format, so clear the current format so that we do that when
starting the next time.

EnumFormat should also not only return the current format in case we
are negotiated but it should return all possible formats.

See #2832
2022-11-17 19:26:46 +01:00
Wim Taymans
086ad336ad audioconvert: redo setup when format changes 2022-11-15 16:29:46 +01:00
Wim Taymans
bf3516ba04 audioadapter: perform setup again after a PortConfig
After the ports are reconfigured, we need to perform the setup again so
that buffers and processing can happen with the right settings.

This fixes an issue when autoswitching between A2DP and HFP with
bluetooth headsets when there is also a stereo capture device available.
The input stream of the browser is quickly reconfigured between stereo
and mono with only a Pause command in between, clearing the setup state
is enough to redo the setup when going back to Playing.

Fixes #2764
2022-11-15 15:40:47 +01:00
Wim Taymans
b07e0c1445 audioconvert: debug in and out positions 2022-11-09 15:19:46 +01:00
Wim Taymans
74447acedb Add some more format checks
The format parse functions don't really check if the parsed values
make any sense so we need to to this ourselves.
2022-11-03 13:10:32 +01:00
Wim Taymans
3a7d6b74f2 audioconvert: only reinit channelmix when params change
Don't reinitialize the channel mixer when only the volume changes.
2022-10-13 10:31:09 +02:00
Wim Taymans
0adc351d36 audioconvert: use spa_dtoa to format floats and doubles
The parsing functions expect float values in the default locale so use
the spa_dtoa function to generate such a float.

Fixes setting params with floating point values when the locale is not
the default locale.
2022-10-13 10:15:52 +02:00
Wim Taymans
01058d9b4c audioconvert: avoids pops and clicks when activating resampler
When we were using the resampler and then bypass it when the configured
rate == 1.0, we create a pop because we don't process the queued data in
the resampler anymore.

Avoid this by keeping the resampler active as soon as the rate property
is set on the audioconvert. The resampler itself will use a more
efficient copy method in that case anyway and it is expected that the
rate will change again later when we need to reactivate the resampler.
2022-10-07 15:05:22 +02:00
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
10f1d545a7 audioconvert: handle NULL params 2022-09-28 12:14:52 +02:00
Wim Taymans
a579fc49ba audioconvert: move peaks functions to separate file
Make a peaks finder helper and use it in the peaks resampler.
2022-09-27 11:25:02 +02:00
Wim Taymans
2d858e0ba2 spa: a Flush command does not stop processing
A flush command is not supposed to stop playback but just clear the
current state. Normally, to avoid complications, an application will
Pause, Flush and optionally Start to do things smoothly without
interfering with the process loop, but things should not crash if that's
not the case.

Fixes #2726
2022-09-26 11:10:02 +02:00
Wim Taymans
e8aef6b4bd audioconvert: only Suspend should trigger negotiate
A Suspend should clear all the negotiated state and start a new
negotiation in Start. Use a flag to control this.

This avoids recalculation of state for each pause/play state change.

See #2701
2022-09-23 15:32:36 +02:00
Wim Taymans
31f9e18edb audioconvert: add resample.prefill option
Add a resampler option to prefill the resampler with 0. This then
results in the resampler always outputing and consuming the same
amount of data instead of a short buffer in the beginning.
2022-09-19 12:35:49 +02:00
Wim Taymans
aca85b49ea audioconvert: set stride on output buffers 2022-09-19 12:01:24 +02:00
Wim Taymans
46c8c9ec03 audioconvert: set monitor port buffer size correctly
Also use quantum_limit samples on the monitor ports.

Fixes #2677
2022-09-08 12:25:28 +02:00
Wim Taymans
201e6ae9fd audioconvert: use given channelmap for volume
Use the given channelmap for the volume, like it used to be in old
audioconvert.

This makes new streams expose a volume even when not negotiated yet.
2022-09-05 15:29:16 +02:00
Wim Taymans
71ec8650ba audioconvert: remove redundant set_volume calls 2022-09-05 13:23:18 +02:00
Wim Taymans
0c47ab76a7 channelmix: Only filter FC/LFE when present 2022-09-05 13:22:40 +02:00
Wim Taymans
24f6225c5d audioconvert: don't emit changed events for rate changes
Rate changes can happen very often when a stream is doing rate control,
so don't emit the changes every time.
2022-08-30 16:00:00 +02:00
Wim Taymans
e04e3ef40e audioconvert: fix rate match for sources
Only update the resampler rate when we ask for more data, when we have
more input data, use the previously configured rate to calculate how
many samples we will consume.

Fixes resync errors with multiple sources. One source would do rate
matching, audioconvert would ask it to produce X samples, the source is
scheduled to produce the samples, the rate match is updated with the new
rate correction, audioconvert is scheduled again. It should now use the
X samples it asked to produce and apply the new rate correction for the
next iteration.
2022-08-30 12:43:14 +02:00
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