Csound Csound-dev Csound-tekno Search About

Re: Converting midi pitch to cps?

Date1998-09-16 21:52
FromAndre Bartetzki
SubjectRe: Converting midi pitch to cps?
Edward Spiegel wrote:
> 
> OK. So, the problem I was having with MidiToCSound was that it doesn't
> output the pitch by default.
> 
> Now that I've got that working, I have a new question. MidiToCSound
> expresses the pitch as the midi note number. Is there a pitch converter
> that will take a midi note number value and convert it to cps, pch or oct
> format?
> 
> As far as I can tell cpsmidi and cpsmidib only work for realtime stuff. I
> tried:
> 
> icps = cpsmidi(p4)
> 
> That doesn't work. Is there a pitch converter function that will do this?
> (I'm using the latest CSound for PPC from Mills).
> 
> Here is a sample of what midiToCsound puts out
> 
> i 1 0.000 0.237 48
> i 1 0.000 0.237 72
> i 1 0.250 0.237 55
> i 1 0.250 0.237 63
> 
> Thanks,
> 
> Edward

A MIDI note number is in Csounds terminology something like a pch (pitch) or oct.
The middle c on a keyboard (note number 60) equals to 8.00 in Csound, one
octave lower is 48 in MIDI and 7.00 in Csound, 36 is 6.00 and so on. Therefore
you have to divide the MIDI number by 12 to get Csound octs. The lowest MIDI
note number is 0, that is 5 octaves below 60 and 3.00 in Csound. This gives us
the formula for transforming MIDI to oct:

oct(MIDI) = MIDI/12.0 + 3.0

The conversion to Hertz can be done by cpsoct ("make cps from oct").
If p4 contains the MIDI note number you can write:

icps = cpsoct(p4/12.0 + 3.0)

If you want to convert MIDI to pch you have to take into account that pch is
not a normal decimal number but two numbers pasted together by a dot: 
octave and two digits for semitones above that octave  (8.09 is a4, 8.9 is 90
semitones higher than c4)

pch(MIDI) = int(MIDI/12.0) + (MIDI - int(MIDI/12.0)) / 10.0


Hope this helps

Andre
 
--------------------------------------------------
Andre Bartetzki http://www.kgw.tu-berlin.de/~abart
Studio fuer elektroakustische Musik http://www.kgw.tu-berlin.de/~abart/Steam/steam.html
Hochschule fuer Musik Berlin http://www.hfm-berlin.de

Tel. +49-30-4726629
Tel. +49-30-203092488