[Csnd] Question re: converting note pitches to ratios
Date | 2023-04-16 23:01 |
From | Scott Daughtrey |
Subject | [Csnd] Question re: converting note pitches to ratios |
With some opcodes such as diskin & the granular opcodes, the pitch is determined by a ratio ex. 1 = no change, 2 = octave up, .5 = octave down. If one knows the pitch of the input file, for example A2, what is the recommended way of dealing with this? So if I want to be able to use cpspch, mtof or cpsmidinn etc. to determine my note choices and apply those to the pitch parameter of the opcodes that use ratios, what would be a good method to approach it? I'm not particularly good at math... so far the idea I had was something like this (assuming input sample is A2, 110 Hz), which is just dividing standard freq by the sample freq: instr 1 kfreq = cpspch(8.09) knote = kfreq/110 printk .1, knote kfreq2 = mtof(69) knote2 = kfreq2/110 printk .1, knote2 endin Is there a better or more accurate way? The answer or proper opcode/example to do this is probably right in front of me somewhere & likely there is a general way to approach it as I certainly can't be the first to ponder this, but I'm a little lost here. Scott Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2023-04-16 23:21 |
From | "Jeanette C." |
Subject | Re: [Csnd] Question re: converting note pitches to ratios |
Hi Scott, there are the opcods semitone and cent, which will determine the factor necessary to change any pitch to go up/down the given semitones or cents. So if you specify MIDI notes and hard code the MIDI note of your file, it's easy. Say iFileNote init 69 iDesiredNote init 60 iTones = iDesiredNote - iFileNote ; = -9 iReadFactor init semitone(iTones) aInput diskin2 Sfile, iReadFactor I haven't tested it, but I hope you get the picture and can corect any haphazard mistakes in the above code. :) Best wishes and good luck, Jeanette -- * Website: http://juliencoder.de - for summer is a state of sound * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g * Audiobombs: https://www.audiobombs.com/users/jeanette_c * GitHub: https://github.com/jeanette-c You should never try to change me I can be nobody else And I like the way I am <3 (Britney Spears) Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |