Commit graph

179 commits

Author SHA1 Message Date
Wim Taymans
1b1a3b96ec alsa: improve startup
Start with an extra period of silence.
Reconfigure a new timeout if we are too far off from the desired
buffer fill level. Reduce this level to the maximum error we
tollerate.

With this we use the extra period of silence to reconfigure the
timeout until we are close enough and we can start the dll with a
small error.

See #892
2021-03-16 09:48:12 +01:00
Wim Taymans
017900575c alsa: don't compensate for resampler delay
Don't try to move closer to the read/write pointers in the ringbuffer
to compensate for the resampler delay. We might not have enough time
anymore to complete a cycle without xruns. The delay is properly
reported in the clock times and should also be reported on the port
latency eventually.
2021-03-14 17:08:04 +01:00
Wim Taymans
c4e3b5adbc alsa: don't double the resampler delay
The delay of the resampler is what it reports, don't double it.

See #854
2021-03-14 14:13:37 +01:00
Wim Taymans
9cd9339c2a alsa-pcm: only disable IRQ when not batch
For batch devices we want to keep the IRQ so that the pointers are
updated with the period-size. Brings my UMC404HD to 4.8ms roundtrip
times with IRQ at 6 sample and batch enabled.
2021-03-11 18:37:13 +01:00
Wim Taymans
b4cf78b5a6 alsa-pcm: improve debug 2021-03-11 18:34:55 +01:00
Wim Taymans
63a34f4f84 alsa: after XRun, fill with previous threshold
It is possible that the quantum has changed before the xrun and
then we will assume the previous quantum was in the device.
2021-03-09 15:46:44 +01:00
Wim Taymans
aa0e0043d3 alsa: only recompute threshold when quantum changes 2021-03-09 13:21:50 +01:00
Wim Taymans
cab5cf3ccb alsa: add resampler delay in clock delay reporting 2021-03-08 17:12:00 +01:00
Wim Taymans
2c1f8af2e6 alsa: correct dll error after quantum change
When the quantum is changed, the error between the current and
expected buffer levels needs to be corrected with the quantum
difference.

For example, say we are running with a 1024 quantum and the quantum
is changed to 8192, when we wake up the filled level might be
1016 vs expected 8192, 1024 - 8192 = -7168. The real error for the
timeout was 1016 - 8192 - (-7168) = -8.
2021-03-08 16:29:53 +01:00
Wim Taymans
ffeb2e0f0e alsa: fill with right amount of silence when starting
When we start or after an xrun, we need fill the buffer with one
period + headroom of samples, not period*2. This is because after
start we set our timeout immediately and expect there to be
period + headroom samples in the buffer.

With period*2 we take one period longer to start and we also feed
one period of error in the dll, which causes it to wobble for no
good reason.
2021-03-08 15:36:58 +01:00
Wim Taymans
3af768f124 resample: take into account the number of queued input samples
Take the queued input samples into account when calculating the
required input size. This can be 0 when there is still enough
data queued in the input for another period.

Handle 0 read_size in alsa-source and make it push out a 0 buffer,
this will then drain the resampler and make it ask for a new buffer
size. This makes the transition from one period to another more
seamless for the resampler.

Fixes #805
2021-03-04 10:27:44 +01:00
Wim Taymans
e15104c5cb alsa: make resync less aggressive 2021-03-04 10:20:08 +01:00
Wim Taymans
c135f9c7ee alsa: always set read_size 2021-03-04 10:13:26 +01:00
Wim Taymans
e210c5f21c alsa: include headroom in silence buffers 2021-03-03 17:15:23 +01:00
Wim Taymans
a36af57899 alsa: reschedule the timeout based on new quantum
Always reschedule the timeout based on the new quantum. If the
quantum descreased we want to wait some more until the buffer only
has the new quantum of samples left.
2021-03-03 17:01:12 +01:00
Wim Taymans
3bcc59120a alsa: fix timeout adjustment
Only adjust the timeout when the quantum increases so that we end u
with exactly the number of samples of the new quantum.

Suppose we are handling a quantum of 1024, we wake up with 1024
samples in the device, we now notice a quantum of 8192 and will pull
in the 8192 samples, we then have 1024 + 8192 samples in the buffer.
Schedule a timeout for 1024 samples so that we end up in the timout
with 8192 samples in the device.
2021-03-03 16:55:40 +01:00
Wim Taymans
8981e11c53 alsa: various improvements
Remove some magic constants that are not needed anymore with the
headroom.
Clamp the error to some reasonable value so that we don't adjust the
rate too much but still apply all of the correction calculated by the
dll.
Remove the bandwidth adjustment.
Also update the matching and resample fields when we reassign the
node to a new driver. This could cause the new follower to not activate
the adaptive resampler and get out of sync.
2021-03-03 15:40:10 +01:00
Wim Taymans
d2fb6db21f alsa: use configured rate and channels when enumerating formats
When we have a rate or channels configured, set this in the hw_params
to restrict the enumeration of the remaining parameters. If we,
for example want 8 channels, some cards restrict the formats in that
case and we don't want to enumerate impossible combinations.

