Ejemplo n.º 1
0
void AmplitudeMod_next(AmplitudeMod* unit, int inNumSamples)
{
	float *out = ZOUT(0);
	float *in = ZIN(0);
	float clamp = ZIN0(1);
	float relax = ZIN0(2);

	if (unit->m_clamp != clamp) {
		unit->m_clamp = clamp;
		unit->m_clampcoef = clamp == 0.0 ? 0.0 : exp(log1/(clamp * SAMPLERATE));
	}

	if (unit->m_relax != relax) {
		unit->m_relax = relax;
		unit->m_relaxcoef = relax == 0.0 ? 0.0 : exp(log1/(relax * SAMPLERATE));
	}

	float relaxcoef = unit->m_relaxcoef;
	float clampcoef = unit->m_clampcoef;
	float previn = unit->m_previn;

	float val;
	LOOP(inNumSamples,
		val = fabs(ZXP(in));
		if (val < previn) {
			val = val + (previn - val) * relaxcoef;
		} else {
			val = val + (previn - val) * clampcoef;
		}
		ZXP(out) = previn = val;
	);
Ejemplo n.º 2
0
Archivo: Lag.cpp Proyecto: Angeldude/pd
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);
}
Ejemplo n.º 3
0
	void next_k(int inNumSamples)
	{
		float newFreq        = in0(1);
		float newQ           = in0(2);
		float newHPCutoff    = in0(3);

		if (q != newQ)
			set_q(newQ);

		if (newHPCutoff != hpCutoff)
			setFeedbackHPF(newHPCutoff * sampleDur());

		double a, a_inv, a2, b, b2, c, g, g0;
		calcFilterCoefficients(newFreq, a, a2, a_inv, b, b2, c, g, g0);

		double z0 = z[0];
		double z1 = z[1];
		double z2 = z[2];
		double z3 = z[3];
		double z4 = z[4];

		const float * inSig = zin(0);
		float * outSig = zout(0);

		for (int i = 0; i != inNumSamples; ++i) {
			double x = ZXP(inSig);
			ZXP(outSig) = tick(x, a, a2, a_inv, b, b2, c, g, g0, z0, z1, z2, z3, z4);
		}
		z[0] = z0;
		z[1] = z1;
		z[2] = z2;
		z[3] = z3;
		z[4] = z4;
	}
