View Single Post
 07-22-2009, 02:28 PM #6 cern.th.skei Human being with feelings     Join Date: Sep 2007 Location: trondheim, norway Posts: 317 a really cool initiative! here's some snippets i've used in a few plugins: a sin() approxamation for an oscillators, lfo, etc.. Code: ```desc:sinusoid (approximation) slider1: 55 < 1, 44100 > freq left - sinusoid slider2: 55 < 1, 44100 > freq right - sin() @init p0 = 0; p1 = 0; @slider r0 = (slider1/srate)*4; r1 = (slider2/srate); @sample // sinusoid p0+=r0; p0>2 ? p0-=4; s0 = p0*(2-abs(p0)); // sin() p1+=r1; p1>=1 ? p1-=1; s1 = sin(p1*(\$pi*2)); // spl0 = s0; spl1 = s1;``` another random/noise thing Code: ```desc:noise/random @init value = 19; // initialize b_noise = 19.1919191919191919191919191919191919191919; @sample // -1..1 b_noise = b_noise * b_noise; i_noise = floor(b_noise); // |0; b_noise = b_noise - i_noise; r0 = b_noise - 0.5; b_noise = b_noise + value; // 0..1 b_noiselast = b_noise; b_noise = b_noise + value; b_noise = b_noise * b_noise; b_noise = (b_noise+b_noiselast) * 0.5; i_noise = floor(b_noise); b_noise = b_noise - i_noise; r1 = b_noise; // spl0 = r0; spl1 = r1;``` and some filtering Code: ```desc:lowpass / weighted average slider1:0.5<0,1,0.001>weight @init n0 = 0; n1 = 0; @slider weight = slider1*slider1; // ??? @sample spl0 = (n0+=((spl0-n0)*weight)); // lowpass spl1 -= (n1+=((spl1-n1)*weight)); // highpass``` perhaps not scientifically correct, but useful when cpu and simplicity is important. the noise and sine things are around twice as fast as the builtin rand() and sin() functions. __________________ later..