[chuck] std.mtof?

Ge Wang gewang at CS.Princeton.EDU
Fri Jul 15 10:00:49 EDT 2005


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!



More information about the chuck mailing list