Commit graph

965 commits

Author SHA1 Message Date
Wim Taymans
e8c5c1bb97 alsa: hopefully fix compilation on ubuntu CI 2023-04-17 10:05:54 +02:00
Wim Taymans
bd42e54c21 alsa: also define area_addr when version check missing 2023-04-14 19:59:18 +02:00
Wim Taymans
aa971187d7 alsa: include version.h to get the version macros 2023-04-14 19:49:44 +02:00
Wim Taymans
381283ad81 alsa: handle old alsa version
Out Ubuntu CI seems to have an older alsa version that doesn't have
snd_pcm_channel_area_addr so include it here.
2023-04-14 19:25:51 +02:00
Wim Taymans
ea7781d7d0 alsa: fix area pointers
We should use the first and step fields to get to the first byte in the
area.

See #3069
2023-04-14 17:52:26 +02:00
Wim Taymans
916f1cdfbf Revert "alsa-mixer: allow to re-attach the mixer control element"
This reverts commit b554fc20e9.
2023-04-14 16:32:18 +02:00
Wim Taymans
a66d5b90f9 Revert "alsa: UCM conflicting devices changes"
If needs some more work

This reverts commit aae770f18b.
This reverts commit 2216956e05.
This reverts commit 1d3c4501ef.
This reverts commit c7ca024607.
This reverts commit 8e4a5f5d5e.
This reverts commit 8b20675ad1.
This reverts commit ebe6f8b51a.
This reverts commit 4b97da1277.
This reverts commit 7c46a656c7.
This reverts commit 96ed03e1fc.
This reverts commit 43770c533c.
This reverts commit ccb2fce054.
This reverts commit 93d0ddc8b3.
This reverts commit 815e8c8fa0.
This reverts commit 97b99a0f7c.
This reverts commit 7e4d87402b.
This reverts commit 168b3ee22c.
This reverts commit 5128cdba31.
This reverts commit 31cde774c5.
This reverts commit b02c8ba153.
This reverts commit 68ac72d098.
This reverts commit 96cfc9bc1a.
This reverts commit e2d642a20b.
This reverts commit 80fc80c343.
This reverts commit 3a68905c7c.
This reverts commit 7e64680a65.
This reverts commit 8d1e38a281.
This reverts commit 591188195c.
This reverts commit 973fe0cb79.
This reverts commit 4d08c9ad60.
This reverts commit 3dce92e580.
This reverts commit 6b5e232c5c.
This reverts commit b1286c62c9.
2023-04-12 13:05:08 +02:00
Wim Taymans
261fb64849 alsa: separate max_error and max_resync
Use a separate variable to hold the maximum amount of drift we allow
between driver and follower. Ensure this value is smaller than the max_error
and period size so that we have at most 1 period of drift.
2023-04-10 16:28:55 +02:00
Wim Taymans
30657abf28 alsa: also set period size when using IRQ mode
Use the graph duration as the period size even when we are not using
a batch device.
2023-04-10 16:07:24 +02:00
Wim Taymans
d59e1094cd alsa: fix capture timings and drift
Don't reschedule a timeout when we have less samples available than the
target but only reschedule when we have less that the required amount we
need to read. This ensures that we hover around the target level and the
timeouts/rate matching adapts correctly. Previously we would only rate
match if the have at least the target amount of samples, which would
then always result in a possitive rate adjustment and cause drift.

For capture, make sure that there is at least 32 samples of headroom
when we are not using IRQ mode to handle jitter in the timer wakeup.

For capture of batch devices this results in (for a 1024 quantum) a
target buffer fill level of 1024 + 512, and we will read if there are at
least 1024 samples available.

For non-batch devices we aim for a target buffer fill level of 1024 + 32
and read if there are at least 1024 samples available.
2023-04-10 15:02:29 +02:00
Wim Taymans
501a80b247 alsa: fix rate match when using IRQ
When using the IRQ, we are woken up based on processed samples so
compare expected and current clock times to rate match the clock.

Fixes #3144
2023-04-10 13:18:25 +02:00
Forest
252620a18d alsa-profiles: SB Audigy: stereo mixer paths
This is a follow-up to d5390c7, where we switched to the 'PCM' mixer controls
on Sound Blaster Audigy devices, since the ones we used before only work in the
stereo-to-all-speakers mirroring mode.

