On day 18 timestamp 20:15 [url=https://hero.handmade.network/episode/code/day018], Casey mentions 4 approaches to help prevent audio dropouts. I couldn't understand those approaches properly, I'll mention what I have understood from the video:
1) Enforcing a frame rate: This means that we write code in such a way that we always finish the computation for the next frame within our target frame rate. Thus audio buffer will always contain some "meaningful" sound for a specific frame.
2) Overwrite next frame: Assuming that our target frame rate is 30fps we'll need to output 0.033 seconds worth of audio within 0.033 seconds. In this approach, if we are currently displaying frame A (i.e we are currently computing frame A + 1), then we'll write audio buffer with samples for frame A+1 and A+2 i.e we'll write 0.066 seconds worth of audio per frame.(How can we write audio samples for frame A+2 without knowing events that occur in frame A+1?)
3)Frame of lag: From what I understood, this is same as method (2)
4)Guard thread: A thread will run concurrently, if the thread sees that enough time is left to compute audio samples for frame A+1 then the thread will do nothing, else it will fill the audio buffer with samples for frame A+1(What will it fill in the audio buffer for frame A+1?Is it a copy of the samples in audio buffer for frame A?)
Can someone explain me these approaches and correct me if I am wrong.
Sorry if this is a really simple question with an obvious answer.