Here is the basic concept behind a Class-D amplifier. The sine wave generator represents your audio signal. I've played with some of the reference voltages of the input signal so that it would give a clearer representation of what's going on. In practice, this design would perform poorly and sound terrible! In reality, your triangle wave would be at a much higher frequency, on the order of 4 Mhz+, your reference voltages would be much more precise and defined, and the comparator would feed either a driver or your output stage, which would then go to a low-pass filter before going into your speaker. This just illustrates the theory :)