Fixes #782
2021-02-23 17:17:14 +01:00
Wim Taymans
c067fd0a20 alsa: log device name in visible debug messages 2021-02-22 10:07:50 +01:00
Wim Taymans
94ec577dcd alsa: make sure _recover() works from SUSPENDED
Pass -ESTRPIPE to _recover() when our state is SUSPENDED so that
it always attempts to resume, regardless of the error code.
2021-02-08 11:48:32 +01:00
Jonas Holmberg
0ccad38df1 alsa-pcm: Fix target calculation
Use threshold instead of last_threshold so that early wakeup is detected
in handle_capture() when duration changes.
2021-01-28 16:18:35 +00:00
Jonas Holmberg
30848ada6b alsa-pcm: Change resync warning to info
Do not print a warning when a client with custom latency disconnects.
2021-01-26 15:46:23 +01:00
Wim Taymans
73896bfa83 alsa: rework batch handling a bit
By default, use a 512 period for batch and use 512 headroom
Add a property to disable special batch handling.
2021-01-21 17:14:51 +01:00
Wim Taymans
02295c5e2b alsa: call prepare again but ignore EBUSY
Not calling _prepare can cause problems on my card. So call it
again but ignore -EBUSY.
2021-01-15 18:42:35 +01:00
Wim Taymans
376436fc2c alsa: remove snd_pcm_prepare() call, it is not needed
set_hw_params already called _prepare for us and calling it twice
might cause trouble in some drivers.

See #580
2021-01-15 16:12:42 +01:00
Wim Taymans
482f96a644 alsa: add option to disable mmap access mode 2021-01-15 15:44:22 +01:00
Wim Taymans
2ff4615e53 alsa: prefer planar formats
They are easier to convert
2021-01-15 15:18:39 +01:00
Wim Taymans
7347b5ef05 alsa: add api.alsa.headroom setting
Can be used to tweak the extra distance kept between the hardware
and software pointers when reading and writing.

See #289
2021-01-14 17:10:05 +01:00
Wim Taymans
dea4836203 alsa-pcm: always start device
Also start device after writing silence.

Fixes #558
2021-01-11 07:11:09 +01:00
Wim Taymans
7f007b6bca resample: tweak the resampler to keep delay number of samples
Instead of requiring the upstream node to resubmit the delayed
samples, keep the samples ourselves. The benefit is probably too
small to measure but it simplifies things a lot.
2021-01-08 16:35:26 +01:00
Wim Taymans
18b5199d44 alsa: add read/write access mode
Add support for read/write access mode when mmap is not available.

See #526
2021-01-05 17:48:09 +01:00
Wim Taymans
87292432b7 alsa: add option to configure period-size
api.alsa.period-size can be set to something else than 1024 with
this config option.
2021-01-05 12:44:10 +01:00
Wim Taymans
134f27a201 alsa: log warning for unhandled formats
When we can't enumerate a single supported format, log a warning with
the supported formats and access.

See #526
2021-01-03 08:52:59 +01:00
Wim Taymans
4b076549f7 alsa: allow override of channel map 2020-12-28 14:24:59 +01:00
Wim Taymans
c81fe38285 alsa-pcm: limit channels to MAX
We don't support more than MAX channels

See #507
2020-12-23 20:07:51 +01:00
Walter Lozano
9f766dd708 alsa: add warning in case of partial read/write
Currently alsa_read and alsa_write assumes that all the frames committed
using snd_pcm_mmap_commit are read or written, which is probably true.
However, as it could be some corner cases add a warning to notice this
fact.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
2020-12-20 00:23:52 -03:00
Wim Taymans
d71259a02c alsa: handle batch devices
For batch devices that are not usb devices, lower the period and
add an extra period of heardoom to avoid xruns.

See !330
2020-12-11 17:38:27 +01:00
Wim Taymans
7768a87a0b alsa: make it possible to fix format 2020-12-09 20:33:57 +01:00
Wim Taymans
4e7be858e4 node: Add ParamBegin/End
Use these commands to mark the begin and end of a series of Param
enumerations and configuration, like when doing format negotiation. The
idea is that the device can remain open while we do this.
Use this in adapter when negotiating a format.
2020-12-09 17:10:52 +01:00
Wim Taymans
ec77979890 alsa-pcm: default to max channels
When nothing else is specified, suggest the max number of channels
for a device.

See #467
2020-12-09 12:10:13 +01:00
Wim Taymans
d776a0917d alsa: refactor dll code 2020-12-09 12:09:40 +01:00
Wim Taymans
136fc028a5 prefer S24 over S16 formats
Prefer the higher quality over performance.

Fixes #457
2020-12-06 10:37:40 +01:00
Wim Taymans
ddfb310087 alsa-pcm: improve recover from suspended state debug 2020-11-26 09:24:57 +01:00
Wim Taymans
b055b9de25 alsa: Make sure we handle errors in close
When a device is removed, close() will error. Warn about this but
continue closing our other things including marking the device
as closed so that we don't try to close it again later.

Fixes #413
2020-11-25 12:37:51 +01:00
Wim Taymans
c1ea63fa7a alsa-pcm: try to recover in all cases
Even if we can't get the current status, still try to recover the
device.

See #347
2020-10-22 09:16:45 +02:00
Wim Taymans
9dfd261c71 add some more debug info 2020-09-25 17:01:52 +02:00
Wim Taymans
1bf6dead10 alsa: add option to force a samplerate 2020-09-16 15:14:26 +02:00
Wim Taymans
8332d3e3ed alsa: don't change the resampler delay value
Don't change the resampler delay value, we need it to make sure
we keep samples around for the next round. With small period sizes,
we set the delay to 0 and mess up the resampler and cause dropouts
and clicking.

Fixes #287
2020-09-15 13:22:41 +02:00
Wim Taymans
2b0b44edc0 alsa: add option do use chmap from alsa, disable by default
This should be more in line with what PulseAudio does and so lead
to less surprises.

See #289
2020-09-14 20:19:44 +02:00
Wim Taymans
ca5836cdf4 alsa: fix delay parameter
We need to keep twice the delay of samples around. Fixes capture
with resampling.
2020-07-27 16:22:17 +02:00