It turns out we do use that mode after all, but only in a couple of profiles.
Since returning those profiles to the default mixer path yields uneven volume
steps similar to #2934, we instead add a new mixer path just for that mode.
2023-04-09 12:20:26 -07:00
Forest
1e77a7cc51 alsa-profiles: SB Audigy: rename path config file
This makes the file name consistent with the other device-specific ones.
2023-04-09 12:14:39 -07:00
Forest
6939c1e4ee alsa-profiles: SB Audigy: remove absent elements
Some of the elements/keys that were copied from analog-output.conf are not
implemented by the Audigy driver, so we don't need to reference them.
2023-04-09 12:14:29 -07:00
Forest
d5390c7199 alsa-profiles: use SB Audigy PCM mixer controls
Creative Labs Sound Blaster Audigy cards (snd_emu10k1 driver) expose
mixer controls named 'PCM Front', 'PCM Rear', etc. in addition to the
more common 'Front', 'Rear', etc.  The latter seem to be intended for
a stereo-to-all-speakers mirroring mode that we do not use, and have
no effect when we adjust them.
https://docs.kernel.org/sound/cards/audigy-mixer.html

We therefore define a custom mixer path for Audigy devices, using the
PCM mixer controls.

This has been tested on an Audigy 5/Rx.  Based on a brief look at the
ALSA driver, I think all Audigy devices (vendor 0x1102, device 0x0004
or 0x0008) have the same PCM controls, making this change probably safe
for our existing Audigy udev rules.

Relevant kernel files:
sound/pci/emu10k1/emu10k1_main.c
sound/pci/emu10k1/emufx.c
include/sound/emu10k1.h

Fixes #2934
2023-04-07 21:15:38 +00:00
Wim Taymans
108715ebfb alsa: add tsched use to info log
Fixes !1580
2023-03-30 17:50:35 +02:00
Wim Taymans
a163f29a43 improve logging 2023-03-30 15:03:21 +02:00
Wim Taymans
5ae73fccdd alsa: only update alsa sources when added to the data loop 2023-03-29 15:31:21 +02:00
Wim Taymans
b16b80601d alsa: start playback right away in IRQ mode 2023-03-29 15:13:00 +02:00
Wim Taymans
354836075d alsa: setup sources from the data thread
For IRQ based scheduling we might otherwise be woken up after we only
added one of the fds to the poll loop and then we get an error when we
try to update it afterwards. Instead, add the fds from the data thread
to get things nicely in sync.
2023-03-29 12:21:23 +02:00
Wim Taymans
8c264d2dcb alsa: in IRQ mode, disable sources while we wait
In IRQ mode, disable the ALSA fds while we wait for the graph to produce
data. Otherwise we will wake up very quickly over and over.

When we get more data, we activate the sources again to start the next
cycle.
2023-03-29 11:30:40 +02:00
Wim Taymans
dc5aa21c87 alsa-pcm: use full period size in IRQ mode
We can simply wake up every period and check the timers there is no need
to tweak the period size.
2023-03-29 11:29:43 +02:00
Wim Taymans
aa0d9c5b41 alsa: add disable-tsched to params 2023-03-28 18:27:53 +02:00
Arun Raghavan
26e37b6575 alsa: Implement period-based wakeups
Provides configuration to disable timer-based scheduling. This can be
useful at low latencies, for example, where period-based interrupts
might be more reliable than timers.
2023-03-28 16:22:53 +00:00
Wim Taymans
3698593481 spa: reuse code to clear the timers
We have set_timeout and enable_flush_timer functions to disable the
timers so use those.
2023-03-24 17:55:15 +01:00
Wim Taymans
7b6680ba57 plugins: simplify target_ handling
Drivers should only read the target_ values in the timeout, update the
timeout with the new duration and then update the position.

For the position we simply need to add the previous duration to the
position and then set the new duration + rate.

Otherwise, everything else should read the duration/rate and not use
the target_ values.
2023-03-24 11:36:15 +01:00
Wim Taymans
6e8625cf96 node: update the duration/rate from the target
Before scheduling the graph from the driver, update the duration and
rate with the new targets.
2023-03-23 18:39:27 +01:00
Wim Taymans
1bdd5eee69 alsa: update rate/duration from target
Also reorganize some things to reuse more code.
2023-03-23 18:04:36 +01:00
Wim Taymans
2adf8d38d5 node: add target_rate and target_duration in io_clock
Place the target rate and duration in the io clock area.

The driver is meant to read these new values at the start of the cycle
and update the position rate and duration.

This used to be done by the pipewire server when it received the ready
callback from the driver but this is in fact too late. Most driver would
start processing and set the next timeout based on the old rate/duration
instead of the new pending ones.

