Advice on Event Synchronization with Portaudio

1 view
Skip to first unread message

Eamon Kavanagh

unread,
Jul 29, 2026, 11:21:51 AM (7 days ago) Jul 29
to PortAudio Mailing List
Hey everyone,

I'm trying to write some software that synchronizes song beats with other events and I'm a bit confused on the correct way to approach this. I've read through this PDF and tried to implement a prototype of the "Synchronising Graphical Display" section as follows:

- Start filling a callback buffer with a fixed BPM click track and save the outputBufferDacTime as the start_time of the track.
- Listen to the output and try to click my mouse in time
- Whenever there's a click event, calculate the song_time as Pa_GetStreamTime(...) - start_time
- Use fmod(song_timebeat_duration) where beat_duration = 60 / BPM to determine how far off the beat I am.

Is this the right approach? When I try this I get fairly poor results and I'm usually off the beat by ~150ms. What I don't quite understand is if I instead calculate song_time each callback as  outputBufferDacTime - start_time Pa_GetStreamInfo(...).outputLatency, I get much better results and am off the beat by ~20ms.

Some additional information if it's helpful:
Sample Rate: 48000
Output Latency: 0.048
Frames per buffer: 256

Let me know if there's any other information I can provide.

Thanks,
Eamon

Reply all
Reply to author
Forward
0 new messages