I’m confused as to how the SDL audio callback works.
I have set it up with a sample rate of 2048, and each time it calls back to my code it asks for 2048 samples. I use that sample rate to control timing of queuing up wave files (similar to DT42). And the whole thing sounds fine: if I sequence out a beat at 120 bpm and play them using the callback logic and my scheduler, everything triggers at the right time.
But if I throw a std::chrono timer into the callback loop, I get wildly different times between calls to the callback. 90ms, 50ms, 40ms, etc.
That doesn’t make any sense to me. How can a callback asking for a fixed amount of data but inconsistently called produce consistent audio?
This is a big problem for me right now because I am trying to synchronize visuals with my audio playback. My render thread runs much faster than my audio thread, so if I use a ‘beat time’ updated based on the number of samples requested by the DSP, I get stuttering (because it only updates the time every 2048 samples, apparently at an inconsistent rate).