Re: [PATCH v2 3/4] usb: gadget: f_uac2: send reasonably sized packets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 26 Aug 2014, Jassi Brar wrote:

> Cool... we can avoid runtime calculations by maybe picking the
> pre-defined 'length pattern' at module load time to match the rate
> selected. And have those many usb requests allocated and their
> 'length' initialized to the pattern. Then the rest of code would
> remain unchanged. Though I won't be surprised if you have some better
> idea.

The normal approach is to perform a simple runtime calculation (no 
pre-allocated pattern).  It's not complex.

Let S be the number of samples per second at the nominal transfer rate 
(for example, S = 44100).  Let R be the number of packets per second 
(1000 because you transfer one packet every millisecond).

Precompute M = DIV_ROUND_UP(S,R); that is the maximum number of samples
you ever have to send.  So the maxpacket value is M * (number of bytes
per sample), for example, M * 4 for 16-bit stereo.  That value should 
be stored in the endpoint descriptor.

Also precompute n = S / R and p = S % R (the truncated quotient and the
remainder).  Each packet will contain either n or n + 1 samples.  
Here's how you decide which:

When the data stream begins, set x = 0.  When preparing each packet,
do:

	if (x < R) {
		put n samples in the next packet;
	} else {
		x = x - R;
		put n + 1 samples in the next packet;
	}
	x = x + p;

That always gives exactly what you want.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux