On Jan 8, 2011, at 5:41 PM, Roger Dannenberg wrote:
Excellent question -- I've been suggesting this as a student project forawhile, but have not had any takers. I recently implemented MIDI/Audiosynchronized playback in Audacity, but it's too complicated to serve asa reference implementation.
Then perhaps this is the best place for me to start. I will /try/ to write a simple app that does something like play a short tone and a midi note every second for ten seconds. I'll be able to hear if they line up, and you'll tell me if the code is correct. Honestly, I'm not so clear on the PA timing stuff.
I will ask questions as I go.When it's done, I can put the code up at the PortAudio website if the PA people agree its appropriate or you can put it up on your site, where I think it's definitely appropriate.
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 experimentalversion of PortAudio because an earlier version we had been using did not have audio output time implemented as well. I don't know whatsystems and API's support accurate audio output time. Long ago, we wrotesome 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 thesample output times. It worked pretty well, but illustrates how hard theproblem can be with "mainstream" audio APIs.
I'm going to pretend I won't have to think about this.
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 beglobal 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.)
Ah. Thanks.
bjorn
-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 EXACTLYright, and obviously that's important. You could be off by quite a bitand 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 samplecode 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
----------------------------- Bjorn Roche http://www.xonami.com Audio Collaboration
_______________________________________________ media_api mailing list [email protected] http://lists.create.ucsb.edu/mailman/listinfo/media_api
