Sync animation to audio, accuracy question

For my project I need to synchronise visual effects with particular samples during playback.

So lets say I want to make a program ‘sync.exe’ so that when I run the command ‘sync.exe tune.wav 36044’, it should play the audio file and when sample #36044 is output from the sound card, a big red box gets put on the screen

So before delving too deeply into the framework I was hoping that some experienced JUCE people might shed some light on to what kind of sync error I would likely experience. Could I achieve a solution where the user would not perceive a delay between hearing sample #36044 and seeing the box appear on the screen?

Lets say [box_appear_time]-[sample-time] < [plus_or_minus_10ms]

Assuming a pretty low-end system - windows xp - direct sound - cheapo builtin sound card.

I have seen various posts regarding output latencies and problems with direct sound, so would love to know how possible this would be, or whether another library would be better - PortAudio/RTAudio/etc

thanks for any pointers

The main problem with DSound is that it’s not possible to sync its input and output channels accurately. If you just need to get the playback position to within 10ms then it should be able to manage that.

All the other device types report accurate latencies.

And bear in mind that you should use WASAPI for Vista/Win7, so it’s only XP users who still need DSound.

Thanks for the reply,

having read my own post I realise my requirements are pretty low, I just need to poll the playback position every so often.

In JUCE is there a nice function to read the playback position (that handles all the latency calculations for me)? or would I need to do this in my audioIO callback - recording the last sample put into the audio buffer and then adding some output latency estimate?

Bit of a newbie question sorry!

I think AudioTransportSource has a method, if you’re using that. Can’t remember if it adds the latency, but that’s pretty simple to do.