From alsa-devel-owner@alsa.jcu.cz  Sun Jul 26 21:04:31 1998
Received: from entry.jcu.cz (perex@entry.jcu.cz [160.217.1.111])
	by marvin.jcu.cz (8.8.8/8.8.8) with SMTP id VAA27042;
	Sun, 26 Jul 1998 21:04:07 +0200
Date: Sun, 26 Jul 1998 21:04:07 +0200 (MET DST)
From: Jaroslav Kysela <perex@jcu.cz>
To: Alessandro Preite Martinez <vsg@arcetri.astro.it>
cc: alsa-devel@alsa.jcu.cz
Subject: Re: trigger functionality in ALSA
In-Reply-To: <199807221208.OAA03735@clio.arcetri.astro.it>
Message-ID: <Pine.LNX.3.96.980726204041.19648E-100000@entry.jcu.cz>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list

On Wed, 22 Jul 1998, Alessandro Preite Martinez wrote:

> 
> I appreciated much the work you've done with ALSA, and I'm pretty 
> satisfied of the functionality, but I've got a (simple) question:
> since I'm trying to move an application from the OSS interface to
> the ALSA one, I found no feature corresponding to OSS' SET_TRIGGER and
> GET_TRIGGER, which I need to syncronize full-duplex operations (actually
> I need to start playback and recording at very exact times), so I'm
> asking you how to implement something like that.
> Thank you in advance for yor help...

There is a little bit problem with synchronization between more
lowlevel drivers.

1. we can't trigger all inputs/output at exact same time
2. hardware (different soundcards) may have a little different clock,
   thus we can't guarantee, that two input/output streams will be
   exactly synchronized

Solution:

Use system clock for synchronization of playback & record. ALSA should
give to application very precise time when the playback or record was
started and at which time will be next sample played or get from record
stream.

Algorithm (example):

1. start playback with some small silence
2. start record (via select)
3. get and compare start time and compute delay + remove some samples
   from record stream until first playback sample will be played
4. after some time synchronize record & playback via status record
5. goto step 4.

Problems:

If system clock is changed, synchronization should fail :-((

Good thing:

You can good synchronize more streams with this method (for example 3
record streams and 6 playback streams, not only one record and one
playback stream as allows OSS driver).

Questions/ideas?


						Jaroslav

-----
Jaroslav Kysela <perex@jcu.cz>
Academic Computer Centre, University of South Bohemia
Branisovska 31, C. Budejovice, CZ-370 05 Czech Republic



