Commit graph

308 commits

Author SHA1 Message Date
Ashok Sidipotu
b0f6c4a8c0 audioconvert: add support for volume ramp time params 2023-04-03 19:04:55 +00:00
Ashok Sidipotu
40cf237eb3 audioconvert: add volume ramp parameters
Add volume ramp parameters and the add ramp up and down funtions which get
triggered on volume change.
2023-04-03 19:04:55 +00:00
Ashok Sidipotu
3b1ce6c268 audioconvert: parameterize channelmix_process_control() function
Decouple the function from control port and parameterize it, so that it can be
called any spa pod sequence.
2023-04-03 19:04:55 +00:00
Wim Taymans
d07e1b5641 audioconvert: disable upmix by default again
But instead ship config override files to enable it again.

The idea is that distros can make extra packages that can than be
installed to enable the upmixing.

Also ship a config file to enable more samplerates.

Fixes #3081
2023-03-22 15:21:55 +01:00
Wim Taymans
689184a5e7 audioconvert: check return value of pod parse 2023-03-16 12:33:08 +01:00
Wim Taymans
670bf8fe8f echo-cancel: add wav debug file support 2023-03-09 16:31:30 +01:00
Wim Taymans
0563e1da52 audioconvert: add debug.wav-path to save wav 2023-03-09 16:22:55 +01:00
Wim Taymans
a2b391b5c7 Improve debug log a little 2023-03-07 19:11:38 +01:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Wim Taymans
f472fd736d fix includes
Only include debug we need. We usually only need the debug types.
2023-01-18 13:12:16 +01:00
Wim Taymans
1d9640af5a spa: Fix audioconvert overflow when scaling
Add SPA_SCALE32_UP that scales a uint32 without overflow.
Use this for scaling the threshold in ALSA.
Fix the scaling in audioconvert of the buffer size, the scaling was
wrong and it was also causing an overflow resulting in choppy sound in
some cases.

See #2680
2023-01-16 18:28:31 +01:00
Wim Taymans
97aafe2234 fix use_buffers checks
We can set 0 buffers even if there is no format.
Return -ENOSPC when too many buffers are set.
2023-01-10 12:30:25 +01:00
Wim Taymans
144df8675f audioconvert: enable channelmix.mix-lfe by default
It seems OK and SDL also seems to mix LFE by default so what could
possibly go wrong.

Fixes #2425
2022-12-13 16:29:46 +01:00
Wim Taymans
63f279c826 audioconvert: remove default channel map
If there is no valid channel map, assume MONO channels. A valid channel
map should be assigned at the source of the data, not here.

The problem is that when a device uses AUX channels, this will be fixed
up here with a surround setup, which is not right.
2022-12-12 09:40:51 +01:00
Wim Taymans
d6101d73e7 audioconvert: fix PortConfig enumeration
Enumerate what we can support in EnumPortConfig.
Enumerate what is configured in PortConfig.
2022-12-05 09:15:48 +01:00
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