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

Re: [sc-dev] UGen creation q

On Wednesday, January 8, 2003, at 12:22 PM, Casey Basichis wrote:

So would this work for the audiorate one (havent done
the kr one)?

Note that the next_a and next_k do NOT refer to whether LFPulse is .ar or .kr, but whether the frequency INPUT is audio rate or control rate. If your frequency input is control rate or scalar, you must implement the version of the code that will accept a control rate frequency input. Otherwise if you try to read a control rate input as if it were audio rate, you will crash with a bad memory access error. An audio rate input can always be treated as if it were control rate, but a control rate input may never be treated as if it were audio rate. An audio rate frequency input for LFPulse is a unusual case, so the other version of the function is more important.

almost have it. You need to store the frequency.
You don't need prevtrig. You trigger when the cycle completes.

struct LFPulseLock : public Unit
        float mPhase, mFreqMul, mDuty;
		[delete prevtrig]
			float mPrevFreq;

void LFPulseLock_next_a(LFPulseLock *unit, int
void LFPulseLock_next_k(LFPulseLock *unit, int
void LFPulseLock_Ctor(LFPulseLock* unit);

void LFPulseLock_Ctor(LFPulseLock* unit)
        if (INRATE(0) == calc_FullRate) {
        } else {

        unit->mFreqMul = unit->mRate->mSampleDur;
        unit->mPhase = ZIN0(1);
        unit->mDuty = ZIN0(2);
		[delete prevtrig]
		unit->mPrevFreq = ZIN0(0) * unit->mFreqMul;

        LFPulse_next_k(unit, 1);


void LFPulseLock_next_a(LFPulseLock *unit, int
        float *out = ZOUT(0);
        float *freq = ZIN(0);
        float nextDuty = ZIN0(2);
        float duty = unit->mDuty;
		[delete prevtrig]

        float freqmul = unit->mFreqMul;
        float phase = unit->mPhase;
		float frequency = unit->mPrevFreq;

                float z;
                if (phase >= 1.f) {
                        phase -= 1.f;
                        duty = unit->mDuty = nextDuty;
                        // output at least one sample
from the opposite
                        z = duty < 0.5 ? 1.f : 0.f;
						frequency = ZXP(freq) * freqmul;
                } else {
                        z = phase < duty ? 1.f : 0.f;
						ZXP(freq); // skip

		[delete prevtrig]
                phase += frequency;
                ZXP(out) = z;

		[delete prevtrig]
        unit->mPrevFreq = frequency;
        unit->mPhase = phase;

void load(InterfaceTable *inTable)
        ft = inTable;


Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
sc-dev mailing list

--- james mccartney   james@xxxxxxxxxxxxxx   <http://www.audiosynth.com>
SuperCollider - a real time synthesis programming language for the PowerMac.