LiSa l => dac;
//more time here means more resolution
//here more time actually prevents LiSa's interpolation from cleaning our intended dirt
second => l.duration;
//only calculating constants once
(l.duration()/ samp) $ int => int NUM_SAMPS;
2.0 / NUM_SAMPS => float STEP_SIZE;
//straight ramp from -1 to 1
for (int x; x< NUM_SAMPS; x++)
{
l.valueAt ( -1 + (x * STEP_SIZE) , x::samp);
}
//get signal's range between 0 and 1.
//slightly less, actually, to avoid edge-case glitches
SinOsc signal => Gain mix => l;
.49 => signal.gain;
Step offset => mix;
.5 => offset.next;
//use the LiSa to map the signal to new values
1 => l.sync;
//off we go. you should hear a pure sine here
1 => l.play;
5::second => now;
//now we start crushing.
6 => int bits;
//the "-1" is for above and minus zero
//again we use a constant to minimise per-value processing
Math.pow ( bits - 1, 2) => float QUANT;
//cheap&dirty quantisation
//we take the original value, multiply it by the number of steps in our chosen bit-depth
//then round this by casting to int
//finally dividing it again to get back in the original range
//and putting the value back
for (int x; x< NUM_SAMPS; x++)
{
l.valueAt ((l.valueAt(x::samp) * QUANT) $ int / QUANT , x::samp);
}
//and there we go again
5::second => now;