Commit graph

178 commits

Author SHA1 Message Date
Wim Taymans
955815b468 alsa: only scale DSD samplerates 2022-09-07 21:42:45 +02:00
Wim Taymans
68581235ae alsa: fix min dsd rate
We just need to allow from DSD64 onwards. Remove some unused fields.
2022-09-07 20:23:53 +02:00
Wim Taymans
72b6788c68 alsa: don't set impossible rates
When the max rate is smaller than the min rate, don't add the DSD
format at all because it is not possible to play it.

See #93
2022-09-07 19:58:30 +02:00
Wim Taymans
23522651f9 alsa: dsd rates are expressed in byte rate
DSD64 would be a rate of 44100 * 64 / 8. When packed in U32_BE, we would
negotiate 44100 * 8 / 4 (88200) with the device, this means all rates
from 88200 and up are allowed for DSD64 in U32_BE.
2022-09-07 19:54:09 +02:00
Wim Taymans
2054dcf36f alsa: Improve format negotiation
When the device is not running but has a format, close/open the
device to get all the available formats again. Do the same when
setting a format.

Otherwise, the configuration space of the device is restricted to the
current negotiated format and we can't query the other possibilities
or change it.

Fixes #2625
2022-08-31 10:03:39 +02:00
Wim Taymans
54b499b1cf alsa: do the right log level checks
spa_log_level_enabled does not work when a custom log level has
been set. Use spa_log_level_topic_enabled instead.
2022-08-05 15:03:22 +02:00
Wim Taymans
73073eb33f alsa: redirect alsa output to log file
Make a custom snd_output object that redirects output to the log
file.
2022-08-05 14:01:37 +02:00
Wim Taymans
0dc5a08bfd alsa: debug hw_params 2022-08-05 13:00:44 +02:00
Wim Taymans
34c1c1614e alsa: add some more debug
See #2614
2022-08-04 14:25:24 +02:00
Wim Taymans
e22e522ab8 alsa-pcm: limit the target to the buffer size
Don't try to wait for more samples than can fit in the ringbuffer.

See #2603
2022-08-03 12:22:38 +02:00
Wim Taymans
52281b9a7e alsa: check the offset against the size of the buffer
We need to check the last offset against the size of the buffer, not the
remaining size in the buffer.

When the writing is split, this could cause the buffer to be reused
wrongly.

See #2536
2022-07-13 09:37:01 +02:00
Carlos Rafael Giani
7e44909741 alsa: add lower rate bound for DSD playback
This prevents errors when trying to play at a rate
that's lower than DSD64 (the lowest rate available).
2022-07-05 16:56:50 +00:00
Wim Taymans
f6938d8364 alsa: simplify writing
We don't use the input buffers as ringbuffers, so remove that
code and simpify fomr things.
2022-06-24 10:38:13 +02:00
Wim Taymans
0f62d3442c alsa: handle driver bugs better
Use the NEAREST flag when setting a format. This only works for raw
formats and will update the format with the nearest accepted rate
or channels. We can then query the real configured format and use that
for the converter.

This makes things work when a driver tells us it can do 44100Hz but then
refuses and changes the rate to 48000.

See #2197, #2457, #2455, rhbz#2096193
2022-06-23 10:20:49 +02:00
Wim Taymans
b99c71262e alsa: force same clock only for pro audio profile
Assume that capture and playback nodes from a device have different
clocks. This enables the adative resampler to match them. A lot of devices
actually have slightly different rates and would work out of the box
with this fix.

Make an exception when the card is configured in the pro audio profile.
Then we force the same clock on all device nodes and avoid resampling
and rate matching. This can still be changed with a session manager
override.
2022-06-08 17:03:50 +02:00
Wim Taymans
63d2102594 alsa: do resync based on current measurements
Call update time with the currently measured delay and then resync when
needed. Previously we would do the resync in the next cycle.

See #2257
2022-05-27 21:20:51 +02:00
Jonas Holmberg
64c1b62aa8 alsa-pcm: Do not log warning when resync was expected
Log as info instead of warning when alsa sync was expected.
2022-05-11 17:45:27 +02:00
Wim Taymans
9d186cf622 alsa-pcm: scale max_error with quantum size
Adjust the max-error between the hardware delay and the quantum. Limit
this between 256 and quantum/2 to make sure we are not too sensitive.
2022-05-11 10:34:27 +02:00
Wim Taymans
b7845bd702 alsa: scale buffer with frame_scale
Make the alsa buffer a little larger when we scaled the samplerate,
like for DSD. This allows us to go all the way up to the quantum
limit.
2022-04-28 13:04:39 +02:00
Wim Taymans
c48a4bc166 pw-cat: fix DSF playback again
Make the DSD buffers a little bigger because we scale down the rate.
Read an interleaved number of samples to fill one quantum.
2022-04-28 12:32:08 +02:00
Wim Taymans
5a023c8c84 alsa: fix argument type for Long
Fixes #2271
2022-04-21 22:13:16 +02:00
Wim Taymans
1547e5fd2b alsa: limit the buffer-size to quantum-limit * 4
We don't actually need to allocate the largest possible buffer. A buffer
that is near 4 times the quantum-limit is more than enough.

See #1995
2022-04-07 16:01:48 +02:00
Wim Taymans
bcdd1ea811 alsa: set better ranges on properties 2022-03-04 17:21:14 +01:00
Wim Taymans
e28b613404 alsa: don't read more than available samples
Keep the original available samples and use them to avoid reading
a chunk when there is not enough data.
2022-02-16 21:30:54 +01:00
Wim Taymans
56c03c11f8 alsa: resync when quantum changes 2022-02-16 21:30:35 +01:00
Wim Taymans
798228a906 alsa: remove useless code
The resync check can be done in check_position_config.
2022-02-16 21:29:55 +01:00
Wim Taymans
4246961070 alsa: use rewind to remove excess delay
When the delay is too big, rewind a little to reduce it when resync.
2022-02-16 21:10:03 +01:00
Wim Taymans
761199be70 alsa: improve resync
Use the max error to do a resync. Don't reset the dll, there is no
reason for that.
Don't use _rewind, but instead limit the amount of samples we read and
write
Should keep more stable sync in most cases.
2022-02-15 16:32:00 +01:00
Wim Taymans
87f4726164 alsa: protect against impossible timeouts
Check if the new timeout is larger than 1sec in the past or future
and reprogram a timeout with a saner timeout.
2022-02-15 15:35:40 +01:00
Wim Taymans
8b899dbc55 alsa: make sure we always trigger a timeout
If we get an error from get_status() make sure program the timer
for one period or else we would just end up with silence.
2022-02-15 15:32:09 +01:00
Wim Taymans
dc76ab2291 alsa: don't use dll when not rate matching
Only use the DLL when we are driver or rate matching with
another driver.
2022-02-15 15:29:40 +01:00
Wim Taymans
0bca352241 alsa: fill with silence when underrun
Also try to resync when the follower buffer is running empty.
Fill the buffer with silence instead of doing _pcm_forward.
2022-02-12 12:09:25 +01:00
Wim Taymans
9855e2b303 alsa: tweak capture follower
If the follower does not have enough data to capture, skip a cycle
instead of trying to capture and get an XRUN.

Tweak some limits a little.
2022-02-11 18:07:44 +01:00
Julian Bouzas
e34d9d209a alsa: try to resume after suspend before recovering
Fixes no audio after suspending with some audio drivers.

See #2001
2022-02-10 16:57:58 -05:00
Wim Taymans
f636603844 alsa: pass current_time around in get_status()
Pass the current time around in various functions.
Make a higher precission htimestamp based get_delay() function. Seems to
work fine for playback but not for capturee.
2022-02-10 15:31:29 +01:00
Wim Taymans
14d252ec9d alsa: try to resync on commit error
When we get a commit error, try to resync our pointers. This fixes a
problem of endless commit errors after a quantum change because it never
manages to resync properly.
2022-02-08 18:31:42 +01:00
Wim Taymans
76417fd2a6 alsa: use MONOTONIC clock for tstamp 2022-02-03 16:22:09 +01:00
Wim Taymans
8d37451fb8 alsa: ensure period_size is not 0 2022-01-24 12:44:16 +01:00
Wim Taymans
5010125452 alsa: make internal latency configurable with params 2022-01-18 11:46:08 +01:00
Wim Taymans
d8c867b515 alsa: improve rate selection
Make sure we don't select an invalid rate when the default is set or
when the card is already opened in some unsupported rate.

See #1975
2022-01-17 14:56:45 +01:00
Wim Taymans
776b52749f Use configured quantum_limit instead of hardcoded value
Parse the quantum_limit parameters and use this to scale the buffers so
that they can contain the maximum allowed samples instead of the
hardcoded 8192 value.

See #1931
2022-01-12 17:50:12 +01:00
Wim Taymans
39716cdd44 alsa: limit batch period size to default
We take half of the current quantum as the period size for batch
devices. Limit this to the default quantum to ensure we don't end up
with too much headroom.
2022-01-11 16:33:19 +01:00
Wim Taymans
67dc97fa43 alsa: add audio.allowed-rates param
Add a construct and runtime param to limit the amount of allowed
samplerates used by the node.

Fixes #1932
2022-01-03 16:03:23 +01:00
Barnabás Pőcze
b04b52ecf8 spa: alsa: do not look up the card again when releasing
Currently, `release_card()` uses `find_card()` to find the card
by the index stored in the state object. However, `find_card()`
increments the reference count of the object, therefore
`release_card()` will drop the reference that it has just
created by calling `find_card()` and not the "calling scope's"
reference. This prevents the card objects from being
freed when the SPA handle is cleared.

Fix it by having `release_card()` take a pointer to the card
and not its index.
2021-12-20 19:50:57 +01:00
Barnabás Pőcze
ee0963b68e spa: alsa: change index type
The `card` structure uses `uint32_t` for its index member,
on the other hand, the `state` structure uses `int`. No code
depends on it being `int`, therefore change it to `uint32_t`
for consistency.
2021-12-20 19:50:57 +01:00
Wim Taymans
f8cdc05720 alsa: allow multi-rate by default
We don't enable multiple rates by default and kernel 5.16 will fix
most issues so allow multiple rates per card.

See #1916
2021-12-18 08:33:34 +01:00
Wim Taymans
b476d6b503 alsa: add api.alsa.period-num param
To configure the amount of periods. By default we use as many as
possible but it is now possible to force a value.

See #1473
2021-12-17 16:09:52 +01:00
Wim Taymans
8630b8846c alsa: use position duration as period size
Use half of the configured quantum as the period size in batch mode.
This gives lower latency for USB devices depending on the quantum.
2021-12-17 16:08:08 +01:00
Wim Taymans
68cd9ac738 alsa: only use graph rate when nothing else is fixed
Only fall back to suggest the graph rate when we don't have a forced
rate or the card was not already in a format.

See #1892
2021-12-16 15:32:36 +01:00
Wim Taymans
738cbcf789 alsa: fix rate for EAC3
EAC3 needs to be opened in 4x the rate of the EAC3 stream, which can be
32, 44.1 or 48 KHz. Some clients already multiply but others don't.
Check here what is the case and fix it up.

Fixes #1902
2021-12-16 11:02:39 +01:00