[alsa-devel] proposal: snd_pcm_start_at()

Takashi Iwai tiwai at suse.de
Mon Oct 6 11:45:57 CEST 2014


At Fri, 03 Oct 2014 17:24:22 -0500,
Pierre-Louis Bossart wrote:
> 
> On 10/3/14, 7:00 AM, Tim Cussins wrote:
> > Hi Peirre,
> >
> > On 02/10/14 18:41, Pierre-Louis Bossart wrote:
> >> On 10/2/14, 9:34 AM, Tim Cussins wrote:
> >>> Hi all,
> >>>
> >>> I'm Tim: I work at Linn Products Ltd - we make Network Music Players,
> >>> amongst other things.
> >>>
> >>> As you might imagine, synchronised-start is important when multiple
> >>> devices on the network are rendering the same audio. We'd be interested
> >>> in contributing a small expansion of the alsa-lib API to support
> >>> synchronised start.
> >>>
> >>> Assuming we can synchronise the audio clocks (I'm aware this is not
> >>> trivial - It's not the topic of this post), we'd propose something like:
> >>>
> >>>      int snd_pcm_start_at(snd_pcm_t* pcm, snd_htimestamp_t* tstamp);
> >>>
> >>> and playback would begin as close to tstamp as possible. If tstamp is in
> >>> the past, it would should return an error.
> >>>
> >>> Recent work by Takashi Iwai enables client code to set the clock type of
> >>> timestamps using snd_pcm_sw_params_set_tstamp_type(). This context could
> >>> quite naturally extend to tstamp argument of snd_pcm_start_at().
> >>>
> >>> Before I get stuck into working up the details under the hood, it'd be
> >>> good to get some feedback/objections regarding this approach.
> >>
> >> It's probably better idea to start PCM playback with a bunch of zeroes
> >> and then rely on existing timestamping to insert samples at the right
> >> location in the ring buffer - which you have to do anyway to compensate
> >> for drifts between your network clock and audio clock. This is a more
> >> predictable solution that abstracts away all the time needed to arm DMA,
> >> FIFOs, etc. The only hardware-dependent variable that would remain is
> >> the precision/granularity of the timestamping.
> >> -Pierre
> >
> > Thanks heaps for the feedback :)
> >
> > Agreed - streaming zeros 'as required' is pretty much the obvious
> > solution when confined to the existing API.
> >
> > So I guess I'll have to show a few more cards from my hand :D
> >
> > The next iteration of our hardware platform will be accompanied by a
> > move to linux, which explains our interest in ALSA for sound delivery.
> >
> > The pcm hardware for the new platform can start rendering when a compare
> > register matches a hw counter (driven by the audio clock). This allows
> > for starting with frame-accurate timing.
> 
> Interesting. I wonder if you actually need a new extension for this, you 
> could write the timestamp in an ALSA control and implement your .trigger 
> function by using the contents of the control, i.e. delay the actual 
> start. it wouldn't be generic but your hardware isn't either.

Well, your suggestion sounds really tricky.  The trigger is supposed
to trigger the stream immediately, and the delay isn't considered
there in principle.  The system can work with delays, but it's not in
a form of the initial design.

I think some synchronized triggering mechanism is missing in API, too.
There has been a similar request from others in the past (Digigram
wanted to have such a feature), so maybe it's not so uncommon
scenario.

This would be a good topic to be discussed in the upcoming audio
mini-summit, but both of you won't be there, right?


Takashi


More information about the Alsa-devel mailing list