Skip to content

Instantly share code, notes, and snippets.

@ryanlaws
Created July 11, 2021 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlaws/a628525877c8b7c585ad439d7ae9e73c to your computer and use it in GitHub Desktop.
Save ryanlaws/a628525877c8b7c585ad439d7ae9e73c to your computer and use it in GitHub Desktop.
Linear Congruential Generator for Monome Crow 3
-- LCG based on https://github.com/monome/dsp-kit/blob/main/noise/lcg.c by @catfact
-- due to differences in data types, the behavior is not the same.
-- int32_t values were truncated to avoid Lua converting them to inf or -inf.
output[1].action = loop {
to(
dyn{x=1}
:mul(dyn{a=-559})
:step(dyn{c=21032})
:wrap(-32768, 32767)
/ 32768
* math.abs(dyn{amp=10}
:step(dyn{ampstep=0.01})
:wrap(-10, 10)),
0
),
to(
dyn{x=1}/ 32768 * math.abs(dyn{amp=10}),
dyn{time= 2.986e-5 }
)
}
-- some values to try out
output[1].dyn.a = 28772.0
output[1].dyn.c = 5221.0
output[1].dyn.time = 0.00233
output[1].dyn.ampstep = 0.0001
output[1].dyn.a = 28772.0
output[1].dyn.c = 8231.0
output[1].dyn.time = 0.000031
output[1].dyn.a = 29272.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment