I always wonder whether it is possible to make an amplifier of class D on ATtiny13 or not. Some time ago I found George Gardner’s project based on ATtiny85 – TinyD. It was a sign to start challenging it with ATtiny13. It took me a few hours but finally I made it! The code is very short and useses a lot of hardware settings which has been explained line-by-line in the comments. The project runs on ATtiny13 with maximum internal clock source (9.6MHz). It gave me posibility to use maximum of hardware PWM frequency (Fast PWM mode).
The PWM freqency of class D amplifiers should be of course much higher, a hundreds of kHz (some sources says 8 times more than sampling frequency). Unfortunately, in case of ATtiny13 it’s not posible to achieve such parameters. However, for experimentally selected settings of ADC sampling rate (~10kHz) and PWM frequency (37.5kHz) the amplifier sounds very good!