Pwm

clean-up: #41

yet another small piece of code i found in my supercollider extensions folder.

it's very basic and just generates a pwm signal (pulse-width modulation). you could do the same thing quicker with the standard LFPulse, but sometimes it's good to roll your own just to see another approach.

Pwm {
        *ar {|freq= 100, width= 0.5|
                ^LFSaw.ar(freq)>(width* -2+1);
        }
        *kr {|freq= 100, width= 0.5|
                ^LFSaw.kr(freq)>(width* -2+1);
        }
}
/*
s.scope
//mouse controls pwm duty cycle
{Pwm.ar(300, MouseX.kr(0, 1))!2*0.2}.play
//simulating voltage
{Amplitude.ar(Pwm.ar(300, MouseX.kr(0, 1))).poll; DC.ar(0)}.play
*/