Commit graph

876 commits

Author SHA1 Message Date
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
8d4fe59764 audioconvert: improve debug
When we are mixing unnamed channels, place MONO in the debug output.
2022-12-12 09:38:51 +01:00
Sefa Eyeoglu
b927063b89
audioconvert: fix distorted audio on AVX2
Closes pipewire/pipewire#2885

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
2022-12-11 20:16:03 +01:00
Barnabás Pőcze
8c892443eb spa: audioadapter: fix stack-use-after-scope when configuring format
It is not enough for `buffer` to be alive in its current
scope because when execution enters that branch, `format`
will be set to `fmt`, which points inside `buffer`. And
since `format` is used outside that scope, `buffer` must
live longer.

This was detected by ASAN when Audacity was starting up.

  ==25007==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffdbcfef560 at pc 0x7fe44ca95db3 bp 0x7ffdbcfeeda0 sp 0x7ffdbcfeed90
  READ of size 4 at 0x7ffdbcfef560 thread T0
      #0 0x7fe44ca95db2 in spa_pod_parser_pod ../spa/include/spa/pod/parser.h:67
      #1 0x7fe44ca9a805 in spa_format_parse ../spa/include/spa/param/format-utils.h:44
      #2 0x7fe44cad293a in port_set_format ../spa/plugins/audioconvert/audioconvert.c:1934
      #3 0x7fe44cadad14 in impl_node_port_set_param ../spa/plugins/audioconvert/audioconvert.c:2038
      #4 0x7fe44ca587e2 in configure_format ../spa/plugins/audioconvert/audioadapter.c:509
      #5 0x7fe44ca60dff in negotiate_format ../spa/plugins/audioconvert/audioadapter.c:822
      #6 0x7fe44ca62bbf in impl_node_send_command ../spa/plugins/audioconvert/audioadapter.c:846
      #7 0x7fe45ea1c2f1 in node_update_state ../src/pipewire/impl-node.c:407
      #8 0x7fe45ea5137e in pw_impl_node_set_state ../src/pipewire/impl-node.c:2251
      #9 0x7fe45eb3355f in pw_work_queue_destroy ../src/pipewire/work-queue.c:142
      #10 0x7fe45b2cd6f4 in source_event_func ../spa/plugins/support/loop.c:615
      #11 0x7fe45b2c634f in loop_iterate ../spa/plugins/support/loop.c:452
      #12 0x7fe45e9ebebc in spa_hook_list_clean ../spa/include/spa/utils/hook.h:395
      #13 0x5561e03dc722 in main ../src/daemon/pipewire.c:131
      #14 0x7fe45da3c28f  (/usr/lib/libc.so.6+0x2328f)
      #15 0x7fe45da3c349 in __libc_start_main (/usr/lib/libc.so.6+0x23349)
      #16 0x5561e03db2a4 in _start ../sysdeps/x86_64/start.S:115

  Address 0x7ffdbcfef560 is located in stack of thread T0 at offset 160 in frame
      #0 0x7fe44ca56fa9 in configure_format ../spa/plugins/audioconvert/audioadapter.c:475

    This frame has 4 object(s):
      [32, 36) 'state' (line 493)
      [48, 56) 'fmt' (line 494)
      [80, 128) 'b' (line 492)
      [160, 4256) 'buffer' (line 491) <== Memory access at offset 160 is inside this variable
2022-12-10 09:59:08 +00:00
Jonas Holmberg
4e3103f566 audioconvert: change warning to info
Change log level to info when stopped node gets ready callback since it
can happen and it is not a problem.
2022-12-09 11:20:20 +01:00
Wim Taymans
bccd33c4ab Revert "audioadapter: only accept PortConfig for the adapter direction"
This reverts commit 5bda4b6a57.

The reason is that when you use a null-audio-sink as a source, the
adapter will think it's a sink while wireplumber will try to use it as a
source.

There is no quick solution for this so revert this check for now.
2022-12-09 10:51:05 +01:00
Wim Taymans
cf3d4c3b5d audioadapter: clear started flag earlier
First clear the started flag so that we ignore scheduling from the
follower. Then stop the follower and the converter.

This is the sequence we follow when deactivating a node, so do the
same here.

it is important that the node is not scheduled anymore when we clear
the format in suspend or else we might crash.

See #2877
2022-12-07 13:12:18 +01:00
Wim Taymans
03f9466c5d audioadapter: improve PortConfig enumeration
When in passthrough mode and there is no converter, simply return
our own PortConfig parameter with our direction and passthrough mode.

Otherwise, use the PortConfig from the converter but filter out only the
PortConfig that matches our direction.

This fixes enumeration of PortConfig on the adapter.
2022-12-05 11:45:44 +01:00
Wim Taymans
5bda4b6a57 audioadapter: only accept PortConfig for the adapter direction 2022-12-05 11:45:10 +01:00
Wim Taymans
177479dfd1 audioconvert: improve some more AVX2 code 2022-12-05 09:37:29 +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
4e4d76ccd0 audioconvert: use gather in AVX2 code 2022-12-04 20:38:35 +01:00
Wim Taymans
4c3f56fca1 resample: cleanup the resampler core functions
Move the increment function to a macro.
Don't use extra local variables, we can just as well call the resample
functipon with them.
2022-11-20 16:19:24 +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
43d02410e6 audioconvert: don't handle params when just enumerating
When we are simply enumerating the params, just collect the info
but don't act on them, like clearing the format or recalculating
the latency.

