Commit graph

66 commits

Author SHA1 Message Date
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
Wim Taymans
8f3771a56c alsa-pcm: also follow resampler insize when resampling
Use the input size of the resampler as the amount of samples to
read when we are resampling.
2020-07-27 15:57:27 +02:00
Wim Taymans
1ee8944a2a alsa: improve debug 2020-07-01 13:16:37 +02:00
Wim Taymans
8168dfdbc1 alsa-pcm: allow setting number of channels
Allow passing the number of channels when creating a device to
restrict the negotiated channels.
2020-07-01 12:54:27 +02:00
Wim Taymans
267eabaf69 alsa: add default channel map when not given 2020-07-01 12:46:03 +02:00
Wim Taymans
f65d71dd5b alsa: support planar formats 2020-07-01 11:43:25 +02:00
Wim Taymans
d2bd076a97 alsa: close output handler to avoid a leak 2020-06-02 17:13:26 +02:00
Wim Taymans
8dcd6c4417 improve debug 2020-05-09 19:21:55 +02:00
Wim Taymans
1ca7713057 implement NEAREST flag
when the NEAREST flag is set and the param could not be completely
set, set_param should return 1 to indicate this.
2020-05-08 17:52:30 +02:00
Wim Taymans
b53cc6feb8 improve debug
Log device name and stream direction
Don't log xrun errors in alsa, we signal the xrun signal, which should
take care of logging if any.
Log quantum in xrun.
ratelimit xrun messages.
2020-05-08 12:13:59 +02:00
Wim Taymans
aafd1e7298 improve debug
Improve log so that debug level 3 gives a reasonably readable overview
of what is going on.
2020-04-22 12:47:18 +02:00
Wim Taymans
441fdb2333 alsa: fix buffer recycle
We only set the OUT flag when we put the buffer on an io area and
might need to recycle later.
Before placing the output buffer into the io area, recycle any
buffer that might be left in there.
Only emit the ready callback when we have some data queued.
2020-03-19 13:12:49 +01:00
Wim Taymans
949dba7bfc fmt-ops: flesh out avx optimizations 2020-03-17 17:27:47 +01:00
Wim Taymans
72d70b0f48 Add and fix some more warnings
Fixes #216
2020-03-17 11:37:56 +01:00