Update() vs audiobuffer/audioOut()

so I was messing around with some audio visual stuff with the Maximilian library and following along this kadenze course. Wanted to understand why and when I should be doing my algorithms in update() and when inside the audiobuffer?

for example, originally I was setting up timers inside update calculating milliseconds but then started using maxiClock which needs to work inside the audiobuffer - what’s the difference?

does update/draw/audiobuffer work at different cores/instances/calculations?

1 Like

Hi, the audio runs on a different thread than update/draw.
the audiobuffer callback gets called by the sound card, each time it needs to get new audio sample data. a usual buffer size is 256 samples, and 44100 is a common sample rate (how many samples there are per second), so in such conditions the audio buffer callback will get called 44100/256 = 172.265625 per second. (the buffer size and sample rate depend on how you configure your app/computer)

on the other hand, draw and update run on the same thread, which is OFs main thread. when you set ofSetVerticalSync(true), which is the default, the update will only get called once before the draw function, so update and draw are “synced”, this happens at the screen refresh rate, which is usually 60 times per second. So, for each draw call there is one update call.
When you set ofSetVerticalSync(false) the update and draw functions are out of sync. which means, the draw function gets called at the screen refresh rate, just like when verticalSync is true, but the update function gets called as many times as possible, so, once the update function is finished it gets called immediately again, and again.
hope it helps.


Thanks! I was wondering if this was the case - and your reply makes complete sense and clears out concepts in my head much better :slight_smile:

Cheers for sharing that man. Just enrolled myself in the course as well :wink: