hi world. i've been dabbling for a while with chuck now, and have a little doubt i've seen this in various of the provided examples (this one is from the band-o-matic.ck // pentatonic 2 * std.rand2( 0, 4 ) => int freq; if( freq == 6 ) 7 => freq; if( freq == 8 ) 9 => freq; std.mtof( (float)( 21 + std.rand2(0,5) * 12 + freq ) ) => band.freq; if ( std.randf() > 0.7 ) std.rand2(0,3) => band.preset; } and i see that it generates a pentatonic scale (in fact i've used it as provided and works). But i don't really understand how it works. i can get the first three lines, but i don't now what std.mtof is for, so i can't guess what it is for. any kind helping hand? thanx a lot. the deeper i know chuck, the more i love it!! cheers!
Greetings!
std.mtof( (float)( 21 + std.rand2(0,5) * 12 + freq ) ) => band.freq;
std.mtof converts numbers in MIDI note space to frequencies in Hz, fashioned after the Max/MSP and Pd object 'mtof'. std.mtof takes a float and returns a float. For example, here is a table of MIDI note numbers: http://www.harmony-central.com/MIDI/Doc/table2.html std.mtof converts numbers in this domain to frequencies, except the input to mtof (1) is not limited to integers and (2) can be much greater than 127 (though this usually isn't useful since it maps to very high frequencies). You can even feed mtof negative MIDI note numbers for really low frequencies.
// pentatonic 2 * std.rand2( 0, 4 ) => int freq; if( freq == 6 ) 7 => freq; if( freq == 8 ) 9 => freq;
This code generates a relative offset (in half steps) using the pentatonic scale. (This would look much less brain-damaged with arrays in v2.)
(float)( 21 + std.rand2(0,5) * 12 + freq )
This places the offset in some key (in this case we use 21 (A0) as the lowest potential note number), offset by some number of octaves (+ std.rand2(0,5) * 12). std.mtof then converts the result to frequency (Hz), since that is what most 'freq' parameters expect. Hope this helps. Best, Ge!
yes, it helps a lot. i somewhat suspected it, but your explanation has been great. thanks a lot, Ge. ChucK roCKs! Best regards.
participants (2)
-
Ge Wang
-
jesus gollonet