There is still a fallback for the old behaviour (with a warning) when
the driver doesn't yet update the position.
2023-03-23 17:57:16 +01:00
Wim Taymans
25f5165e4c acp: return EEXIST when seeing a linked device
Otherwise we get ENOENT, which is confusing because it is the same
error when the plugin doesn't exist.

See #2016
2023-03-23 13:24:22 +01:00
Wim Taymans
2d6669d571 acp: fix pa_strbuf
We need vfprintf.
2023-03-22 15:08:29 +01:00
Wim Taymans
aae770f18b alsa: avoid assert
We're doing something different than pulseaudio when setting up the
ports.
2023-03-21 12:29:37 +01:00
Wim Taymans
2216956e05 alsa: fixup after merge 2023-03-21 10:07:39 +01:00
Wim Taymans
1d3c4501ef alsa: use pa_strbuf 2023-03-21 09:47:10 +01:00
Wim Taymans
c7ca024607 alsa: ucm: Fix spurious mixer path removal on initial profile set
The code that removes the mixer path if probing fails can be called in
the path that sets a non-off device profile on hotplug *before*
card->active_profile is updated, which results in spuriously removing
the mixer path. By this point, context->ucm->active_verb would be set
to the same as the profile name, so we can use that instead to avoid
the issue.

On Apple Silicon machines with the UCM profiles in the Asahi Linux repo,
this manifests as the headphones jack having hardware volume controls
*only* if PA is started with headphones connected and until they are
disconnected. Hotplugs end up triggering the bad codepath, and it falls
back to software volume (which is particularly a problem when the
hardware volume happens to be very low or 0 at that point).

Fixes: a9cc1373e2a7 ("alsa: ucm - update the mixer path also after volume probe")
Signed-off-by: Hector Martin <marcan@marcan.st>
2023-03-20 18:35:15 +01:00
Wim Taymans
8e4a5f5d5e alsa-ucm: Fix more instances of profile-verb conflation
The ucm_get_device_property() function adds to each UCM device's
playback_volumes (or capture_volumes) hash map an associated volume
mixer keyed with the UCM verb. These key-value pairs are then iterated
over in various places which assume the key is a profile name. This
assumption is no longer true since we can generate multiple profiles to
use conflicting devices.

