From: Clemens Ladisch <clemens@ladisch.de>
To: Ricard Wanderlof <ricard.wanderlof@axis.com>,
alsa-devel <alsa-devel@alsa-project.org>
Cc: Liam Girdwood <liam.r.girdwood@linux.intel.com>,
Takashi Iwai <tiwai@suse.de>, Mark Brown <broonie@kernel.org>
Subject: Re: [PATCH v2] ALSA: usb-audio: Fix max packet size calculation for USB audio
Date: Sat, 10 Oct 2015 10:48:33 +0200 [thread overview]
Message-ID: <5618D0E1.1000308@ladisch.de> (raw)
In-Reply-To: <alpine.DEB.2.02.1510100012390.7332@lnxricardw1.se.axis.com>
Ricard Wanderlof wrote:
> The addition of 0xffff ("almost 1" in Q16.16 format), resulting
> in the rounding up of the resulting value, was in the wrong place,
> as it is the resulting packet size that needs to be rounded up
> to the nearest integer (e.g. if the resulting packet size is
> calculated as 55.125 bytes, we need a packet of 56 bytes),
> rather than the rate value (ep->freqmax).
>
> Tested with an Edirol UA-5 both at 44.1 kHz and 96 kHz.
>
> Signed-off-by: Ricard Wanderlof <ricardw@axis.com>
> ---
> V2: Added tested device to commit message. No other changes.
>
> Since this clearly is a sensitive part of the code, here follows a lengthy
> rationale with examples to illustrate the problem.
There is a maximum size for USB packets, but not for git commit messages. :)
> [...]
> The problem here is that the addition of 0xffff is in the wrong place. We don't
> want the rounding up to take place on the frequency, but on the resulting
> packet size.
Packets must not contain partial frames, so the rounding must take place
on the number of frames per packet.
> Let's take an example. We have a sample rate of 96 kHz, so our
> ep->freqn is 786432 (see usb_high_speed_rate()). Add 25% (line 612) and we get
> 983040. The calculated maxsize is then ((983040 + 65535) * 8) >> 16 = 127 .
That code was intended to round correctly, but it's obviously wrong
because the result is not an integer multiple of the frame size.
(Please write Q16.16 values in hex.)
> However, if we do the number of bytes calculation in a less obscure way it's
> more apparent what the true corresponding packet size is: we get
> (96000 * 1.25 / 8000) * 8 = 120
The value inside the parentheses is the number of frames per packet, and
must be rounded.
> This is also corroborated by the wMaxPacketSize check on line 616. Assume
> that wMaxPacketSize = 108
It would not make sense to have a value that is not a multiple of the
frame size. (I'm not saying that it doesn't occur in practice ...)
Regards,
Clemens
next prev parent reply other threads:[~2015-10-10 8:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-09 22:16 [PATCH v2] ALSA: usb-audio: Fix max packet size calculation for USB audio Ricard Wanderlof
2015-10-10 8:48 ` Clemens Ladisch [this message]
2015-10-10 15:46 ` Ricard Wanderlof
2015-10-10 18:12 ` Ricard Wanderlof
2015-10-10 21:24 ` Ricard Wanderlof
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5618D0E1.1000308@ladisch.de \
--to=clemens@ladisch.de \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=liam.r.girdwood@linux.intel.com \
--cc=ricard.wanderlof@axis.com \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.