I write to the port using the ->port command. By turning on and off the port rapidly I can emulate a digital to analog converter.
Edit: Btw in the video it was just altering the duty cycle.
The square at 50% duty cycle sounds loud and at 10% the volume of the note is much lower. Real pwm using digital to analog conversion can be heard by the human ear, so I would have to add a capacitor and a resistor to filter the signal which is not a problem for me, but not everyone wants to make custom hardware for it to work. For those who do want to make this little circuit I will add support for custom waveforms and such, but otherwise you will be stuck to squarewaves.