This avoids some useless work when enumerating params.

Use the more complete configure_format function to clear the format
and buffers when the EnumFormat param changed.
2022-11-18 09:34:37 +01:00
Wim Taymans
82f7ed419c audioconvert: shortcut configure_format
When we don't have a format and can't to clear it, we can return
immediately.
2022-11-18 09:29:23 +01:00
Wim Taymans
bc66060b7d audioconvert: also clear buffer when new EnumFormat
Fixes #2832
2022-11-17 19:41:12 +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
04aa803d7e test: avoid compiler warnings when SSE is not enabled
Refactor the sample test and run the test against itself to make
sure we use all variables at least once.
2022-11-11 12:09:22 +01:00
Wim Taymans
8d6ff6137d audioadapter: remove checks for format
This is meant to be a filter for the follower format and can thus
contain wildcards.
2022-11-09 16:29:04 +01:00
Wim Taymans
85ffe68ea3 Revert "adapter: removed unused follower_current_format"
This reverts commit 6c963ed933.

This code was meant to set a filter on the format for the follower
but is not implemented yet.

Problem is that the unit tests and wireplumber call this code and would
need to be patched.
2022-11-09 16:24:49 +01:00
Wim Taymans
6c963ed933 adapter: removed unused follower_current_format 2022-11-09 16:03:18 +01:00
Wim Taymans
b07e0c1445 audioconvert: debug in and out positions 2022-11-09 15:19:46 +01:00
Wim Taymans
bb002a3eef test: add test for 6p1 to 5p1 with remapped REAR
See #2809
2022-11-09 09:41:21 +01:00
Wim Taymans
39bfc0cb56 test: add more 5p1 to 6p1 tests
See #2809
2022-11-09 09:24:03 +01:00
Wim Taymans
25e3144887 audioconvert: skip upmix when moving channels
When we use SIDE for REAR, don't try to upmix REAR channels and vice
versa.
2022-11-09 09:24:03 +01:00
Wim Taymans
a500abaf90 tests: add some more 6p1 conversion tests
Also add a 6p1 to 5p1 downmix test.

See #2809
2022-11-08 18:10:11 +01:00
Wim Taymans
cadb7b4910 audioconvert: set SSE flag on SSE function
Or else it might be selected even when we don't run on an SSE capable
machine.
2022-11-08 18:09:02 +01:00
Wim Taymans
c8e2c4fcd6 audioconvert: debug the conversion matrix with info level 2022-11-08 17:39:16 +01:00
Wim Taymans
9cfc0eff48 audioconvert: upmix RC 2022-11-08 17:38:55 +01:00
Wim Taymans
492920ca35 test: add another 6.1 channelmix test
Reorder the bitmask in the natural channel order to avoid confusion.
Add another test with RL/RR/RC channels.

See #2809
2022-11-06 10:57:25 +01:00
Wim Taymans
ccec687104 test: add unit test for 6.1 up and downmix
See #2809
2022-11-05 17:12:35 +01:00
Wim Taymans
44d743ed95 spa: make all format parsing fields optional
Just like the optional build, make all field parsing optional. This
will leave the fields with their default values if they are not parsed
from the param.

We can then remove our custom functions and use the generic ones in
various places.
2022-11-03 13:13:07 +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
855bebf0ea audioconvert: update started field better
Set up the adapter and then set the started field to true before we
Start the follower and converter. It is possible that the follower will
start processing immediately so the started state needs to be set
correctly.

Similarly, first perform the Pause and Suspend calls on the follower
and converter before clearing our buffers and format so that things
are stopped properly.

See #2764
2022-10-27 10:29:15 +02:00
Wim Taymans
2c4e1b8537 node: check if active when ready event is emited
Add a check that the node is actually started when we get the ready
callback.
2022-10-24 12:33:56 +02: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
9efb2e3463 audioconvert: optimize upmix functions with SSE 2022-10-13 10:19:04 +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
Demi Marie Obenour
e8f3450a58 Fix various compiler warnings
These caused build failures with -Werror.
2022-10-06 12:12:35 -04:00
Wim Taymans
9b6e504c19 clean up some more array iterations 2022-10-03 09:20:42 +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
a145c42ec4 audioconvert: make separate noise functions
So that we can reuse optimized versions in unoptimized noise
functions.
Do allocation a little different so that we can align everything
from the start.
2022-09-29 21:36:06 +02:00
Wim Taymans
14028c67cd audioconvert: some optimizations 2022-09-29 21:36:06 +02:00
Wim Taymans
41fd8144f0 tests: relax test a little 2022-09-29 15:25:02 +02:00
Wim Taymans
e97a0a67d8 tests: use spa_assert_se for tests
Or otherwise they are compiled away
2022-09-29 15:05:16 +02:00