mrmixer
It doesn't sound at all like your recording on my side (could the recording be wrong, because it doesn't sound like what you describe) ?
It sounds, is 1/120 of tone and 1/120 of silence. 60 times per seconds. That is the result. In line `sdl_game.c:162` replace `perf->game_update_hz` with value `120`, you will get something like the weird noise.
mrmixer
On my machine (manjaro linux in a virtual machine), the sound is ok except for a glitch after 1 second, and it seems that the glitch is kept in the next loop into the buffer, with an offset, so the sound become worse with time (first loop there is a glitch after 1 second, then there are 2 glitches, at different times, than 3 ...). So it seems that either the copy from the game memory to the global buffer, or the copy from the global buffer to the sdl data has an issue.
Indeed this also happens...
mrmixer
In sdl_SoundGetCursors you're multiplying sound_output->safety_bytes by sound_output->bytes_per_sample but that should already be in bytes. Removing that improved the situation for me, I'm left with only a single glitch when the ring buffer loops.
Indeed.
mrmixer
I tried to fill the buffer with a sine wave at 240hz (multiple of 48000hz) at startup, never update the buffer after that and just send that to sdl, but it still had a glitch (although it was hard to hear). I wasn't able to debug that as my the virtual machine is quite slow and working on it is painful, but I would suggest you to get that running, before continuing on other things.
What running? Audio? If so, yes, I would like much. I'm almost throwing all that code away and rewriting it from some day ahead (like 30) where the plataform layer reached some point. But I really want to understand what wrong is happening there, otherwise I will be just postponing the problem.
mrmixer
I'm assuming you're trying to stay close to the handmade hero code, because otherwise you could probably simplify the code (and you probably should as the DirectSound API is probably not the best thing to imitate and handmade hero has still not done much in term of audio).
Yes, as close as I can, except I use pure C, snake_case, avoid globals, put things in extenal function calls and using SDL.
What do you think about SDL_AudioQueue vs SDL_AudioCallback?
Should Queue the next frame seconds (in fact 1/FPS ms) be reasonable? Like in start of every game loop clean queue and requeue next frame audio (that to avoid queue to get too behind game updates)? What about audio continuity? It will suffef from those clicks and clancks when resetting audio?
I'm really concerned about audio part, is too important to me in game development.