Unwanted noise in wave generator

You will eventually burn out the output pin by driving a speaker directly, and possibly destroy the Due as well. Use an audio amplifier to drive the speaker.