A previous commit 45278904167f ("alsa-ucm: Stop conflating profile name
with UCM verb name") fixes some instances of this assumption, but misses
the relation explained above. Fix more instances of misleading
"profile"s where the UCM verb name is actually meant.

Fixes: 45278904167f ("alsa-ucm: Stop conflating profile name with UCM verb name")
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 18:33:36 +01:00
Wim Taymans
8b20675ad1 alsa-ucm: Consider devices using the same PCM as incompatible
Although it's a valid UCM configuration to have multiple devices using
the same PlaybackPCM or CapturePCM, it's unclear how PulseAudio should
handle the cases where multiple of these devices are enabled. Some
options I can think of are:

- Merge all devices sharing the same PCM into the same mapping, open
  only one PCM substream for this mapping, and add 'combination ports'
  that enable combinations of the devices. This has been the case until
  recently, although the combination port logic was broken. A problem
  with this is that we can't independently control device volumes. We
  most likely cannot use hardware volumes either.

- Have one mapping for each device in the same profile, and open one PCM
  substream for each mapping. This is the current state, and it fails
  when there are fewer substreams than devices. Otherwise it works, but
  it's still confusing, as sound directed to a device-specific mapping
  might end up playing at multiple devices.

- Make multiple profiles each with combinations of upto-substream-count
  devices, and have one mapping/substream per device. This still causes
  the confusion mentioned above. And it's likely that the substream
  count will almost always be one, where this case degenerates into the
  last one.

- Have one mapping for each device in the same profile, but open only
  one PCM substream. I assume this is possible with software mixing, but
  it is still confusing like the above, and probably less performant.

- Generate multiple profiles each with one of the shared-PCM devices,
  again with one mapping/substream for that one device. The trade-off
  with this is that we can't use multiple of these devices at the same
  time. However, this doesn't have the output device confusion,
  combination port's volume problems, or the substream count limitation.

This patch takes a short-cut to achieve the last option, by considering
shared-PCM devices implicitly conflicting with each other.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 18:29:51 +01:00
Wim Taymans
ebe6f8b51a alsa-ucm: Disable old modifiers when switching profiles of same verb
While switching profiles of the same UCM verb, existing code first
disables devices that are only on the first profile to avoid conflicts.
However, it only disables devices, not modifiers. Even worse, modifiers
which have PlaybackPCM/CapturePCM are incorrectly treated as devices and
result in a segmentation fault.

Check what we are disabling, and call the appropriate disable function
for both devices and modifiers. Modifiers are disabled before devices,
because _dismod calls fail when the modifier's supported devices are
disabled.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 18:28:10 +01:00
Wim Taymans
4b97da1277 alsa-ucm: Add enable, disable, status helpers for modifiers
These are mostly the same as the device helpers added in c83b34516929
("alsa-ucm: Add enable, disable, status helpers for devices"), but for
modifiers instead.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 18:26:46 +01:00
Wim Taymans
7c46a656c7 alsa-util: Fix pa_alsa_get_supported_formats fallback.
Looks like original intention was to scan over sample formats supported by PA,
but code does the scan by list of alsa formats. Reverse the map and adjust
fallback case which now can use the same map.
2023-03-20 18:24:20 +01:00
Wim Taymans
96ed03e1fc alsa-util: Perform format and rate detection before setting HW params
Perform detection of supported sample format and rates just after device is
opened, before `snd_pcm_hw_params()` is called for the first time. This fixes a
problem where device restricts available sample rates after HW params are set
preventing sample rate detection (seen with UAC2 devices and kernel 6.1.9)
2023-03-20 18:22:09 +01:00
Wim Taymans
43770c533c alsa-profiles: rename mappings for Xonar SE
Remove descriptions as well.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/754>
2023-03-20 17:56:33 +01:00
Wim Taymans
ccb2fce054 alsa-util: Add more standard sample rates.
Dump probed rates
2023-03-20 17:54:54 +01:00
Wim Taymans
93d0ddc8b3 alsa-mixer: extend pa_alsa_mixer_find with the subdevice check
The full identifier check must be executed for the new melem
creation, otherwise the duplicate control element code check
is reached.

Example (using the snd-aloop driver):

numid=56,iface=PCM,name='PCM Notify',device=1,subdevice=1
numid=62,iface=PCM,name='PCM Notify',device=1,subdevice=2

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-03-20 17:50:17 +01:00
Wim Taymans
815e8c8fa0 alsa-mixer: fix the re-attach code for the mixer control element
The new helem must be tracked and old helem must be cleared
to make the code work properly. Introduce the pointer to helem
as the private value for melem and add the necessary code.

Also, add a check for the duplicate mixer elements. The duplicate
mixer element invokes the abort check in alsa-lib. Print a warning
instead and handle the exit gracefully.

Fixes: def8eb074 ("alsa-mixer: allow to re-attach the mixer control element")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-03-20 17:47:52 +01:00
Wim Taymans
97b99a0f7c alsa-ucm: remove extra space from the device.intended_roles property
Before:
  device.intended_roles = " voice"

After:
  device.intended_roles = "voice"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-03-20 17:40:33 +01:00
Wim Taymans
7e4d87402b alsa-ucm: Create multiple profiles per verb for conflicting devices
Right now we try to add all UCM devices of a verb to a single profile.
But if some devices using different PCMs are configured as conflicting
with one another, we will only be able to utilize one of them, chosen
seemingly based on the order in the UCM config file.

This is not a problem with conflicting devices sharing a PCM, as they
are assigned to the same mapping and the ports mechanism only enables
one of them to be active at a time.

To utilize all devices in a UCM verb even when there are conflicting
devices using different PCMs, calculate subsets of devices which
can be simultaneously used and create a profile for each such set.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 17:38:44 +01:00
Wim Taymans
168b3ee22c alsa-ucm: Disable old devices when switching profiles of same verb
While switching profiles, it was enough to switch UCM verbs since that
disables all enabled UCM devices and every profile had a distinct verb.
However, switching to the current verb does not disable any devices.

To support multiple profiles for a verb we need to explicitly disable
the old profile's devices, since they might be conflicting with the new
profile's devices and will prevent them from being enabled. Compare both
profiles' mappings, and disable the devices not in the new mappings.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 17:33:10 +01:00
Wim Taymans
5128cdba31 alsa-ucm: Make mapping UCM contexts have only one modifier
After previous patches, we should be generating no combination ports, so
we don't need to store multiple modifiers per mapping. Simplify the code
based on this.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 17:31:31 +01:00
Wim Taymans
31cde774c5 alsa-ucm: Make mapping UCM contexts have only one device
After previous patches, we should be generating no combination ports, so
we don't need to store multiple devices per mapping. Simplify the code
based on this.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 17:24:12 +01:00