Audio frequency generator: Difference between revisions
Content added Content deleted
(→{{header|SuperCollider}}: switch between sine wave, square wave and triangular sawtooth) |
(→{{header|SuperCollider}}: second example) |
||
Line 431: | Line 431: | ||
// use the cursor position to switch between sine wave, square wave and triangular sawtooth |
// use the cursor position to switch between sine wave, square wave and triangular sawtooth |
||
// the rounding and lag smoothes the transition between them |
|||
{ SelectX.ar(MouseX.kr(0, 2).round.lag, [ SinOsc.ar, Pulse.ar, LFTri.ar ]) * 0.1 }.play; |
{ SelectX.ar(MouseX.kr(0, 2).round.lag, [ SinOsc.ar, Pulse.ar, LFTri.ar ]) * 0.1 }.play; |
||
// the same expressed as an array of functions of a common phase |
|||
( |
|||
{ |
|||
var phase = LFSaw.ar; |
|||
var functions = [ |
|||
{ |x| sin(x * pi) }, |
|||
{ |x| x > 0 }, |
|||
{ |x| abs(x) }, |
|||
]; |
|||
var which = MouseX.kr(0, 2); |
|||
functions.sum { |f, i| |
|||
abs(which - i) < 0.5 * f.(phase) |
|||
} * 0.1 |
|||
}.play |
|||
) |
|||
// sound stops on exit |
// sound stops on exit |