All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens-P6GI/4k7KOmELgA04lAiVw@public.gmane.org>
To: Laurent Pinchart
	<laurent.pinchart-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org>
Cc: alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	Steve Calfee
	<stevecalfee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Hal Murray <hmurray-8cQiHa/C+6Go9G/jEpaUCQ@public.gmane.org>,
	linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [RFC] ALSA vs. dedicated char device for a USB Audio Class gadget driver
Date: Fri, 15 May 2009 19:04:10 +0200	[thread overview]
Message-ID: <4A0DA08A.4040104@ladisch.de> (raw)
In-Reply-To: <200905151752.58040.laurent.pinchart-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org>

Laurent Pinchart wrote:
> On Friday 15 May 2009 17:07:30 Clemens Ladisch wrote:
> > Laurent Pinchart wrote:
> > > When streaming audio data from a real audio device to USB, the audio
> > > clock comes from the real audio device and is beyond control of the
> > > USB Audio Class gadget driver.
> >
> > In this case, you have _two_ clocks, the clock of the actual audio
> > device, and the USB SOF clock.  What you need to know is the relative
> > speed of these clocks, because that determines the number of samples per
> > USB frame.
> 
> If I use a synchronous endpoint, isn't the number of samples per frame
> determined by the nominal sampling rate and the nominal SOF frequency ?

Yes, but in _this_ case, the second case, you cannot use a synchronous
endpoint.  Since the real audio device controls the rate, this would be
an asynchronous endpoint.

> > I'd guess that your gadget driver does not have access to the real audio
> > device, so it is the application that must do the measurement.
> 
> That's right. The gadget driver doesn't care if data comes from a file or a
> real audio device.

I'd guess you don't want to restrict your gadget to reading from a file,
so you'll have to implement an asynchronous endpoint, and reading from
a file is just an uninteresting special case.

> > The ALSA API has no mechanism to tell the driver how fast to play, so it
> > looks as if you have to write you own device driver.
> 
> If I use a synchronous endpoint I can solve the problem on the driver side.
> There would still be a problem on the application side, as the audio source
> clock will obviously not be synchronous with the USB SOF clock. The userspace
> application will request audio data at a nominal rate equal to the nominal
> sample frequency advertised on USB, and will need to perform rate matching
> between its source (real audio device) and sink (USB driver). Is that (at
> least relatively) easy to do with ALSA ?

It is possible, but not trivially easy.

To measure the rate of the real audio device, you have to continually
(or regularly) correlate the sample position (derived from
snd_pcm_delay()) and some time stamp.  Using the computer's time would
introduce a third clock, so I'd guess you should use the USB SOF
interrupts as timer ticks (so your driver should notify the application
of SOFs).

With these measurements, you have the audio device rate, measured in
(i.e., relative to) the USB SOF rate.  With this relation, you can do
the rate matching; or you could use it to adjust the packet sizes of
the asynchronous endpoint, which I think is much easier.

> I suppose this is a common use case for all audio streaming
> applications such as internet radios, as in that case audio data
> streamed over the network will not be synchronous with the sound card
> audio clock and thus need to be resampled in the audio player before
> being sent to the sound card.

Or the player uses a buffer that is big enough so that there is enough
data even if the sound card runs faster than the server.  :-)


Best regards,
Clemens
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2009-05-15 17:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <laurent.pinchart@skynet.be>
     [not found] ` <200905141545.01798.laurent.pinchart-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org>
2009-05-14 18:18   ` [RFC] ALSA vs. dedicated char device for a USB Audio Class gadget driver Hal Murray
2009-05-14 20:58     ` Laurent Pinchart
     [not found]       ` <200905142258.42935.laurent.pinchart-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org>
2009-05-14 21:12         ` Steve Calfee
     [not found]           ` <4a5ff6bc0905141412t5ab4f0f5x6c50b4e38af0790f-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-05-14 21:25             ` Laurent Pinchart
     [not found]               ` <200905142325.24408.laurent.pinchart-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org>
2009-05-15  7:01                 ` [alsa-devel] " Clemens Ladisch
     [not found]                   ` <4A0D135C.7090806-P6GI/4k7KOmELgA04lAiVw@public.gmane.org>
2009-05-15  9:36                     ` Laurent Pinchart
     [not found]                       ` <200905151136.52995.laurent.pinchart-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org>
2009-05-15 15:07                         ` Clemens Ladisch
     [not found]                           ` <4A0D8532.4070104-P6GI/4k7KOmELgA04lAiVw@public.gmane.org>
2009-05-15 15:52                             ` Laurent Pinchart
     [not found]                               ` <200905151752.58040.laurent.pinchart-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org>
2009-05-15 17:04                                 ` Clemens Ladisch [this message]
2009-05-17 16:49                                   ` Laurent Pinchart
2009-05-15 20:15                                 ` Hal Murray
     [not found]                                   ` <20090515201519.7C347BCE6-1EH7ZSm6cX1tFMQ1DeeEjrzXk6sypdOaHzxsA6J8rrk@public.gmane.org>
2009-05-17 17:25                                     ` Laurent Pinchart
     [not found]                                       ` <200905171925.23956.laurent.pinchart-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org>
2009-05-17 21:28                                         ` Alan Stern
     [not found]                                           ` <Pine.LNX.4.44L0.0905171654500.20300-100000-pYrvlCTfrz9XsRXLowluHWD2FQJk+8+b@public.gmane.org>
2009-05-18 14:36                                             ` Laurent Pinchart
2009-05-18  8:39                                       ` Clemens Ladisch
     [not found]                                         ` <4A111EBC.2010606-P6GI/4k7KOmELgA04lAiVw@public.gmane.org>
2009-05-18 14:47                                           ` Laurent Pinchart
     [not found]                                             ` <200905181647.41771.laurent.pinchart-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org>
2009-05-19 11:01                                               ` Clemens Ladisch
2009-05-14 13:45 Laurent Pinchart

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=4A0DA08A.4040104@ladisch.de \
    --to=clemens-p6gi/4k7komelga04laivw@public.gmane.org \
    --cc=alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org \
    --cc=hmurray-8cQiHa/C+6Go9G/jEpaUCQ@public.gmane.org \
    --cc=laurent.pinchart-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=stevecalfee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /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.