The trick to getting non-square waveforms out of a microcontroller is called PWM. To get audio signals up to 20 Khz, you would need to use at least 50KHz as the PWM frequency, 100KHz would be better. The PWM period is changed over a cycle of the designed waveform to match the voltage at that...