float getNextSample(){ float impact = osc[0]->getNextSample(); impact += osc[1]->getNextSample(); impact += osc[2]->getNextSample(); float body = impact; impact = bp->process(impact); impact *= eg[0]->getNextSample(); body = hp->process(body); body *= eg[1]->getNextSample(); return impact + body; }
void processAudio(AudioBuffer &buffer) { float tune = getParameterValue(PARAMETER_A)*10.0 - 6.0; float fc = getParameterValue(PARAMETER_B)*10.0 - 4.0; float q = getParameterValue(PARAMETER_C)*3+0.75; float shape = getParameterValue(PARAMETER_E)*2; float pw = 0.5; if(shape > 1.0){ pw += 0.49*(shape-1.0); // pw 0.5 to 0.99 shape = 1.0; // square wave } float df = getParameterValue(PARAMETER_D)*4; int di = (int)df; float gain = 0.0f; switch(di){ // a/d case 0: // l/s env.setAttack(1.0-df); env.setRelease(0.0); break; case 1: // s/s env.setAttack(0.0); env.setRelease(df-1); break; case 2: // s/l env.setAttack(df-2); env.setRelease(1.0); break; case 3: // l/l env.setAttack(1.0); env.setRelease(1.0); gain = df-3; break; } env.trigger(isButtonPressed(PUSHBUTTON), getSamplesSinceButtonPressed(PUSHBUTTON)); FloatArray left = buffer.getSamples(LEFT_CHANNEL); FloatArray right = buffer.getSamples(RIGHT_CHANNEL); // vco hz.setTune(tune); float lfreq = hz.getFrequency(left[0]); osc.setFrequency(lfreq); osc.setShape(shape); osc.setPulseWidth(pw); osc.getSamples(left); // vcf hz.setTune(fc); fc = hz.getFrequency(right[0]); fc = min(0.999, max(0.01, fc/(getSampleRate()*2))); // normalised and bounded filter->setLowPass(fc, q); right.copyFrom(left); filter->process(right); right.multiply(0.8-q*0.2); // gain compensation for high q // vca env.getEnvelope(envelope); envelope.add(gain); left.multiply(envelope); right.multiply(envelope); }
void processAudio(AudioBuffer &buffer){ float cutoff=getParameterValue(PARAMETER_A); float resonance=10*getParameterValue(PARAMETER_B); FloatArray fa=buffer.getSamples(0); // fa.noise(); filter->setLowPass(cutoff, resonance); filter->process(fa, fa, fa.getSize()); buffer.getSamples(1).copyFrom(fa); }
BiquadFilterTestPatch(){ registerParameter(PARAMETER_A, "Cutoff"); registerParameter(PARAMETER_B, "Resonance"); int stages=3; filter=BiquadFilter::create(stages); float cutoff=0.2; float resonance=2; //test setLowPass FloatArray coefficients=FloatArray::create(5*stages); FloatArray states=FloatArray::create(2*stages); FilterStage stage(coefficients, states); filter->setLowPass(cutoff, resonance); stage.setLowPass(cutoff, resonance); for(int k=0; k<stages; k++){ for(int n=0; n<5; n++){ float filterC=filter->getFilterStage(k).getCoefficients()[n]; float stageC=stage.getCoefficients()[n]; ASSERT(filterC==stageC, "Coefficients not initialized"); //check that filter coefficients are properly initialized } } int signalLength=100; FloatArray x=FloatArray::create(signalLength); FloatArray x1=FloatArray::create(signalLength); FloatArray y=FloatArray::create(signalLength); FloatArray y1=FloatArray::create(signalLength); x.noise(); x1.copyFrom(x); filter->process(x1, y1, x1.getSize()); //manually compute the filter float b0=filter->getFilterStage(0).getCoefficients()[0]; float b1=filter->getFilterStage(0).getCoefficients()[1]; float b2=filter->getFilterStage(0).getCoefficients()[2]; float a1=filter->getFilterStage(0).getCoefficients()[3]; float a2=filter->getFilterStage(0).getCoefficients()[4]; for(int n=0; n<stages; n++){ float d1=0; float d2=0; for(int n=0; n<x.getSize(); n++){ //manually apply filter, one stage y[n] = b0 * x[n] + d1; d1 = b1 * x[n] + a1 * y[n] + d2; d2 = b2 * x[n] + a2 * y[n]; } x.copyFrom(y); //copy the output to the input for the next iteration. INEFFICIENT } //done with the filter for(int n=0; n<x.getSize(); n++){ // ASSERT(abs(y[n]-y1[n])<0.0001, "");//BiquadFilter.process(FloatArray, FloatArray) result"); //TODO: fails for non-arm } FloatArray::destroy(x); FloatArray::destroy(x1); FloatArray::destroy(y); FloatArray::destroy(y1); debugMessage("All tests passed"); }
float getNextSample(){ float vca1 = sine->getNextSample(); vca1 += chirp->getNextSample(); vca1 *= env1->getNextSample(); float vca2 = 0.0f; vca2 += impulse->getNextSample(); // vca2 += filter->process(noise->getNextSample()); // vca2 *= env2->getNextSample(); vca2 += noise->getNextSample(); vca2 = filter->process(vca2); vca2 *= env2->getNextSample(); float sample = vca1*(1.0-balance) + vca2*balance; return sample; }
void processAudio(AudioBuffer &buffer) { float feedback, wet, _delayTime, _tone, delaySamples; _delayTime = getParameterValue(PARAMETER_A); feedback = 2*getParameterValue(PARAMETER_B)+0.01; _tone = getParameterValue(PARAMETER_C); wet = getParameterValue(PARAMETER_D); tone = 0.05*_tone + 0.95*tone; tf.setTone(tone); FloatArray buf = buffer.getSamples(LEFT_CHANNEL); highpass->process(buf); for (int i = 0 ; i < buffer.getSize(); i++) { delayTime = 0.01*_delayTime + 0.99*delayTime; delaySamples = delayTime * (delayBuffer->getSize()-1); buf[i] = dist(tf.processSample(buf[i] + (wet * delayBuffer->read(delaySamples)))); // delayBuffer->write(dist(tf.processSample(feedback * buf[i],0))); delayBuffer->write(feedback * buf[i]); } }
void processAudio(AudioBuffer &buffer){ int mode = getParameterValue(PARAMETER_A)*ZOELZER_MODES; float omega = (M_PI/2 - 0.01)*getParameterValue(PARAMETER_B) + 0.00001; // Frequency float K = tan(omega); float Q = getParameterValue(PARAMETER_C) * 10 + 0.1; // Resonance float gain = getParameterValue(PARAMETER_D); float V = abs(gain-0.5)*60 + 1; // Gain float norm; /* coeffs[b0, b1, b2, a1, a2] */ switch(mode){ case ZOELZER_LOWPASS_FILTER_MODE: norm = 1 / (1 + K / Q + K * K); coeffs[0] = K * K * norm; coeffs[1] = 2 * coeffs[0]; coeffs[2] = coeffs[0]; coeffs[3] = 2 * (K * K - 1) * norm; coeffs[4] = (1 - K / Q + K * K) * norm; break; case ZOELZER_HIGHPASS_FILTER_MODE: norm = 1 / (1 + K / Q + K * K); coeffs[0] = 1 * norm; coeffs[1] = -2 * coeffs[0]; coeffs[2] = coeffs[0]; coeffs[3] = 2 * (K * K - 1) * norm; coeffs[4] = (1 - K / Q + K * K) * norm; break; case ZOELZER_BANDPASS_FILTER_MODE: norm = 1 / (1 + K / Q + K * K); coeffs[0] = K / Q * norm; coeffs[1] = 0; coeffs[2] = -coeffs[0]; coeffs[3] = 2 * (K * K - 1) * norm; coeffs[4] = (1 - K / Q + K * K) * norm; break; case ZOELZER_NOTCH_FILTER_MODE: norm = 1 / (1 + K / Q + K * K); coeffs[0] = (1 + K * K) * norm; coeffs[1] = 2 * (K * K - 1) * norm; coeffs[2] = coeffs[0]; coeffs[3] = coeffs[1]; coeffs[4] = (1 - K / Q + K * K) * norm; break; case ZOELZER_PEAK_FILTER_MODE: if (gain >= 0.5) { norm = 1 / (1 + 1/Q * K + K * K); coeffs[0] = (1 + V/Q * K + K * K) * norm; coeffs[1] = 2 * (K * K - 1) * norm; coeffs[2] = (1 - V/Q * K + K * K) * norm; coeffs[3] = coeffs[1]; coeffs[4] = (1 - 1/Q * K + K * K) * norm; } else { norm = 1 / (1 + V/Q * K + K * K); coeffs[0] = (1 + 1/Q * K + K * K) * norm; coeffs[1] = 2 * (K * K - 1) * norm; coeffs[2] = (1 - 1/Q * K + K * K) * norm; coeffs[3] = coeffs[1]; coeffs[4] = (1 - V/Q * K + K * K) * norm; } break; case ZOELZER_LOWSHELF_FILTER_MODE: if (gain >= 0.5) { norm = 1 / (1 + M_SQRT2 * K + K * K); coeffs[0] = (1 + sqrt(2*V) * K + V * K * K) * norm; coeffs[1] = 2 * (V * K * K - 1) * norm; coeffs[2] = (1 - sqrt(2*V) * K + V * K * K) * norm; coeffs[3] = 2 * (K * K - 1) * norm; coeffs[4] = (1 - M_SQRT2 * K + K * K) * norm; } else { norm = 1 / (1 + sqrt(2*V) * K + V * K * K); coeffs[0] = (1 + M_SQRT2 * K + K * K) * norm; coeffs[1] = 2 * (K * K - 1) * norm; coeffs[2] = (1 - M_SQRT2 * K + K * K) * norm; coeffs[3] = 2 * (V * K * K - 1) * norm; coeffs[4] = (1 - sqrt(2*V) * K + V * K * K) * norm; } break; case ZOELZER_HIGHSHELF_FILTER_MODE: if (gain >= 0.5) { norm = 1 / (1 + M_SQRT2 * K + K * K); coeffs[0] = (V + sqrt(2*V) * K + K * K) * norm; coeffs[1] = 2 * (K * K - V) * norm; coeffs[2] = (V - sqrt(2*V) * K + K * K) * norm; coeffs[3] = 2 * (K * K - 1) * norm; coeffs[4] = (1 - M_SQRT2 * K + K * K) * norm; } else { norm = 1 / (V + sqrt(2*V) * K + K * K); coeffs[0] = (1 + M_SQRT2 * K + K * K) * norm; coeffs[1] = 2 * (K * K - 1) * norm; coeffs[2] = (1 - M_SQRT2 * K + K * K) * norm; coeffs[3] = 2 * (K * K - V) * norm; coeffs[4] = (V - sqrt(2*V) * K + K * K) * norm; } break; } int size = buffer.getSize(); float* samples = buffer.getSamples(0); float buf[size]; previous.process(samples, buf, size); previous.setCoefficents(coeffs); filter.setCoefficents(coeffs); filter.process(samples, size); for(int i=0; i<size; ++i){ float xfade = (float)i/(float)size; samples[i] = buf[i]*(1.0f-xfade) + samples[i]*xfade; } }