[alsa-devel] USB Audio questions
clemens at ladisch.de
Tue Aug 16 08:37:01 CEST 2011
Pierre-Louis Bossart wrote:
> - Is there any good reason why the max number of packets per urb defaults to
Not really. It is an attempt to compromise between interrupt frequency
and the latency resulting from packet queueing.
> - Increasing the number of packets/urbs solves my power issue but not the
> synchronization issue. If I reduce the number of urbs to reduce the
> interrupt rate, then the accuracy of the hw_pointer is decreased big time
> and it becomes difficult to synchronize with video. The .pointer routine
> only keeps track of retired urbs, it seems there's no way to know how many
> samples were played at a given time?
Only the URB completion callback tells us about finished packets.
For playback, we know how many bytes we had submitted, so we could
derive the current position from the USB frame counter, but for capture,
we don't know the precise byte count until the HCD has looked at the
> Isn't there a direct way to query the usb core to know how many bytes
> have been transmitted and make the hw_ptr/delay information independent
> of the urb buffer size?
No, this information isn't returned earlier than the completion callback.
It would be nice to be able to tell the HCD to collect information about
all currently completed USB frames, regardless of whether the entire URB
has finished or whether its interrupt flag is set, but this would require
changes in all host controller drivers. (I'm contemplating something
like this for FireWire, but there we have only one controller driver.)
> - Is there any reason why the driver relies on vmalloc and memcpy? It seems
> like using physically-contiguous memory would be more efficient, as done in
> the CAIQ driver?
Why more efficient? You cannot avoid double-buffering when a USB packet
wraps around the end of the ALSA ring buffer.
> - The period information is not updated when the urbs are allocated. In my
> case the period specified was 25ms, but with all the approximations the
> actual period (number of urbs*buffer_size_per_urb) was 24ms.
Please note that URBs are usually not completely filled. For playback,
the driver makes URBs shorter so that they end as nearly as possible on
or after a period boundary; for capture, we cannot predict sample counts,
so the driver just uses one URB per ms.
More information about the Alsa-devel