Excellent question -- I've been suggesting this as a student project for 
awhile, but have not had any takers. I recently implemented MIDI/Audio 
synchronized playback in Audacity, but it's too complicated to serve as 
a reference implementation.

I'm not totally sure about the proper way to get audio output time from 
PortAudio, and we recently upgraded Audacity to use a more experimental 
version of PortAudio because an earlier version we had been using did 
not have audio output time implemented as well. I don't know what 
systems and API's support accurate audio output time. Long ago, we wrote 
some code for winmm, which transfers samples to devices through a list 
of buffers. The timing of buffers was full of jitter, so we had some 
complicated smoothing software (maybe Kalman filters) to estimate the 
sample output times. It worked pretty well, but illustrates how hard the 
problem can be with "mainstream" audio APIs.

The void * argument in PmTimeProcPtr is a copy of the pointer you pass 
in as the time_info parameter to Pm_OpenOutput(). It can be anything, 
but typically would either be NULL or a pointer to a data structure that 
the PmTimeProcPtr might need to compute the time. (This could easily be 
global information such as system time or audio time, but it's 
conceivable that you would want to sync different midi streams to 
different time sources.)

-Roger


On 1/8/11 4:18 PM, Bjorn Roche wrote:
> Hey all,
>
>       I see that it's possible to synchronize midi events in PortMidi with
> audio playback in PortAudio using the PmTimeProcPtr in Pm_OpenInput.
> Okay, good enough, and I understand the principle. However, in this
> world where computers are finally capable of reasonably low latency,
> it's not always obvious when you get these sorts of things EXACTLY
> right, and obviously that's important. You could be off by quite a bit
> and it would be hard to tell without scrupulous testing -- but users
> would know! Moreover, it seems like there's a lot of hard to track
> down subtly here: PmTimeProcPtr takes a void * argument. What's that?
> I even saw this terrifying code when digging for answers on the PA
> mailing list:
>
> http://music.columbia.edu/pipermail/portaudio/2004-September/003832.html
>
> OMG!
>
> So..... this seems like a common enough use-case. Is there some sample
> code for synchronizing PortAudio and PortMidi? This would be a huge
> plus!
>
>       bjorn
>
> -----------------------------
> Bjorn Roche
> http://www.xonami.com
> Audio Collaboration
>
> _______________________________________________
> media_api mailing list
> [email protected]
> http://lists.create.ucsb.edu/mailman/listinfo/media_api
>
_______________________________________________
media_api mailing list
[email protected]
http://lists.create.ucsb.edu/mailman/listinfo/media_api

Reply via email to