Re: [LAD] writing a bpm counter with (or without) ALSA

From: Arnold Krille <arnold@email-addr-hidden>
Date: Sun Sep 26 2010 - 02:21:49 EEST

On Sunday 26 September 2010 01:08:21 Max Payne wrote:
> Hi guys,
> first of all forgive my not-so-perfect English :-)
> I'm writing down some code for a minimal loop player based on two threads:
> one handles a beat counter, the other feeds the soundcard with audio
> frames, through ALSA. When the beat counter has completed a full cycle
> (e.g. 4/4) it simply rewinds the PCM data to byte 0 making a seamless
> loop. Really straightforward. Now, I'm wondering how to implement the
> metronome side: should I rely on something like usleep/nanosleep or ALSA
> layer could offer an advanced timer? Another potential issue would come
> from latency, obviously present within the audio thread (due to ALSA):
> what happens when the beat counter restarts the audio sample but an alsa
> frame is still being written to the soundcard? Thank you in advance for
> any suggestion!

Why do you part a task that belongs together?

The most trusted clock to relate samples to real world time (which you want
for your beats/bars) is the sampling-clock. Which you get from the alsa-
thread. Why even bother to do the time-keeping in a different thread? Do all
your audio-stuff in one thread.

You should use a different thread when disk is accessed. Or when you do long
running math that you only need to be finished for the audio-block after the
current (or even later). And you would have a different thread for the gui
stuff. Most probably this thread is called the main-thread:-)

Have fun,

Arnold

_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev

Received on Sun Sep 26 04:15:04 2010

This archive was generated by hypermail 2.1.8 : Sun Sep 26 2010 - 04:15:04 EEST