| 1 |
// WarpTable: end-constrained mapping table |
| 2 |
// |
| 3 |
// created originally for the PLOrk Utilities by dan trueman |
| 4 |
// ported to ChucK by dan trueman, 2007. |
| 5 |
// |
| 6 |
// this table is mostly useful for conditioning control signals |
| 7 |
// it is end-constrained in that an input of 0 always yields 0 |
| 8 |
// and an output of 1 always yields 1 |
| 9 |
// |
| 10 |
// WarpTable.value(0) => 0 always |
| 11 |
// WarpTable.value(1) => 1 always |
| 12 |
// |
| 13 |
// expects input [0,1], generates output [0,1] |
| 14 |
// |
| 15 |
// what happens in between is what is interesting.... |
| 16 |
// |
| 17 |
// WarpTable is useful for mapping sensors and focusing |
| 18 |
// attention on: |
| 19 |
// --either extreme (asymmetrical warping) |
| 20 |
// --both extremes (symmetrical warping) |
| 21 |
// --central values (also symmetrical warping) |
| 22 |
// |
| 23 |
// the first coefficient sets the asymmetrical warping value |
| 24 |
// --asym = 1. => linear |
| 25 |
// --asym > 1. => exponential (focusing resolution on lower output values) |
| 26 |
// --asym < 1. => log (focusing resolution on higher output values) |
| 27 |
// |
| 28 |
// the second coefficient sets the symmetrical warping value |
| 29 |
// --sym = 1. => linear |
| 30 |
// --sym < 1. => focusing resolution around central (0.5) output value |
| 31 |
// __________/ |
| 32 |
// / |
| 33 |
// |
| 34 |
// --sym > 1. => focusing resolution on extremes (0 and 1) output values |
| 35 |
// _____ |
| 36 |
// _____/ |
| 37 |
// |
| 38 |
// and of course they can be combined to create related warped shapes |
| 39 |
|
| 40 |
// make one |
| 41 |
WarpTable w; |
| 42 |
|
| 43 |
// some examples: |
| 44 |
w.coefs( [4., 1.] ); // fairly strong focus on low values; 4 is useful for octave mappings |
| 45 |
// w.coefs([0.25, 1.]); // some focus on high values |
| 46 |
// w.coefs([1., 0.3]); // strong focus on central values |
| 47 |
// w.coefs([1., 3.]); // strong focus on hi/low values |
| 48 |
// w.coefs([10., 3.]); // some focus on high values, strong focus on low values; warped |
| 49 |
// w.coefs([0.1, 0.3]); |
| 50 |
// w.coefs([1., 1.]); // linear |
| 51 |
|
| 52 |
// create an envelope to scan through the table values |
| 53 |
Envelope e => blackhole; |
| 54 |
e.duration( 10000::ms ); |
| 55 |
0. => e.value; |
| 56 |
e.keyOn(); // ramp 0 to 1 in 10 seconds |
| 57 |
|
| 58 |
// on your mark |
| 59 |
while( true ) |
| 60 |
{ |
| 61 |
// print |
| 62 |
<<< e.value(), w.lookup(e.value()) >>>; |
| 63 |
|
| 64 |
// end |
| 65 |
if( e.value() == 1. ) break; |
| 66 |
|
| 67 |
// advance time |
| 68 |
10::ms => now; |
| 69 |
} |