When we start freewheeling, pause the device and resume when we
finish freewheel.
In freewheel mode, just discard samples in the sink and produce
silence in the source.
SPA_MEMBER is misleading, all we're doing here is pointer+offset and a
type-casting the result. Rename to SPA_PTROFF which is more expressive (and
has the same number of characters so we don't need to re-indent).
The start-delay adds extra silence to the buffer before starting the
playback. The idea is to have more time to adapt to the device
startup and set the timer more accurately.
See #983, #431
When we are following the resampler requested size in capture, never
keep queued buffers around or we might get out of sync with the
requested size and cause cracks and pops in the resampler.
See #805
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
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.
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.
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.
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.
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
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.
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.
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.
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
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.
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>
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.