Last active
December 6, 2020 17:44
-
-
Save jpcima/572b3f39a66c98192f47c6771c7bb9b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import("stdfaust.lib"); | |
//--- for tabulating intervals ---// | |
// calculate a tabulated function of normalized range [0;1] with interpolation | |
lookup(fn, start, end, size) = lut(0, fn, start, end, size).lookup_itp; | |
// calculate a tabulated function of normalized range [0;1] without interpolation | |
fastlookup(fn, start, end, size) = lut(0, fn, start, end, size).lookup_direct; | |
// calculate a tabulated function of range [start;end] with interpolation | |
eval(fn, start, end, size) = lut(0, fn, start, end, size).eval_itp; | |
// calculate a tabulated function of range [start;end] without interpolation | |
fasteval(fn, start, end, size) = lut(0, fn, start, end, size).eval_direct; | |
//--- for tabulating periods ---// | |
// calculate a periodic function of nominal range [0;1] with interpolation | |
lookup_circular(fn, start, end, size) = lut(1, fn, start, end, size).lookup_itp; | |
// calculate a periodic function of nominal range [0;1] without interpolation | |
fastlookup_circular(fn, start, end, size) = lut(1, fn, start, end, size).lookup_direct; | |
// calculate a periodic function of nominal range [start;end] with interpolation | |
eval_circular(fn, start, end, size) = lut(1, fn, start, end, size).eval_itp; | |
// calculate a periodic function of nominal range [start;end] without interpolation | |
fasteval_circular(fn, start, end, size) = lut(1, fn, start, end, size).eval_direct; | |
//--- implementation detail ---// | |
lut(circular, fn, start, end, size) = environment | |
{ | |
lookup_direct(x) = read(i0) with { | |
tabpos = x : *(select2(circular, size-1, size)); | |
i0 = int(tabpos) : keepinrange; | |
}; | |
lookup_itp(x) = (read(i0), read(i1)) : itp(mu) with { | |
tabpos = x : *(select2(circular, size-1, size)); | |
i0 = int(tabpos) : keepinrange; | |
i1 = (int(tabpos)+1) : keepinrange; | |
mu = tabpos-int(tabpos); | |
itp(mu, y1, y2) = y1+mu*(y2-y1); | |
}; | |
eval_direct = normalize : lookup_direct; | |
eval_itp = normalize : lookup_itp; | |
normalize = -(start) : *(1.0/(end-start)); | |
denormalize = *(end-start) : +(start); | |
read = rdtable(size, sampleat(normpos)) with { | |
normpos = float(ba.time)/select2(circular, float(size-1), float(size)); | |
sampleat = denormalize : fn; | |
}; | |
keepinrange = _ <: select2(circular, lin, circ) with { | |
lin = max(0) : min(size-1); | |
circ(x) = select2(t<0, t, t+size) with { t = x%size; }; | |
}; | |
}; | |
//--- example ---// | |
//process = eval(atan, -1.0, +1.0, 128); | |
//process = os.lf_sawpos(440.0) : lookup_circular(sin, 0.0, 2.0*ma.PI, 64); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment