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

[sc-dev] Latch init bug



I'm having a strange problem with Phasor initializing incorrectly when its 'start' input is a Latch. Illustrating with a couple of units from a more complex SynthDef -- first, this tells how much time elapsed between the synth start time and the time the trace was taken.

  unit 17 Line
    in  0 500 500 0
    out 0.0522449

0.0522449 sec * 44100 samp/sec * (1/64) control/samp ≈ 36 control blocks

Then...

  unit 19 Phasor
    in  1 0.015625 128.002 5.17337e+06 128.002
    out 5.17325e+06

But, 128.002 + (0.015625 * 36) = 128.5645 -- that's a bit more than rounding error, no?

I can reproduce it more simply this way. The original SynthDef pulls the starting buffer position (normalized to 0-1 for GrainBuf) from a control bus and latches it because the control bus value will change continuously.

n = 5173374;
z = Bus.control(s, 1);
z.set(128 / n);

{ var debugTrig = 1 - Trig1.kr(Impulse.kr(0), 0.0522449),
rate = ControlRate.ir / SampleRate.ir,
inPos = Latch.kr(In.kr(z, 1), 1) * n;
Phasor.kr(1, rate, inPos, n, inPos)
.poll(debugTrig);
FreeSelf.kr(debugTrig);
Silent.ar(1)
}.play;

UGen(Phasor): 5.17325e+06

Removing Latch:

{ var debugTrig = 1 - Trig1.kr(Impulse.kr(0), 0.0522449),
rate = ControlRate.ir / SampleRate.ir,
inPos = In.kr(z, 1) * n;
Phasor.kr(1, rate, inPos, n, inPos)
.poll(debugTrig);
FreeSelf.kr(debugTrig);
Silent.ar(1)
}.play;

UGen(Phasor): 128.562 - that's the right one!

I think the issue is that Latch should initialize its output to the input value, instead of as is currently assumed. After changing the last line of Latch_Ctor to this:

ZOUT0(0) = ZIN0(0); // 0.f;

... the test case above (with Latch) returns the expected 128.562 value.

Commit? Please say yes :-)  I've had other issues with Latch where the expected init value was not passed further down the chain.

hjh


: H. James Harkins
.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:

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