[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] Impulse UGen Fix: was Re: [sc-users] is this really phase offset?



void Impulse_next_aa(Impulse *unit, int inNumSamples)
{
	float *out = ZOUT(0);
	float *freq = ZIN(0);
	float *phaseOffset =  ZIN(1);
	
	float freqmul = unit->mFreqMul;
	double phase = unit->mPhase;
	double rate_acum = unit->mPhase;
	//	double phaseSlope = CALCSLOPE(phaseOffset, prev_phaseOffset);
	phase += unit->mPhaseOffset;
	
	LOOP(inNumSamples,
		float z;
	
		if (phase >= 1.f) {
			rate_acum -= 1.f;
			z = 1.f;
		} else if (phase < 0.f) {
		  rate_acum += 1.f;
		  z = 1.f;
                }
                else {
			z = 0.f;
		}
		rate_acum += (ZXP(freq) * freqmul);
                phase = rate_acum + ZXP(phaseOffset);
		ZXP(out) = z;
	);

	unit->mPhase = rate_acum;
	unit->mPhaseOffset = phase - rate_acum;
}

This is not correct. The phase modulation should not be accumulated into the phase. Phase modulation always comes after the phase accumulator. If phase modulation is audio rate, I don't see a reason to store mPhaseOffset. The phase offset is updated every sample, so storing it should be unecessary. All you need to store is phase.