I did a PWM demo on the Apple II using a format similar to the DPCM samples on the NES. Those samples have a pretty simple format: a 1 bit raises the amplitude, a 0 bit lowers it. So you're kinda approximating the waveform with a bunch of triangles.
The NES has a 7-bit DAC, but since we're bit-banging with the CPU we only have enough time between samples for about 13 levels. Each level has its own toggle-wait-toggle-wait routine, and then we shift another bit and decide whether to branch to the next (level+1) routine or the previous (level-1) routine.
https://8bitworkshop.com/v3.12.1/?platform=apple2&file=delta...