void MIDIUIUgen_next(MIDIUIUgen *unit, int inNumSamples) { uint8 device = ZIN0(0); uint8 type = ZIN0(1); uint8 channel = ZIN0(2); float minval = ZIN0(3); float maxval = ZIN0(4); float warp = ZIN0(5); float lag = ZIN0(6); float y1 = unit->m_y1; float b1 = unit->m_b1; if (lag != unit->m_lag) { unit->m_b1 = lag == 0.f ? 0.f : (float)exp(log001 / (lag * unit->mRate->mSampleRate)); unit->m_lag = lag; } float value = (float)(gMIDIUIUgenGlobals[device][type][channel]).value/(float)127; if (warp == 0.0) { value = (maxval - minval) * value + minval; } else { value = pow(maxval/minval, value) * minval; } ZOUT0(0) = y1 = value + b1 * (y1 - value); unit->m_y1 = zapgremlins(y1); }
void LagIn_next_k(LagIn *unit, int inNumSamples) { //Print("->LagIn_next_k\n"); World *world = unit->mWorld; int numChannels = unit->mNumOutputs; float fbusChannel = ZIN0(0); if (fbusChannel != unit->m_fbusChannel) { unit->m_fbusChannel = fbusChannel; uint32 busChannel = (uint32)fbusChannel; uint32 lastChannel = busChannel + numChannels; if (!(lastChannel > world->mNumControlBusChannels)) { unit->m_bus = world->mControlBus + busChannel; } } float *in = unit->m_bus; float b1 = unit->m_b1; float *y1 = unit->m_y1; for (int i=0; i<numChannels; ++i, in++) { float *out = OUT(i); float z = *in; float x = z + b1 * (y1[i] - z); *out = y1[i] = zapgremlins(x); } //Print("<-In_next_k\n"); }
void KeyState_next(KeyState *unit, int inNumSamples) { // minval, maxval, warp, lag uint8 *keys = (uint8*)unit->gstate->keys; int keynum = (int)ZIN0(0); #ifdef __APPLE__ int byte = (keynum >> 3) & 15; #else int byte = (keynum >> 3) & 31; #endif int bit = keynum & 7; int val = keys[byte] & (1 << bit); float minval = ZIN0(1); float maxval = ZIN0(2); float lag = ZIN0(3); float y1 = unit->m_y1; float b1 = unit->m_b1; if (lag != unit->m_lag) { unit->m_b1 = lag == 0.f ? 0.f : exp(log001 / (lag * unit->mRate->mSampleRate)); unit->m_lag = lag; } float y0 = val ? maxval : minval; ZOUT0(0) = y1 = y0 + b1 * (y1 - y0); unit->m_y1 = zapgremlins(y1); }
void MouseY_next(MouseInputUGen *unit, int inNumSamples) { // minval, maxval, warp, lag float minval = ZIN0(0); float maxval = ZIN0(1); float warp = ZIN0(2); float lag = ZIN0(3); float y1 = unit->m_y1; float b1 = unit->m_b1; if (lag != unit->m_lag) { unit->m_b1 = lag == 0.f ? 0.f : (float)exp(log001 / (lag * unit->mRate->mSampleRate)); unit->m_lag = lag; } float y0 = gMouseUGenGlobals.mouseY; if (warp == 0.0) { y0 = (maxval - minval) * y0 + minval; } else { y0 = pow(maxval/minval, y0) * minval; } ZOUT0(0) = y1 = y0 + b1 * (y1 - y0); unit->m_y1 = zapgremlins(y1); }
void Lag_ar::m_signal(int n, t_sample *const *in, t_sample *const *out) { t_sample *nout = *out; t_sample *nin = *in; float y1 = m_y1; float b1 = m_b1; if (changed) { float b1_slope = CALCSLOPE(m_b1, n_b1); m_b1 = n_b1; for (int i = 0; i!= n;++i) { float y0 = ZXP(nin); ZXP(nout) = y1 = y0 + b1 * (y1 - y0); b1 += b1_slope; } changed = false; } else { for (int i = 0; i!= n;++i) { float y0 = ZXP(nin); ZXP(nout) = y1 = y0 + b1 * (y1 - y0); } } m_y1 = zapgremlins(y1); }
void LagControl_next_1(LagControl *unit, int inNumSamples) { float **mapin = unit->mParent->mMapControls + unit->mSpecialIndex; float *out = OUT(0); float z = **mapin; float x = z + unit->m_b1[0] * (unit->m_y1[0] - z); *out = unit->m_y1[0] = zapgremlins(x); }
static inline float diffuser_do(GVerb *unit, g_diffuser *p, float x){ float y,w; w = x - p->buf[p->idx] * p->coef; w = flush_to_zero(w); y = p->buf[p->idx] + w * p->coef; p->buf[p->idx] = zapgremlins(w); p->idx = (p->idx + 1) % p->size; return(y); }
void LagControl_next_k(LagControl *unit, int inNumSamples) { uint32 numChannels = unit->mNumOutputs; float **mapin = unit->mParent->mMapControls + unit->mSpecialIndex; for (uint32 i=0; i<numChannels; ++i, mapin++) { float *out = OUT(i); float z = **mapin; float x = z + unit->m_b1[i] * (unit->m_y1[i] - z); *out = unit->m_y1[i] = zapgremlins(x); } }
void Lag3_ar::m_signal(int n, t_sample *const *in, t_sample *const *out) { t_sample *nout = *out; t_sample *nin = *in; float y1a = m_y1a; float y1b = m_y1b; float y1c = m_y1c; float b1 = m_b1; if (changed) { float b1_slope = CALCSLOPE(m_b1, n_b1); m_b1 = n_b1; for (int i = 0; i!= n;++i) { float y0a = ZXP(nin); y1a = y0a + b1 * (y1a - y0a); y1b = y1a + b1 * (y1b - y1a); y1c = y1b + b1 * (y1c - y1b); ZXP(nout) = y1c; b1 += b1_slope; } changed = false; } else { for (int i = 0; i!= n;++i) { float y0a = ZXP(nin); y1a = y0a + b1 * (y1a - y0a); y1b = y1a + b1 * (y1b - y1a); y1c = y1b + b1 * (y1c - y1b); ZXP(nout) = y1c; } } m_y1a = zapgremlins(y1a); m_y1b = zapgremlins(y1b); m_y1b = zapgremlins(y1c); }
void MouseButton_next(MouseInputUGen *unit, int inNumSamples) { // minval, maxval, warp, lag float minval = ZIN0(0); float maxval = ZIN0(1); float lag = ZIN0(2); float y1 = unit->m_y1; float b1 = unit->m_b1; if (lag != unit->m_lag) { unit->m_b1 = lag == 0.f ? 0.f : (float)exp(log001 / (lag * unit->mRate->mSampleRate)); unit->m_lag = lag; } float y0 = gMouseUGenGlobals.mouseButton ? maxval : minval; ZOUT0(0) = y1 = y0 + b1 * (y1 - y0); unit->m_y1 = zapgremlins(y1); }
void RMS_next (RMS *unit, int inNumSamples) { float *out = ZOUT(0); float *in = ZIN(0); float freq = ZIN0(1); float p = unit->p; float y1 = unit->m_y1; float lastLPF = unit->last_lpf; float inVal; if (unit->last_freq != freq) { float newp = (1.f-2.f*tanf((freq/SAMPLERATE))); float pinc = (newp-p)/inNumSamples; unit->p=newp; unit->last_freq=freq; LOOP(inNumSamples, inVal = ZXP(in); lastLPF = (1.f-p)*(inVal*inVal)+ p*lastLPF; ZXP(out) = y1 = zapgremlins(sqrt(lastLPF)); p += pinc; );
void HPF_ar::m_signal(int n, t_sample *const *in, t_sample *const *out) { t_sample *nin = *in; t_sample *nout = *out; float y0; float y1 = m_y1; float y2 = m_y2; float a0 = m_a0; float b1 = m_b1; float b2 = m_b2; if (changed) { float pfreq = m_freq * mRadiansPerSample * 0.5; float C = tan(pfreq); float C2 = C * C; float sqrt2C = C * sqrt2; float next_a0 = 1.f / (1.f + sqrt2C + C2); float next_b1 = 2.f * (1.f - C2) * next_a0 ; float next_b2 = -(1.f - sqrt2C + C2) * next_a0; float a0_slope = (next_a0 - a0) * mFilterSlope; float b1_slope = (next_b1 - b1) * mFilterSlope; float b2_slope = (next_b2 - b2) * mFilterSlope; for (int i = 0; i!= mFilterLoops;++i) { y0 = ZXP(nin) + b1 * y1 + b2 * y2; ZXP(nout) = a0 * (y0 - 2.f * y1 + y2); y2 = ZXP(nin) + b1 * y0 + b2 * y1; ZXP(nout) = a0 * (y2 - 2.f * y0 + y1); y1 = ZXP(nin) + b1 * y2 + b2 * y0; ZXP(nout) = a0 * (y1 - 2.f * y2 + y0); a0 += a0_slope; b1 += b1_slope; b2 += b2_slope; } for (int i = 0; i!= mFilterRemain;++i) { y0 = ZXP(nin) + b1 * y1 + b2 * y2; ZXP(nout) = a0 * (y0 - 2.f * y1 + y2); y2 = y1; y1 = y0; } m_a0 = a0; m_b1 = b1; m_b2 = b2; changed = false; } else { for (int i = 0; i!= mFilterLoops;++i) { y0 = ZXP(nin) + b1 * y1 + b2 * y2; ZXP(nout) = a0 * (y0 - 2.f * y1 + y2); y2 = ZXP(nin) + b1 * y0 + b2 * y1; ZXP(nout) = a0 * (y2 - 2.f * y0 + y1); y1 = ZXP(nin) + b1 * y2 + b2 * y0; ZXP(nout) = a0 * (y1 - 2.f * y2 + y0); } for (int i = 0; i!= mFilterRemain;++i) { y0 = ZXP(nin) + b1 * y1 + b2 * y2; ZXP(nout) = a0 * (y0 - 2.f * y1 + y2); y2 = y1; y1 = y0; } } m_y1 = zapgremlins(y1); m_y2 = zapgremlins(y2); }
static inline float damper_do(GVerb *unit, g_damper *p, float x){ float y; y = x*(1.0-p->damping) + p->delay*p->damping; p->delay = zapgremlins(y); return(y); }
static inline void fixeddelay_write(GVerb *unit, g_fixeddelay *p, float x){ p->buf[p->idx] = zapgremlins(x); p->idx = (p->idx + 1) % p->size; }
void Dneuromodule_next(Dneuromodule *unit, int inNumSamples) { if(inNumSamples) { int size = unit->m_size; int numWeights = size * size; // printf("theta: "); // THETA for(int i=0; i < size; i++) { double val = (double) DEMANDINPUT_A(i + 1, inNumSamples); if(sc_isnan(val)) { Dneuromodule_end(unit); return; } //printf("%f ", val); unit->m_theta[i] = val; } // printf("weights: "); // WEIGHTS for(int i=0; i < numWeights; i++) { double val = (double) DEMANDINPUT_A(i + 1 + size + size, inNumSamples); if(sc_isnan(val)) { Dneuromodule_end(unit); return; } // printf("%f ", val); unit->m_weights[i] = val; } // keep normalized old values in a temporary array // so that we can overwrite the original directly for(int i=0; i < size; i++) { unit->m_x_temp[i] = std::tanh(unit->m_x[i]); } // iterate over all other values for each values and calcuate their contribution by weights. // printf("outputs: \n"); for(int i=0; i < size; i++) { double xval; xval = unit->m_theta[i]; for(int j=0; j < size; j++) { // printf("x = %f + %f * %f\n", xval, unit->m_weights[i * size + j], unit->m_x_temp[j]); xval += unit->m_weights[i * size + j] * unit->m_x_temp[j]; } xval = zapgremlins(xval); unit->m_x[i] = xval; // printf("-> %f ", xval); OUT0(i) = (float) xval; } //printf("\n"); } else { Dneuromodule_reset(unit, inNumSamples); } }