| User-Defined Opcode Database |
|---|
converts a frequency to a MIDI.Cent note number
Download UDO Fileconverts a frequency to a MIDI.Cent note number
imidicent F2MC ifreq
ifreq - input frequency
imidicent - midi note number and cent deviation as fractional part
opcode F2MC, i, i ifq xin in1 = 12 * (log(ifq/220)/log(2)) + 57 ;'real' conversion in2 = floor(in1) ;next lower midi note icent = (in1 - in2) * 100 ;cent difference xout in2 + icent/100 endop
<CsoundSynthesizer> <CsInstruments> opcode F2M, i, i ;converts a frequency to the next possible MIDI note number ifq xin inotenum = round(12 * (log(ifq/220)/log(2)) + 57) xout inotenum endop opcode F2MC, i, i ;converts a frequency to a MIDI.Cent note number ifq xin in1 = 12 * (log(ifq/220)/log(2)) + 57 ;'real' conversion in2 = floor(in1) ;next lower midi note icent = (in1 - in2) * 100 ;cent difference xout in2 + icent/100 endop instr 1 inote1 F2M p4 inote2 F2MC p4 prints "Frequency = %f, F2M = %d, F2MC = %f\n", p4, inote1, inote2 endin </CsInstruments> <CsScore> i 1 0 0 440 i . . . 430 i . . . 420 i . . . 410 i . . . 400 i . . . 220 i . . . 262 i . . . 261 </CsScore> </CsoundSynthesizer>
joachim heintz sept 2010
| Previous | Home | Next |
| F2M | FilDir |