12345678910111213141516171819202122232425262728293031323334353637383940(* Claude Code
*
* Copyright (C) 2026 Yoann Padioleau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* (LGPL) as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*)(* See Drift.mli *)letstep_samples=64(* the walk's parameters (sigma, tau); where it is; the random state; the
* samples since the last step *)typet={sigma:float;tau:float;mutablex:float;mutablerandom:int;mutablesince:int}(* a random number of variance 1: uniform on -1..1 has 1/3 *)letdraw(t:t):float=t.random<-Noise.lcgt.random;sqrt3.*.Noise.uniformt.randomletcreate?(cents=3.)?(seconds=2.)~(seed:int)():t=lett={sigma=cents*.sqrt(2./.seconds);tau=seconds;x=0.;random=seed;since=0}in(* from its settled spread, not from 0: two oscillators out of tune
* from the start *)t.x<-cents*.drawt;tletadvance(t:t)(n:int):unit=leth=float_of_intstep_samples/.float_of_intSignal.rateint.since<-t.since+n;whilet.since>=step_samplesdot.x<-(t.x*.(1.-.(h/.t.tau)))+.(t.sigma*.sqrth*.drawt);t.since<-t.since-step_samplesdoneletcents(t:t):float=t.xletfactor(t:t):float=Float.pow2.(t.x/.1200.)