So basically one can generate a pwm by feeding the signal you want to process into one of the inputs of an op-amp and a sawtooth wave with a higher frequency into the other input. To convert it back you just need a low-pass filter. I didn’t calculate any values so it could probably work better than this.