[alsa-devel] Alsa timing question
Olivier Guillion - Myriad
olivier at myriad-online.com
Fri Aug 26 10:29:52 CEST 2011
Raymond Toy wrote:
> > > I'm working on an application where I'd like to have relatively fixed
> > timing
> > > between calls to snd_pcm_writei.
> > Why?
> It's a bit complicated. A different process generates the audio and places the
> data in a shared memory area. My process sends signals the other process to
> generate more data, I read the shared memory area (for the previously generated
> data). Sometime later, the other process fills the shared area with new
> samples. Thus, if the timing between calls is not fairly regular, I'll either
> reread the same data or miss the new data. (I'm not in control of how this
> works. I just have to deal with what I'm given.)
IMO, it's not a good idea to try to synchronize perfectly two processes by way
of an interrupt.
If the generating process has to remain untouched, you should probably
bufferize its data in your own process before sending it to writei. It would
add some latency, but make the data flow safer.
Here is how it could work:
1- Your process writes a "magic" pattern at the end of the shared area
2- It sends a signal to the other process to make it generate data
3- It checks whether the magic pattern is still here
4- When changed, it means the data have been calculated. It saves them to an
internal circular buffer
5- If the circular buffer is not full, it restarts at 1-
6-In parallel, when data can be written to the device through writei, they are
taken from the circular buffer.
Hope this helps,
More information about the Alsa-devel