FILTRY 3, //1) Simple comb filter


//1) Simple comb filter

y=rrand(); // generate random signal

y = y + .99 * S1; // comb

tap 1 200 // 200 sample delay line

//----------------------------------------------------

//2) Plucked string filter

if(t < 100) y=rrand(); else y=0; // generate random numbers for

// first 100 samples only

y = y + .99 * S1; // comb

tap 2 1 // 1 sample feed forward delay

y = .5*y + .5 * S2; // lowpas

tap 1 100 // feedback delay

//----------------------------------------------------

//3) Comb with internal allpass filter

#define D -.5

#define LEN 60

if( t < LEN) y = rrand(); else y=0;

y = y + .99 * S1; //comb

tap 2 1

y = S2 + D * (y - S3); //allpass

tap 3 1

tap 1 100

//----------------------------------------------------

//4) Simple FM instrument

#define Phase two_PI*t/sr

float modulator,envelope,line;

line = (float)t/nsamps; //line from 0 to 1 over dur

envelope = exp(-3. * (float)t/sr); //exponential decay

modulator=20*line*sin(100.*Phase); //modulator

y= envelope * sin(modulator + 200. * Phase); //carrier

//----------------------------------------------------

//5) Simple two pole resonator

float cf,bw,a2,a1;

if(!t) { // initialize filter

cf=1000; // set center freq

bw=10; //set bandwidth

a2=exp(-2.* M_PI * bw/sr); // set coefficients

a1= 4. * a2/(a2+1) * cos(2 * M_PI * cf/sr);

}

y=rrand(); // white noise

y=y+a1*S1-a2*S2; // filter

tap 1 1

tap 2 2

//---------------------------------------------------

//6) Signal moving in stereo field

float cf,bw,a0,a1,a2,a3,pos,boost;

if(!t) { // setup two pole filter on white noise

cf=200; // with one zero, as per Julius Smith recommendation.

bw=4;

a0=exp(-M_PI * bw/sr);

a1=1.-a0;

a2= 2 * a0 * cos(2 * M_PI * cf/sr);

a3 = -a0*a0;

}

y=rrand();

tap 1 2

y=a1 * (y-a0*S1) + a2*S2 + a3*S3;

tap 2 1

tap 3 2

// set radio button (below) to stereo

pos = (float)t/nsamps; //current position

boost = 1./sqrt(pos*pos + (1.-pos)*(1.-pos)); //compensation

left = y * pos * boost; //left speaker

right = y * (1.-pos) * boost; //right speaker

//------------------------------------------------------

//7) Comb filter with changing length

y=rrand(); // generate white noise

y=y+.99*S1; // comb filter

L1 = 90. +((float)t/sr) * (-20); // change length of delay

tap 1 2000 // initialize very long delay

//---------------------------------------------------------

//8) Doppler shift

// make sure to toggle stereo button

#define c 769.3 /* speed of sound in mph */

#define Dfeet 20.0 /* distance from railroad tracks in feet */

#define s 50.0 /* speed of train in mph*/

float D, D2, duration, length, mid, d2, theta, x;

float p, boost;

float cf, bw, a2, a1;

if (!t)

{ D = Dfeet/5280.0; /* distance from railroad tracks in miles */

D2 = D*D;

duration = ((float)nsamps/sr)/3600.0; /* in hours */

length = s*duration;

mid = length/2.0;}

x = ((float)t/sr)*s/3600.0; /* current distance along track */

d2 = D2 + (x - mid)*(x - mid); /* distance-squared to train */

if (x < mid) theta = atan(D/(mid-x));

else if (mid==x) theta = M_PI/2;

else theta = atan(D/(mid-x))+M_PI; /* atan between -pi/2, pi/2 */

cf =500*(c/(c-s*cos(theta))); /* reson with doppler shift */

bw = 4;

a2 = exp(-2.*M_PI*bw/sr);

a1 = 4.*(a2/(a2+1))*cos(2*M_PI*cf/sr);

y = rrand();

y = y + a1*S1 - a2*S2;

tap 1 1

tap 2 2

left = y * cos(theta/2) /d2;

right = y * sin(theta/2 )/d2;



Wyszukiwarka