• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
AU MIDI out: threading problem with Logic
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AU MIDI out: threading problem with Logic


  • Subject: AU MIDI out: threading problem with Logic
  • From: Philippe Wicker <email@hidden>
  • Date: Mon, 17 Oct 2011 11:39:12 +0200

Hi all,

I'm currently working on the MIDI export from the AU version of a plugin. After having read the posts about the MIDIOutputCallback on this list I followed the path of the scheduling of the MIDI events slightly in the future using the CoreMidi API MIDISend (using the IAC driver), and I found an issue when the host is Logic. 

The issue is that Logic switches - or migrate - the thread on which the plugin audio callback is running when some events occur (eg when I start recording the MIDI). What I have understood is that Logic creates a pool of audio threads, I imagine it is made so to dispatch the load between the cores (I run my tests on an iMac using a 4-core i5 processor). This thread switch has the side effect to break my time line, and the recorded events are affected by an important jitter which I think is a result of my events time stamp being - after the the thread switch - in the past. The "time line" is something within the plugin which reconstruct an absolute time (needed by MIDISend) from a relative time (the sample position of the event in the current buffer). It saves the current host time (calling AudioGetCurrentHostTime()), and from there on computes the absolute time at which the events should be sent by adding to this "reference time" an "offset in the future" and a relative time derived from the accumulation of the sample position.

To demonstrate the behavior I've set the plugin so it sends an eighth note on each beat with a bpm set at 120. So I should get an event every 125ms (note ON then OFF then ON....).  I've also written a small command line executable which read these events sent by the plugin and periodically print a measure of the average period and the min/max jitter. When the MIDI out is enabled on the plugin the messages printed by my simple MIDI monitor shows a very steady events sequence with a jitter around +/- 200 microseconds. As soon as I start the recording on Logic the jitter increases to something around +/- 10/15 ms. I could correlate this behavior change to the thread switching.

For now the work around I've found is to restart  my internal plugin time line when I detect that the thread ID has changed in the IOProc. It should work as long as the thread is not changed while the recording is ON. 

Is there a safer solution?

This work around gives good results when I record on a track which is not the plugin's track. The results are a little bit degraded when I record on the plugin's track (the jitter is around -.4ms and +2.8 ms). The Logic buffer size is set to 128, and the "offset in the future" is set to 1024*22.676 microseconds (1024 times the sampling period at 44.1KHz). Same results when the offset is increased to 2048*22.676.  I'm a bit puzzled here. Anyone any idea?

By the way is it safe to call pthread_self and pthread_equal in the audio thread?

And finally, things would be so much simpler if the Logic guys had implemented the MIDIOutputCallback ........

Thanks,
Philippe

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: AU MIDI out: threading problem with Logic
      • From: Paul Davis <email@hidden>
  • Prev by Date: AUSampler details
  • Next by Date: Re: AU MIDI out: threading problem with Logic
  • Previous by thread: Re: AUSampler details
  • Next by thread: Re: AU MIDI out: threading problem with Logic
  • Index(es):
    • Date
    • Thread