I’m trying to simulate the sound of an LFSR a la Gameboy using a buffer which is filled with noise when triggered. It is mostly working, but I noticed when swapping the noise for a sine, the buffer starts crackling after about 20 seconds. I watched JACK and it didn’t show any xruns.
Here’s the SynthDef
and the pattern I’m testing with.
(SynthDef(\fauxLfsr, {|
outbus=0, freq=55,
decay=1, ampCurve=(-4),
t_sync=0, quality=1,
t_rewrite=0,
t_trig=1,
pan=0|
var bufferSeconds = 1;
var lastIndex = s.sampleRate;
var buf = Buffer.alloc(s, lastIndex * bufferSeconds, bufferSeconds);
// Reader - rate based on quality, not (note) freq
var readRate = quality.max(0.00001).min(1);
var startIndex = 0;
var loopIndex = (lastIndex / freq * readRate).min(lastIndex);
var readIndex = Phasor.ar(t_sync, readRate, startIndex, loopIndex);
// Writer - one shot
// Empty until t_rewrite triggered
var writeIndex = EnvGen.ar(Env.new([0, lastIndex], [1]), t_rewrite);
var ampEnv = EnvGen.ar(Env.perc(0, decay, 1, ampCurve), t_trig, /* doneAction: Done.freeSelf */);
// Writer - one shot
// .sign to make "1 bit" signal
// BufWr.ar([WhiteNoise.ar.sign], buf.bufnum, writeIndex);
BufWr.ar([SinOsc.ar], buf.bufnum, writeIndex);
// Reader
Out.ar(outbus, Pan2.ar(
BufRd.ar(1, buf.bufnum, readIndex, 0, 4),
pan
) * ampEnv);
}).add;);
(
var makeLine = {|pan|
Pmono(\fauxLfsr,
// \rewrite, Pseq([1]) ++ Pwrand([0, 1], [0.6, 0.4], inf),
\rewrite, Pseq([1]) ++ Pn(0), // necessary
\sync, 1,
\degree, Pdefn(\degree),
\scale, [0, 1, 3, 4, 6, 7, 9, 10],
\ctranspose, Pdefn(\tran),
\dur, Prand((1..4)/10, inf) + Pwhite(-0.0001, 0.0001),
\decay, Pdefn(\decay),
\quality, Pdefn(\quality),
\ampCurve, Pdefn(\ampCurve),
\pan, pan,
);
};
Pdefn(\degree, Pbrown(0, 12, 3));
Pdefn(\quality, 1/8);
Pdefn(\tran, -24);
Pdefn(\decay, 0.2);
Pdefn(\ampCurve, -4);
Ppar([-0.3, 0.3].collect(makeLine)).trace.play;
);
I initially used a non-interpolated BufRd
, but the problem still reproduces with both linear and cubic interpolation.
This is a separate issue obviously, but I also noticed the BufWr
doesn’t seem to re-read when I send it a \rewrite
trigger (see commented-out parameter in the Pmono
)