The SID could play sampled sound by poking a click into the chip at an appropriate frequency, and some Commodore 64 games like Ghostbusters and Impossible Mission did this (though only for a few seconds, of course; it wouldn't take much sampled sound to exceed 64K).
This would seem to involve a tight loop whose timing would depend on the exact speed of the CPU.
But when tile-mode graphics are being displayed, as is usual for games, the CPU is locked out for one in eight scan lines ('bad lines'). This would seem to have the potential to alter the timing, thereby messing up the sound.
How did games playing sampled sound, solve this problem?