Ejemplo n.º 4
0
void scmul_ar::m_signal(int n, t_sample *const *in, 
			    t_sample *const *out)
{
    t_sample *nin = *in;
    t_sample *nout = *out;

    if (changed)
    {
	float xb = m_nextfactor;
	float slope =  CALCSLOPE(xb, m_factor);
	for (int i = 0; i!=n; ++i)
	{
	    ZXP(nout) = ZXP(nin) * xb;
	    xb += slope;
	}
	m_factor = xb;
	changed = false;
    }
    else
    {
	float xb = m_factor;

	for (int i = 0; i!=n; ++i)
	{
	    ZXP(nout) = ZXP(nin) * xb;
	}
    }
}
Ejemplo n.º 5
0
void LPZ1_ar::m_signal(int n, t_sample *const *in, 
			  t_sample *const *out)
{
    t_sample *nin = *in;
    t_sample *nout = *out;

    float x0;
    float x1 = m_x1;

    int t = n >> 2;
    for (int i = 0; i!= t;++i)
    {
	x0 = ZXP(nin); 
	ZXP(nout) = 0.5f * (x0 + x1);
	x1 = ZXP(nin); 
	ZXP(nout) = 0.5f * (x1 + x0);
	x0 = ZXP(nin); 
	ZXP(nout) = 0.5f * (x0 + x1);
	x1 = ZXP(nin); 
	ZXP(nout) = 0.5f * (x1 + x0);
    }
    
    t = n & 3;
    for (int i = 0; i!= t;++i)
    {
	x0 = ZXP(nin); 
	ZXP(nout) = 0.5f * (x0 + x1);
	x1 = x0;
    }
    m_x1 = x1;
}
Ejemplo n.º 6
0
void Squiz_next(Squiz *unit, int inNumSamples)
{
	float *in = ZIN(0);
	float *out = ZOUT(0);

	float *buf = unit->m_buf;
	int buflen = unit->m_buflen;

	float ratio = sc_min(sc_max(ZIN0(1), 1.0f), (float)buflen); // pitch ratio; also === the sample-by-sample readback increment
	int zcperchunk = (int)ZIN0(2);

	int writepos = unit->m_writepos;
	float prevval = unit->m_prevval; // Used for checking for positivegoing zero crossings
	float readpos = unit->m_readpos; // Where in the buffer we're reading back from. Float value for accuracy, cast to uninterpolated int position though.
	int zcsofar = unit->m_zcsofar;

	float curval, outval;
	int readposi;
	for (int i=0; i < inNumSamples; ++i)
	{
		// First we read from the buffer
		readposi = (int)readpos;
		if(readposi >= buflen){
			outval = 0.f;
		}else{
			outval = buf[readposi];
			// postincrement the play-head position
			readpos += ratio;
		}

		// Next we write to the buffer
		curval = ZXP(in);
		writepos++;

		// If positive-going zero-crossing (or if buffer full), this is a new segment.
		//Print("zcsofar: %i\n", zcsofar);
		if((writepos==buflen) || (prevval<0.f && curval>=0.f && (++zcsofar >= zcperchunk))){
			writepos = 0;
			readpos = 0.f;
			zcsofar = 0;
		}
		buf[writepos] = curval;

		//Print("prevval: %g, curval: %g, on: %i, drop: %i, outof: %i, mode: %i\n", prevval, curval, on, drop, outof, mode);

		// Now output the thing we read
		ZXP(out) = outval;
		prevval = curval;
	}

	// Store state
	unit->m_writepos = writepos;
	unit->m_readpos = readpos;
	unit->m_prevval = prevval;
	unit->m_zcsofar = zcsofar;
}
Ejemplo n.º 7
0
void BBlockerBuf_next_i(BBlockerBuf *unit, int inNumSamples) {
	// buffer access
	GET_BUF
	uint32 numInputChannels = 1; // input should be one channel.
	if (!bbcheckBuffer(unit, bufData, bufChannels, numInputChannels, inNumSamples))
		return;

	// get info from unit
	machine &m = unit->bblocker;
	// thread  t  = m.get_thread();

	float *pCOut       = ZOUT(0);

	float *stackOut0  = ZOUT(1);
	float *stackOut1  = ZOUT(2);
	float *stackOut2  = ZOUT(3);
	float *stackOut3  = ZOUT(4);
	float *stackOut4  = ZOUT(5);
	float *stackOut5  = ZOUT(6);
	float *stackOut6  = ZOUT(7);
	float *stackOut7  = ZOUT(8);

	float  freq    = ZIN0(1);
	double phase   = unit->m_phase;
	float  freqmul = unit->m_freqMul;

	// get heap from buffer
	/* 		Cast bufData (float()) to u8 and put it into machine's heap. 
			For now, I assume the buffer to be HEAP_SIZE elements (i.e. 256). 
			Buffer items should range between 0 and 255.	*/
	for(size_t i = 0; i < HEAP_SIZE; i++) {
		m.m_heap[i] = (u8) bufData[i];
	}

	// compute samples
	LOOP1(inNumSamples,
		if (phase >= 1.f) {
			//printf("running: %f (%e * %f)\n", phase, ZXP(freq), freqmul);
			phase -= 1.f;
			m.run();
		}
		phase += freq * freqmul;

//		printf("1: %d  %d\n", m.get_thread().m_pc, m.get_thread().at(0));

		// out must be written last for in place operation
		ZXP(pCOut)     = ((float) m.get_thread().m_pc  / 127.f) - 1.f;
		ZXP(stackOut0) = ((float) m.get_thread().at(0) / 127.f) - 1.f;
		ZXP(stackOut1) = ((float) m.get_thread().at(1) / 127.f) - 1.f;
		ZXP(stackOut2) = ((float) m.get_thread().at(2) / 127.f) - 1.f;
		ZXP(stackOut3) = ((float) m.get_thread().at(3) / 127.f) - 1.f;
		ZXP(stackOut4) = ((float) m.get_thread().at(4) / 127.f) - 1.f;
		ZXP(stackOut5) = ((float) m.get_thread().at(5) / 127.f) - 1.f;
		ZXP(stackOut6) = ((float) m.get_thread().at(6) / 127.f) - 1.f;
		ZXP(stackOut7) = ((float) m.get_thread().at(7) / 127.f) - 1.f;
	)

	// write back to unit, resp. buffer
	for(size_t i = 0; i < HEAP_SIZE; i++) {
Ejemplo n.º 8
0
void LPF18_next(LPF18 *unit, int nsmps)
{
  float *in = ZIN(0);
  float *out = ZOUT(0);
  float fco = ZIN0(1);
  float res = ZIN0(2);
  float dist = ZIN0(3);

  float aout = unit->aout;
  float ay1 = unit->ay1;
  float ay2 = unit->ay2;
  float lastin = unit->lastin;
  float kfcn, kp = unit->kp;
  float kp1, kp1h;


  if (fco != unit->last_fco) {
	  kfcn = 2.0f * unit->last_fco * SAMPLEDUR;
	  kp1 = kp+1.0f;
	  kp1h = 0.5f*kp1;

	  float newkfcn = 2.0f * fco * SAMPLEDUR;
	  float newkp = ((-2.7528f*newkfcn + 3.0429f)*newkfcn +
			   1.718f)*newkfcn - 0.9984f;
	  float newkp1 = kp+1.0f;
	  float newkp1h = 0.5f*kp1;
	  float kp1hinc = (newkp1h-kp1h)/nsmps;
	  float kpinc = (newkp-kp)/nsmps;
	  float kres = unit->kres;
	  float newkres = res * (((-2.7079f*newkp1 + 10.963f)*newkp1
				  - 14.934f)*newkp1 + 8.4974f);
	  float kresinc = (newkres-kres)/nsmps;
	  float value = unit->m_value;
	  float newvalue = 1.0f+(dist*(1.5f+2.0f*newkres*(1.0f-newkfcn)));
	  float valueinc = (newvalue-value)/nsmps;
	  unit->kp = newkp;
	  unit->m_value = newvalue;
	  unit->kres = newkres;
	  unit->last_fco = fco;
	  LOOP(nsmps,
	       float ax1   = lastin;
	       float ay11  = ay1;
	       float ay31  = ay2;
	       lastin  =  ZXP(in) - TANH(kres*aout);
	       ay1      = kp1h * (lastin + ax1) - kp*ay1;
	       ay2      = kp1h * (ay1 + ay11) - kp*ay2;
	       aout     = kp1h * (ay2 + ay31) - kp*aout;
	       ZXP(out) = TANH(aout*value);
	       kp1h += kp1hinc;
	       kp += kpinc;
	       kres += kresinc;
	       value += valueinc;
	       );
Ejemplo n.º 9
0
void HPZ2_ar::m_signal(int n, t_sample *const *in, 
			  t_sample *const *out)
{
    t_sample *nin = *in;
    t_sample *nout = *out;

    float x0;
    float x1 = m_x1;
    float x2 = m_x2;

    for (int i = 0; i!=mFilterLoops ;++i)
    {
	x0 = ZXP(nin);
	ZXP(nout) = (x0 - 2.f * x1 + x2) * 0.25f;
	x2 = ZXP(nin);
	ZXP(nout) = (x2 - 2.f * x0 + x1) * 0.25f;
	x1 = ZXP(nin);
	ZXP(nout) = (x1 - 2.f * x2 + x0) * 0.25f;
    }
    
    for (int i = 0; i!= mFilterRemain;++i)
    {
	x0 = ZXP(nin); 
	ZXP(nout) = (x0 - 2.f * x1 + x2) * 0.25f;
	x2 = x1;
	x1 = x0;
    }
    m_x1 = x1;
    m_x2 = x2;
}
Ejemplo n.º 10
0
void LFDNoise1_ar::m_signal(int n, t_sample *const *in, 
			    t_sample *const *out)
{
    t_sample *nout = *out;

    float prevLevel = m_prevlevel;
    float nextLevel = m_nextlevel;
    float phase = m_phase;
    
    RGET;

    if (m_ar)
    {
	t_sample *nin = *in;
	float smpdur = m_smpdur;
	for (int i = 0; i!= n; ++i)
	{
	    phase -= ZXP(nin) * smpdur;
	    if (phase <= 0) 
	    {
		phase = sc_wrap(phase, 0.f, 1.f);
		prevLevel = nextLevel;
		nextLevel = frand2(s1,s2,s3);
	    }
	    ZXP(nout) = nextLevel + ( phase * (prevLevel - nextLevel) );
	}
    }
    else 
    {
	float dphase = m_smpdur * m_freq;
	for (int i = 0; i!= n; ++i)
	{
	    phase -= dphase;
	    if (phase <= 0) 
	    {
		phase = sc_wrap(phase, 0.f, 1.f);
		prevLevel = nextLevel;
		nextLevel = frand2(s1,s2,s3);
	    }
	    ZXP(nout) = nextLevel + ( phase * (prevLevel - nextLevel) );
	}
    }

    m_prevlevel = prevLevel;
    m_nextlevel = nextLevel;
    m_phase = phase;
    
    RPUT;
}
Ejemplo n.º 11
0
void PeakEQ4_next(PeakEQ4* unit, int inNumSamples)
{
  float *out = ZOUT(0);
  float *input = ZIN(0);
  float freq = ZIN0(1);
  float width = ZIN0(2);
  float gain = ZIN0(3);
  double *bc = unit->m_b;
  double *ac = unit->m_a;
  double *buf = unit->m_mem;


  if ((unit->freq!=freq)||(unit->gain!=gain)||(unit->width!=width)) {
	  double w0 = freq * 2*M_PI / SAMPLERATE;
	  double Dw = w0 * width;
	  calc_coeffs4(bc,ac,w0, Dw, gain);
  }

  LOOP(inNumSamples,
       double in = (double) ZXP(input);
       double iir;
       double iir2;
       double fir;
       iir= in-
         ac[0]*buf[3]-
         ac[1]*buf[2]-
         ac[2]*buf[1]-
         ac[3]*buf[0];
       fir= bc[0]*iir+
         bc[1]*buf[3]+
         bc[2]*buf[2]+
         bc[3]*buf[1]+
         bc[4]*buf[0];
       iir2= fir-
         ac[4]*buf[7]-
         ac[5]*buf[6]-
         ac[6]*buf[5]-
         ac[7]*buf[4];
       fir= bc[5]*iir2+
         bc[6]*buf[7]+
         bc[7]*buf[6]+
         bc[8]*buf[5]+
         bc[9]*buf[4];
       memmove(buf, buf+1, 7*sizeof(double));
       buf[3]= iir;
       buf[7]= iir2;
       ZXP(out) = (float)fir;
       )
}
Ejemplo n.º 12
0
void SendTrigN_next(SendTrigN *unit, int inNumSamples)
{
    const char* cmdName = "/tr";

    float *trig = ZIN(0);
    float prevtrig = unit->m_prevtrig;

    if (unit->m_values == 0)
        return;
    
    LOOP(inNumSamples, 
        float curtrig = ZXP(trig);
        if (curtrig > 0.f && prevtrig <= 0.f) {
            for (size_t i=0; i < unit->numValues(); ++i) {
                unit->m_values[i] = ZIN0(unit->valueOffset()+i);
            }
            SendNodeReply(
                &unit->mParent->mNode,
                (int)ZIN0(1),
                cmdName,
                unit->numValues(),
                unit->m_values);
        }
        prevtrig = curtrig;
    );
void Spring_next(Spring *unit, int inNumSamples)
{
	float pos = unit->m_pos;
	float vel = unit->m_vel;
	float *out = ZOUT(0); 		// out force
	float *in = ZIN(0); 		// in force
	float spring = ZIN0(1);		// spring constant
	float damping = 1.f - ZIN0(2);// damping
	float c = SAMPLEDUR;
	float rc = SAMPLERATE;
	spring = spring * c;
	LOOP1(inNumSamples,
		float force = ZXP(in) * c - pos * spring;
		vel = (force + vel) * damping;
		pos += vel;
		ZXP(out) = force * rc;
	);
Ejemplo n.º 14
0
void InsideOut_next(InsideOut *unit, int inNumSamples)
{
	float *in = ZIN(0);
	float *out = ZOUT(0);

	float val;
	for (int i=0; i < inNumSamples; ++i)
	{
		val = ZXP(in);
		if(val>0.f)
			ZXP(out) = 1.0f - val;
		else if(val<0.f)
			ZXP(out) = - 1.0f - val;
		else
			ZXP(out) = 0.f;
	}
}
void LFDNoise0_next(LFDNoise0 *unit, int inNumSamples)
{
	float *out = ZOUT(0);
	float *freq = ZIN(0);
	float level = unit->mLevel;
	float phase = unit->mPhase;
	float smpdur = SAMPLEDUR;
	RGET

	LOOP1(inNumSamples,
		phase -= ZXP(freq) * smpdur;
		if (phase < 0) {
			phase = sc_wrap(phase, 0.f, 1.f);
			level = frand2(s1,s2,s3);
		}
		ZXP(out) = level;
	)
Ejemplo n.º 16
0
void WaveLoss_next(WaveLoss *unit, int inNumSamples)
{
	float *in = ZIN(0);
	float *out = ZOUT(0);

	bool on = unit->m_on; // Whether the current wave segment is being output
	int pos = unit->m_pos; // Which "number" of wave segment we're on
	float prevval = unit->m_prevval; // Used for checking for positivegoing zero crossings

	int drop  = (int)ZIN0(1);
	int outof = (int)ZIN0(2);
	int mode  = (int)ZIN0(3);

	float curval;
	for (int i=0; i < inNumSamples; ++i)
	{
		curval = ZXP(in);
		// If positive-going zero-crossing, this is a new segment.
		if(prevval<0.f && curval>=0.f){

			if(++pos >= outof){
				pos = 0;
			}
			if(mode == 2){ // Random
				on = (frand(unit->mParent->mRGen->s1, unit->mParent->mRGen->s2, unit->mParent->mRGen->s3)
					>= ((float)drop / (float)outof));
			}else{ // Nonrandom
				on = (pos >= drop);
			}

		}

		//Print("prevval: %g, curval: %g, on: %i, drop: %i, outof: %i, mode: %i\n", prevval, curval, on, drop, outof, mode);

		// Now simply output... or don't...
		ZXP(out) = on ? curval : 0.f;
		prevval = curval;
	}

	// Store state
	unit->m_on = on;
	unit->m_pos = pos;
	unit->m_prevval = prevval;
}
void Demand_next_aa(Demand *unit, int inNumSamples)
{
	float *trig = ZIN(0);
	float *reset = ZIN(1);

	float** out = unit->m_out;
	float* prevout = unit->m_prevout;

	for (int i=0; i<unit->mNumOutputs; ++i) {
		out[i] = OUT(i);
	}

	float prevtrig = unit->m_prevtrig;
	float prevreset = unit->m_prevreset;

	//Print("Demand_next_aa %d  %g\n", inNumSamples, prevtrig);
	for (int i=0; i<inNumSamples; ++i) {
		float ztrig = ZXP(trig);
		float zreset = ZXP(reset);
		if (zreset > 0.f && prevreset <= 0.f) {
			for (int j=2; j<unit->mNumInputs; ++j) {
				RESETINPUT(j);
			}
		}
		if (ztrig > 0.f && prevtrig <= 0.f) {
			//Print("triggered\n");
			for (int j=2, k=0; j<unit->mNumInputs; ++j, ++k) {
				float x = DEMANDINPUT_A(j, i + 1);
				//printf("in  %d %g\n", k, x);
				if (sc_isnan(x)) x = prevout[k];
				else prevout[k] = x;
				out[k][i] = x;
			}
		} else {
			for (int j=2, k=0; j<unit->mNumInputs; ++j, ++k) {
				out[k][i] = prevout[k];
			}
		}
		prevtrig = ztrig;
		prevreset = zreset;
	}
}
void LFDNoise1_next(LFDNoise1 *unit, int inNumSamples)
{
	float *out = ZOUT(0);
	float *freq = ZIN(0);
	float prevLevel = unit->mPrevLevel;
	float nextLevel = unit->mNextLevel;
	float phase = unit->mPhase;
	float smpdur = SAMPLEDUR;

	RGET

	LOOP1(inNumSamples,
		phase -= ZXP(freq) * smpdur;
		if (phase < 0) {
			phase = sc_wrap(phase, 0.f, 1.f);
			prevLevel = nextLevel;
			nextLevel = frand2(s1,s2,s3);
		}
		ZXP(out) = nextLevel + ( phase * (prevLevel - nextLevel) );
	)
Ejemplo n.º 19
0
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);
}
Ejemplo n.º 20
0
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;
	  );
Ejemplo n.º 21
0
void RedLbyl_next_a(RedLbyl *unit, int inNumSamples) {
	float *out= ZOUT(0);
	float *in= ZIN(0);
	float thresh= ZIN0(1);
	float samples= ZIN0(2);
	float prevout= unit->m_prevout;
	unsigned long counter= unit->m_counter;
	
	LOOP(inNumSamples,
		 float zout= ZXP(in);
		 if(sc_abs(zout-prevout)>thresh) {
			counter++;
			if(counter<samples) {
				zout= prevout;
			} else {
				counter= 0;
			}
		 } else {
			counter= 0;
		 }
		 prevout= zout;
		 ZXP(out)= zout;
	);
void Duty_next_da(Duty *unit, int inNumSamples)
{

	float *reset = ZIN(duty_reset);

	float *out = OUT(0);
	float prevout = unit->m_prevout;
	float count = unit->m_count;
	float prevreset = unit->m_prevreset;
	float sr = (float) SAMPLERATE;

	for (int i=0; i<inNumSamples; ++i) {

		float zreset = ZXP(reset);
		if (zreset > 0.f && prevreset <= 0.f) {

			RESETINPUT(duty_level);
			RESETINPUT(duty_dur);
			count = 0.f;
		}
		if (count <= 0.f) {
			count = DEMANDINPUT_A(duty_dur, i + 1) * sr + count;
			if(sc_isnan(count)) {
				int doneAction = (int)ZIN0(duty_doneAction);
				DoneAction(doneAction, unit);
			}
			float x = DEMANDINPUT_A(duty_level, i + 1);
			//printf("in  %d\n", count);
			if(sc_isnan(x)) {
				x = prevout;
				int doneAction = (int)ZIN0(duty_doneAction);
				DoneAction(doneAction, unit);
			} else {
				prevout = x;
			}
			out[i] = x;

		} else {
			count--;
			out[i] = prevout;
		}

		prevreset = zreset;
	}

	unit->m_count = count;
	unit->m_prevreset = prevreset;
	unit->m_prevout = prevout;
}
Ejemplo n.º 23
0
void CoupledResonator_next(CoupledResonator *unit, int inNumSamples)
{
    // get the pointer to the output buffer
    float *out = ZOUT(0);
    
    float displacement1 = unit->displacement1;
    float displacement2 = unit->displacement2;
    float velocity1 = unit->velocity1;
    float velocity2 = unit->velocity2;
    float acceleration1 = unit->acceleration1;
    float acceleration2 = unit->acceleration2;
    float forceSpring1 = unit->forceSpring1;
    float forceSpring2 = unit->forceSpring2;
    float forceSpring3 = unit->forceSpring3;
    float mass1 = ZIN0(9);
    float mass2 = ZIN0(10);
    float b1 = ZIN0(11);
    float b2 = ZIN0(12);
    float b3 = ZIN0(13);
    short outputChoice = ZIN0(14);
    float outval;

    LOOP(inNumSamples,
          acceleration1 = (forceSpring1 - forceSpring2) / mass1;
          acceleration2 = (forceSpring2 + forceSpring3) / mass2;
          velocity1 = velocity1 + acceleration1 / SAMPLERATE;
          velocity2 = velocity2 + acceleration2 / SAMPLERATE;
          displacement1 = displacement1 + velocity1 / SAMPLERATE;
          displacement2 = displacement2 + velocity2 / SAMPLERATE;
          forceSpring1 = - b1 * displacement1;
          forceSpring2 = - b2 * (displacement2 - displacement1);
          forceSpring3 = - b3 * displacement2;
          switch (outputChoice) {
             case 0: outval = displacement1;
                 break;
             case 1: outval = displacement2;
                 break;
             case 2: outval = velocity1;
                 break;
             case 3: outval = velocity2;
                 break;
             case 4: outval = acceleration1;
                 break;
             case 5: outval = acceleration2;
                 break;
             default: outval = displacement1;
         };
          ZXP(out) = outval;
         )
void LFDNoise3_next(LFDNoise3 *unit, int inNumSamples)
{
	float *out = ZOUT(0);
	float *freq = ZIN(0);
	float a = unit->mLevelA;
	float b = unit->mLevelB;
	float c = unit->mLevelC;
	float d = unit->mLevelD;
	float phase = unit->mPhase;
	float smpdur = SAMPLEDUR;

	RGET

	LOOP1(inNumSamples,
		phase -= ZXP(freq) * smpdur;
		if (phase < 0) {
			phase = sc_wrap(phase, 0.f, 1.f);
			a = b;
			b = c;
			c = d;
			d = frand2(s1,s2,s3) * 0.8f;	// limits max interpol. overshoot to 1.
		}
		ZXP(out) = cubicinterp(1.f - phase, a, b, c, d);
	)
Ejemplo n.º 25
0
void DelayN_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out)
{
    t_sample *nin = *in;
    t_sample *nout = *out;

    float *dlybuf = m_dlybuf;
    long iwrphase = m_iwrphase;
    float dsamp = m_dsamp;
    long mask = m_mask;

    if (changed)
    {
	float next_dsamp = CalcDelay(m_delaytime);
	float dsamp_slope = CALCSLOPE(next_dsamp, dsamp);
		
	for (int i = 0; i!= n;++i)
	{
	    dlybuf[iwrphase & mask] = ZXP(nin);
	    dsamp += dsamp_slope;
	    ++iwrphase;
	    long irdphase = iwrphase - (long)dsamp;
	    ZXP(nout) = dlybuf[irdphase & mask];
	}
	m_dsamp = dsamp;
	changed = false;
    }
    else
    {
	long irdphase = iwrphase - (long)dsamp;
	float* dlybuf1 = dlybuf - ZOFF;
	float* dlyrd   = dlybuf1 + (irdphase & mask);
	float* dlywr   = dlybuf1 + (iwrphase & mask);
	float* dlyN    = dlybuf1 + m_idelaylen;
	long remain = n;
	while (remain) 
	{
	    long rdspace = dlyN - dlyrd;
	    long wrspace = dlyN - dlywr;
	    long nsmps = sc_min(rdspace, wrspace);
	    nsmps = sc_min(remain, nsmps);
	    remain -= nsmps;
	    for (int i = 0; i!= nsmps;++i)
	    {
		ZXP(dlywr) = ZXP(nin);
		ZXP(nout) = ZXP(dlyrd);
	    }
	    if (dlyrd == dlyN) dlyrd = dlybuf1;
	    if (dlywr == dlyN) dlywr = dlybuf1;
	}
	iwrphase += n;
    }
    m_iwrphase = iwrphase;
}
void BLOscWithComplexSinusoid_next(BLOscWithComplexSinusoid *unit, int inNumSamples)
{
    
    float *out = ZOUT(0);
    float freqin = ZIN0(0);
    int32 loHarmonics = ZIN0(1);
    int32 numHarmonics = ZIN0(2);
    float slope = ZIN0(3);
    float evenOddRatio = ZIN0(4);

    int32 hiHarmonics = loHarmonics + numHarmonics - 1; // The highest harmonic index
    int32 hiHarmonicsPlusOne = hiHarmonics + 1;
    int32 loEvenHarmonics = loHarmonics%2 == 0? loHarmonics : loHarmonics + 1; // The lowest even harmonic index
    int32 hiEvenHarmonics = hiHarmonics%2 == 0? hiHarmonics : hiHarmonics - 1; // The highest even harmonic index
    int32 hiEvenHarmonicsPlusTwo = hiEvenHarmonics + 2;
    int32 numEvenHarmonics = (hiEvenHarmonics - loEvenHarmonics) / 2 + 1; //The total number of even harmonics
    float evenOddFactor = 1 - evenOddRatio;
    std::complex<double> evenOddFactorC(evenOddFactor, 0);
    float ampFactor = 0.99<slope&&slope<1.01? numHarmonics - evenOddFactor * numEvenHarmonics:((pow(slope,loHarmonics) - pow(slope,hiHarmonicsPlusOne)) / (1 - slope)) - (evenOddFactor * (pow(slope, loEvenHarmonics) - pow(slope, hiEvenHarmonicsPlusTwo)) / (1 - pow(slope, 2)));  //ampFactor will be used to normalize the output amplitude. To avoid the denominator of this calculation to be 0 when slope = 1, the different formula is used when slope falls between 0.99 and 1.01.
    
    float phaseinc = ZIN0(0) * unit->partialTheta;
    float currentphase = unit->currentphase;
    std::complex<double> baseOsc;
    std::complex<double> r;
    std::complex<double> signalC; // signal as complex number
    float signalR; // signal as real number
    std::complex<double> oneC(1,0);
    std::complex<double> slopeC(slope, 0);
    float z;
    
    LOOP(inNumSamples,
         baseOsc = std::exp(std::complex<double>(0, currentphase));

         r = slopeC * baseOsc;
         signalC = (std::pow(r, loHarmonics) - std::pow(r, hiHarmonicsPlusOne))/(oneC - r) - evenOddFactorC * (std::pow(r, loEvenHarmonics) - std::pow(r, hiEvenHarmonicsPlusTwo))/(oneC - std::pow(r, 2));
         signalR = signalC.real();
         z = signalR/ampFactor;
         
         currentphase += phaseinc;
         while (currentphase >= twopi_f)
         currentphase -= twopi_f;
         
         ZXP(out) = z;
         )
void Demand_next_ak(Demand *unit, int inNumSamples)
{
	float *trig = ZIN(0);
	float zreset = IN0(1);

	float** out = unit->m_out;
	float *prevout = unit->m_prevout;

	for (int i=0; i<unit->mNumOutputs; ++i) {
		out[i] = OUT(i);
	}

	float prevtrig = unit->m_prevtrig;
	float prevreset = unit->m_prevreset;

	for (int i=0; i<inNumSamples; ++i) {
		float ztrig = ZXP(trig);
		if (zreset > 0.f && prevreset <= 0.f) {
			for (int j=2; j<unit->mNumInputs; ++j) {
				RESETINPUT(j);
			}
		}

		if (ztrig > 0.f && prevtrig <= 0.f) {
			for (int j=2, k=0; j<unit->mNumInputs; ++j, ++k) {
				float x = DEMANDINPUT_A(j, i + 1);
				if (sc_isnan(x)) x = prevout[k];
				else prevout[k] = x;
				out[k][i] = x;
			}

		} else {
			for (int j=2, k=0; j<unit->mNumInputs; ++j, ++k) {
				out[k][i] = prevout[k];
			}

		}
		prevtrig = ztrig;
		prevreset = zreset;
	}

	unit->m_prevtrig = prevtrig;
	unit->m_prevreset = prevreset;
}
void LFDClipNoise_next_k(LFDClipNoise *unit, int inNumSamples)
{
	float *out = ZOUT(0);
	float freq = ZIN0(0);
	float level = unit->mLevel;
	float phase = unit->mPhase;
	float smpdur = SAMPLEDUR;
	float dphase = smpdur * freq;

	RGET

	LOOP1(inNumSamples,
		phase -= dphase;
		if (phase < 0) {
			phase = sc_wrap(phase, 0.f, 1.f);
			level = fcoin(s1,s2,s3);
		}
		ZXP(out) = level;
	)
Ejemplo n.º 29
0
void GlitchRHPF_next(GlitchRHPF* unit, int inNumSamples)
{
	//printf("GlitchRHPFs_next\n");

	float *out = ZOUT(0);
	float *in = ZIN(0);
	float freq = ZIN0(1);
	float reson = ZIN0(2);

	float y0;
	float y1 = unit->m_y1;
	float y2 = unit->m_y2;
	float a0 = unit->m_a0;
	float b1 = unit->m_b1;
	float b2 = unit->m_b2;

	if (freq != unit->m_freq || reson != unit->m_reson) {

		float qres = sc_max(0.001f, reson);
		float pfreq = freq * unit->mRate->mRadiansPerSample;

		float D = tan(pfreq * qres * 0.5f);
		float C = ((1.f-D)/(1.f+D));
		float cosf = cos(pfreq);

		float next_b1 = (1.f + C) * cosf;
		float next_b2 = -C;
		float next_a0 = (1.f + C + next_b1) * .25f;

		//post("%g %g %g   %g %g   %g %g %g   %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);

		float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
		float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
		float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
		LOOP(unit->mRate->mFilterLoops,
			 y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
			 ZXP(out) = y0 - 2.f * y1 + y2;

			 y2 = a0 * ZXP(in) + b1 * y0 + b2 * y1;
			 ZXP(out) = y2 - 2.f * y0 + y1;

			 y1 = a0 * ZXP(in) + b1 * y2 + b2 * y0;
			 ZXP(out) = y1 - 2.f * y2 + y0;

			 a0 += a0_slope;
			 b1 += b1_slope;
			 b2 += b2_slope;
			 );
Ejemplo n.º 30
0
void RedPhasor_next_kk(RedPhasor *unit, int inNumSamples) {
	float *out= ZOUT(0);
	float in= ZIN0(0);
	float rate= sc_max(0, ZIN0(1));
	double start= ZIN0(2);
	double end= ZIN0(3);
	float loop= ZIN0(4);
	float previn= unit->m_previn;
	double level= unit->mLevel;
	
	if((previn<=0.f)&&(in>0.f)) {
		level= start;
	}
	
	if(loop<=0.f) {										//kk off
		if(end<start) {
			LOOP(inNumSamples,
				ZXP(out)= level;
				level-= rate;
				level= sc_clip(level, end, start);
			);
		} else {