[video output=day020 member=cmuratori stream_platform=twitch stream_username=handmade_hero project=code title="Debugging the Audio Sync" vod_platform=youtube id=hELF8KRqSIs annotator=jacebennett annotator=Miblo annotator=garlandobloom] [2:44][Fixing an off by one error] [5:12][Explanation of off by one errors] [7:13][Overview of the state of our audio code] [11:05][A breakdown of how time is spent during each frame] [14:07][A possible, though not great, solution to audio latency] [16:22][Tradeoff between audio lag and input lag] [17:51][Falling back to a little bit stupider] [21:58][Beginning to change the code for the audio output method] [22:48][Finding the minimum expected audio latency] [27:31][Converting to seconds using dimensional analysis] [31:34][Writing sound based on the audio latency] [34:14][Great aside about keeping code fluid and a bit messy in the early stages] [37:00][Determining the position to write the audio to] [46:27][How to deal with the low latency case] [51:16][A puzzling situation] [53:00][The aha moment] [55:34][The approach we will be taking for low latency] [57:36][The higher latency approach] [1:01:14][Another snag] [1:07:08][Putting our approach down in words] [1:13:02][Implementing the two case latency handling] [1:18:34][Do over due to deleted code] [1:20:08][Putting in the latency branching code] [1:23:35][Determining if the sound card is latent] [1:26:02][Mapping the WriteCursor and the PlayCursor into the same space] [1:27:51][Overview of the code determining how to write the sound] [1:30:00][Cleaning up] [1:31:22][How can we possibly predict how many bytes the game should write?] [1:33:02][Getting sound output separately with GameGetSoundSamples()] [1:36:45][More cleaning up] [1:37:43][Computing SafetyBytes] [1:39:06][Implementing GameGetSoundSamples() in the game code] [1:40:10][Testing is surprisingly successful, no bugs? NO WAY!] [1:42:47][Improving our sound output debug drawing] [1:48:25][Recording some additional details in our markers] [1:56:36][An assertion fires and some cleanup] [1:58:33][First look at the debug drawing output and adding global pause key] [2:02:38][Taking a good look at the debug drawing output] [2:04:40][A couple early questions] [2:05:47][Final Thoughts?] [2:06:42][Drawing another debug marker] [2:10:53][Improving our estimate of the PlayCursor position to reduce latency] [2:17:59][Taking a look at how our estimate lines up] [2:19:13][Drawing our 480 sample jitter window] [2:22:15][Q&A][:speech] [2:22:58][Did you try the audio without OBS?] [2:24:15][Is it inexpensive to query for the play cursor and the write cursor?] [2:25:03][Audio seems to be the most complex part until now, which will be the next most complicated thing?] [2:26:58][Audio asserts are a pain when you're debugging other things. Change to log messages.] [2:27:46][If we had a buffer that played from start to finish, would it be a valid syncing method to manually set AudioTimer = VideoTimer?] [2:28:45][Fully visualize waveforms and remove gradient. Turn entire thing into massive audio visualizer.] [2:29:42][Could you please increase ToneHz to 512, my crappy laptop speakers can't output 256?] [2:30:29][Will this audio system be able to handle music and sound, or will the game have to mux the audio for us?] [2:31:08][How will you make sure that you don't have regressions in some parts that are not that easy to spot right away?] [2:31:54][I'm sorry if I'm being slow, but I still don't truly understand why exactly the audio is jumping. It just seems like we should be able to handle it more simply.] [2:32:39][Why is the pitch of the sound changing after the game has been running a little while?] [2:39:55][Callback to earlier half of question: (I'm sorry if I'm being slow, but I don't truly understand why the audio is skipping.) The original audio skipped when we moved the latency to be inside of three frames.] [2:42:25][If it's not too much of an issue, can we have line numbers on the side when you are coding so we can get a grip of where you are.] [2:43:08][It's more likely to be the accumulation of a small value onto a larger value that is a numerical problem. Mantissas not lining up.] [2:44:03][Wrap-up][:speech] [/video]