It is possible to have a larger buffer that can be opportunistically filled for such cases, say, you may fill 1024 future samples while only the first 256 will be processed soon and you don't have to touch the remainder unless something else happened, but AFAIK this is not how most audio APIs work because such opportunistic buffering can be done outside of the API anyway.
My recollection as a game producer who worked with musicians around that time is that this was all MIDI-like synthesis (although short, low-quality sampled "special effects" were possible) handled by dedicated hardware — Yamaha YM2612 on Genesis, Ricoh 2A03 on NES, etc. — and so lots more forgiving timing-wise.
- Old consoles had dedicated sound processing in them. In fact, they usually had both a dedicated sound mixer and a separate CPU core[0] to put the audio thread on. Hung audio threads in this case would mean musical slowdown rather than stuttering or crackling, which is noticeable in yet another different way.
- Source Engine does this, sort of. It loads just the first half a second of each sound it expects to play in a given level, which is used to hide I/O latency reading from disk. The particular failure mode of this solution, typically caused by a bunch of sounds triggering right after a level load, is that it takes longer than half a second to read all those files, and you hear that half-second sample stuttering instead of the audio.
[0] In several cases the audio CPU core would also serve as the primary CPU in backwards compatibility modes. For example, the Sega Genesis/Mega Drive has a Z80 in it that can run either the audio thread of a Genesis game or the primary thread of a Master System one. The PlayStation 2 does the same thing with having an "I/O processor" that's the PS1 CPU in a trenchcoat. The DS ARM7 is a holdover from the Game Boy Advance and, AFAIK, could also be used as an audio thread CPU if you wanted.
Some random thoughts:
- instead of having the system run into an “underrun”, perhaps it could use a fallback rule to just loop over the previously known buffer? That would be the equivalent of the last frame being displayed until a new one arrives.
- on old consoles, sound used to be _generated_ on the fly, usually in lockstep/in sync with the game thread. I think this used to work well because then the game would be the only thing running on the system. Not sure how this worked when consoles got dedicated sound cards later to offload sound processing.
- I guess one could load all of the game’s sound at startup, and let the audio thread just switch what to play when, with a default rule of what to play if no command is received. Not great memory-wise, though.