« Return to Thread: Writing Efficient Code

Re: Writing Efficient Code

by James Harkins-2 :: Rate this Message:

Reply to Author | View in Thread

Be aware, when creating parallel UGens with loops, of units that are
doing the same thing. Those could be created outside the loop and
shared across all the downstream units.

// inefficient: 5 SinOscs that will produce the exact same signal

SynthDef(\chainedDelays, { |delayFreq = 0.15, delayCtr = 0.05,
delayMod = 0.03, out = 0|
        var sig = In.ar(out, 2),
                new = sig;
        5.do {
                new = DelayL.ar(new, 0.1, SinOsc.kr(delayFreq, 0, delayMod, delayCtr));
        };
        Out.ar(out, sig);
});

// better:

SynthDef(\chainedDelays, { |delayFreq = 0.15, delayCtr = 0.05,
delayMod = 0.03, out = 0|
        var sig = In.ar(out, 2),
                delayTime = SinOsc.kr(delayFreq, 0, delayMod, delayCtr),
                new = sig;
        5.do {
                new = DelayL.ar(new, 0.1, delayTime);
        };
        Out.ar(out, sig);
});

This kind of inefficiency is really easy to overlook.
James

PS Am I the only person who trims old replies from the e-mail? Some
messages get really huge just because of quoted material that doesn't
add anything to the discussion. (Speaking of efficiency...!)


--
James Harkins /// dewdrop world
jamshark70@...
http://www.dewdrop-world.net

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal."  -- Whitman

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

 « Return to Thread: Writing Efficient Code