Hi Fons,

Thanks for your ideas. This is how I've started to do it but was worried I was going down the wrong path.
Thanks for the flag tips, I'll do that.

Cheers,
Andrés

Fons Adriaensen wrote:
On Fri, Jul 06, 2007 at 06:48:54PM -0500, Andres Cabrera wrote:

The long title says it all... =) I want to pass some data generated
from real-time audio analysis to the main program (only in that
direction, i.e. only the jack callback writes to the structures). Are
there synchronization issues involved? Can I use a C++ object for this, or is that an absolute no,no?

You can use a C++ object for this (it's the cleanest way IMHO),
but there are some points to watch out for.

* Within the callback you cannot safely allocate and object.
  It must exist statically, or be allocated at a safe place,
  and pointer given to the callback.

* The main program has to know when it should read the object.
  Either use a flag in the object, and let the main program
  poll it periodically (if the delay is acceptable), or use
  a semaphore. POSIX semas are simple and easy to use, and
  you can signal them safely from within the callback.

* The callback has to know when it can (re)write the object.
  Clearly it should never wait on a sema, and it is already
periodic, so here you can use a flag in the object.
* If you use a flag and polling in both directions make
  sure to use two separate flags. One is read-only for
  the main program and write-only for the callback and
  vice versa.

Things get a bit (but not much) more complex if you need
more than one object, but this should get you started.


_______________________________________________
Linux-audio-dev mailing list
[email protected]
http://lists.linuxaudio.org/mailman/listinfo.cgi/linux-audio-dev

Reply via email to