// WahWah v0.2 // by Benito class WahWah extends UGen { protected Envelope ff; float lowFreq = 400, highFreq = 8000; float attackTime = 100, attackExp = 1, decayTime = 100, decayExp = 1; double two_pi_over_sf; float res, n2res; float y1 = 0, y2 = 0, y0 = 0; float a1 = 0, a2 = 0, b0 = 0; WahWah(AudioContext context) { super(context, 1, 1); ff = new Envelope(context, lowFreq); two_pi_over_sf = TWO_PI / context.getSampleRate(); setRes(.99); } public void setRes(float res) { if(res < 0) { this.res = 0; } else if(res > .999999f) { this.res = .999999f; } else { this.res = res; } a2 = res * res; n2res = -2 * res; } void wah(float amt) { ff.clear(); ff.addSegment(highFreq, attackTime, attackExp, null); ff.addSegment(lowFreq, decayTime, decayExp, null); println("wah " + amt); } void calculateBuffer() { float[] bi = bufIn[0]; float[] bo = bufOut[0]; for(int i = 0; i < bi.length; i++) { /* // BUTTERWORTH shelf double pif = 2 * PI * env[i]; double k = pif / tan((float)(pif * sr2i)); a0 = (float)(pif / (k + pif)); b1 = (float)((pif - k) / (k + pif)); */ //b0 = env[i] * TWO_PI / 44100; //a1 = (b0 - 1) * q; //a2 = (b0 - 1) * (1 - q); float cosw = (float)Math.cos(ff.getValue(0, i) * two_pi_over_sf); a1 = n2res * cosw; b0 = 1 + a1 + a2; y2 = y1; y1 = y0; bo[i] = y0 = b0 * bi[i] - a1 * y1 - a2 * y2; } } } // WahEffect v0.1 // by Benito class WahEffect extends Effect { BiquadFilter filt; Envelope ff; float filtq = 1; float lowFreq = 1000, highFreq = 12000; float attackTime = 400, attackExp = 1, decayTime = 100, decayExp = .5; WahEffect(AudioContext context) { ff = new Envelope(context, lowFreq); filt = new BiquadFilter(context, BiquadFilter.LP, ff, filtq); in = filt; out = filt; } void hit(float amt) { ff.clear(); ff.addSegment(highFreq, attackTime, attackExp, null); ff.addSegment(lowFreq, decayTime, decayExp, null); //println("wah!"); } } class Effect extends Bead { UGen in, out; void addInput(UGen inp) { in.addInput(inp); } }