PWM square wave decimator process in nyquist (audacity)

1.1k views Asked by At

I am trying to create a PWM effect such that a square-wave is modulated with PWM to approximate the input selection in Audacity. One could use this to hear what their favorite music would sound like in PC (or Apple ][) Squeaker Fidelity LOL :-) after applying a suitable filter effect.

My original thought was to create a saw oscillator and use it as reference for the comparitor step of PWM

the hard part is keeping track of the square wave flips based on the comparitor results

In C++ I'd just do it per sample using > and change the sign of the currently generating square sample as appropriate but this is audacity in windows (unlike linux where C/C++ compiler comes stock) so I've only got the Nyquist prompt to try to do this with

---assume mono sample input for simplicity---

using (> s (osc-saw 44100)) as comparison doesn't work

so I'm not sure where to go from here since the sample looping stuff in nyquist is very scary and evil

audacity doesn't have a plugin to do this effect... it only has a PWM tone generator

PS: I could use some examples of how to do the per-sample stuff in Nyquist.

1

There are 1 answers

1
hotpaw2 On

The saw-wave oscillator frequency needs to be much slower than the audio sample rate, slower by a factor related to the number of bits of PWM resolution desired. Then the audio input signal needs to be low pass filtered to below half the frequency of the saw wave oscillator before doing the comparitor step, perhaps with a cut-off frequency 4X below.