Linus Akesson and friends have created the “Craft” demo – using an ATmega88 to generate 4 channels of 8-bit sound and 3D graphics.

Timing is crucial: One display line takes 24 μs, and is followed by a 7.75 μs break called the horizontal blanking period. After 480 such lines, there’s a longer break (1428.75 μs, equal to 45 full display lines) before it all starts over. Two digital signals are used to synchronize the sender (graphics card, custom demo hardware etc.) and the receiver (monitor).
Sound is generated during the horizontal blanking periods. That gives a sample rate of 31496 kHz. Of course, only the really timing critical part (waveform generation) is performed during the horizontal blanking. Melody, rhythm, amplitude envelopes, arpeggios etc. are handled by a playroutine which gets called once for every video frame, during vertical blanking.

Craft demo