Ronan Whitteker     Fri, Jun 10, 2011  Permanent link
Ah yeah man.. much a preciated for that learning curve can be a slippery slope to no gumption!

Hey it seems like you know a bit about programming and i thought i might tell you my problem and if you have a solution then we could collaborate... I do a little java programming (processing).

What I do not understand if the best way to sync audio and video (with minimum precalculation).

I guess triggering the video from the audio but i haven't been able to get less than a whole buffer size worth of latency..

please help!!


p.s. ur evlv sftwr s vry nc
BenRayfield     Fri, Jun 10, 2011  Permanent link
If you look in the code of JSoundCard, you'll see how I control the sync of speakers and microphone. Its the code that uses my InterpolateBuffer class. There has to be some delay since its 2 different systems and the speaker output depends on what the microphone hears, but it calculates how to smoothly change that delay while keeping it small and avoiding an empty buffer which would make the sound jump. It changes the speed of consuming audio data (.99 to 1.01 usually, interpolated) based on those statistics. I created that system for audio in Java because I found that sometimes the speakers will run at 44.1 khz and the microphone at 44.2 khz, for example, so my code uses one a little faster than the other, interpolating between its data points continuously, to make them match, and it makes them not match a little when it needs to shrink the delay between them, then it pushes the ratio the other direction to balance it at the lower delay, and it continues like that.

You could use similar code between sound and video. My code (download at SourceForge at the link above) can be slightly modified to sync any audio in Java to anything else... video, mouse movements, anything you can write code to connect it to. Its math is for general synchronizing of things that change speeds continuously.

In Java you can display any pixels (realtime generated video, for example) using the java.awt.image.MemoryImageSource class. Its only realtime speed if you make the window very small, but I'm happy to have realtime video ability in Java at all, in standard Java with no plugins.
Ronan Whitteker     Mon, Jun 13, 2011  Permanent link
oh right thanks..

yeah I'm not so worried about being realtime as I AM ABOUT BEING IN SYNC.

lol, I think stretching the audio is getting a bit technical for me..

but yeah I think a lot of that stuff is beyond me at the moment. I should just focus on my mathematics. Thanks for the help :)

I think I will download the code and make the jump to genuine JAVA over processing :)