| 1 |
// gen17 chebyshev lookup table |
| 2 |
// |
| 3 |
// ported to ChucK from rtcmix by dan trueman |
| 4 |
// see luke's page: http://www.music.columbia.edu/cmix/makegens.html#06 |
| 5 |
// |
| 6 |
// like gen10, this is a series of weightings for successive partials |
| 7 |
// also http://www.music.columbia.edu/cmc/Rtcmix/docs/scorefile/gen17.html |
| 8 |
// and http://www.music.columbia.edu/cmc/Rtcmix/docs/scorefile/maketable.html (scroll down) |
| 9 |
// for nice documentation of this gen |
| 10 |
// see also: http://math.fullerton.edu/mathews/n2003/ChebyshevPolyMod.html |
| 11 |
// for info about chebyshev polynomials in general |
| 12 |
// |
| 13 |
// the main feature to be aware of is that these functions are primarily |
| 14 |
// useful for waveshaping, so in this case we drive it with a |
| 15 |
// SinOsc instead of a Phasor. see, for example: |
| 16 |
// http://crca.ucsd.edu/~msp/techniques/v0.08/book-html/node74.html |
| 17 |
// http://en.wikipedia.org/wiki/Distortion_synthesis |
| 18 |
|
| 19 |
// the patch |
| 20 |
SinOsc drive => Gen17 g17 => dac; |
| 21 |
|
| 22 |
// load up the coeffs |
| 23 |
[1., 0.5, 0.25, 0.125, 0.06, 0.03, 0.015] => g17.coefs; |
| 24 |
// some examples to try |
| 25 |
// [1., 0.5, 0.3, 0.2] => g17.coefs; |
| 26 |
// [1., 0.5, 0.25, 0.125, 0.06, 0.03, 0.015] => g17.coefs; |
| 27 |
// [1., 0.] @=> g17.coefs; // a simple one |
| 28 |
|
| 29 |
// make it quiet |
| 30 |
0.1 => g17.gain; |
| 31 |
|
| 32 |
// set frequency for reading through table |
| 33 |
drive.freq( 440 ); |
| 34 |
// sounds better not going to extremes |
| 35 |
drive.gain( 0.99 ); |
| 36 |
|
| 37 |
// create an envelope to scan through the table values |
| 38 |
// so we can look at them as well as hear them |
| 39 |
Envelope e => blackhole; |
| 40 |
e.duration( 10000::ms ); |
| 41 |
0. => e.value; |
| 42 |
e.keyOn(); |
| 43 |
|
| 44 |
// loop |
| 45 |
while (true) |
| 46 |
{ |
| 47 |
// print |
| 48 |
<<< e.value(), g17.lookup(e.value()) >>>; |
| 49 |
|
| 50 |
// stop when envelope reaches 1 |
| 51 |
if( e.value() == 1. ) break; |
| 52 |
|
| 53 |
// advance time |
| 54 |
10::ms => now; |
| 55 |
} |