Re: [chuck-users] pitching samples
Brilliant, this is exactly what I'm looking for. Thank you Atte. Ollie
Ollie Glaskovik wrote:
I'd like to make a pitched sample playing function which, given a sample at a known pitch (say C-2) and a MIDI pitch value (0-127), plays the sample at that pitch. I suppose this could be done with sndbuf's .rate function and some math but I'm not sure where to start.
Given you have the midi pitch in the variable "note", the following will work. "transpose" is just a handy way of transposing the instrument, "root" is the known pitch of the sample. Note also that mtof will work with float, so you can have 12.01 => transpose, to transpose an octave + a cent.
12 => transpose; 60 => root;
sndbuf s => dac;
std.mtof(note + transpose)/ std.mtof(root) => s.rate;
-- peace, love & harmony Atte
participants (1)
-
Ollie Glass