# Can Anyone Help With Some Maths?

I’m trying to work out a formula for doing what Renoise does when I select to adjust sample’s pitch to fit the loop into the current BPM - so I can do the same when using my Akai sampler, and take a bit of the guess work out of fine tuning cents… but I seem to have completely forgotten how to do maths

This is what I’ve got so far:

( ( number of beats in bar / sample length in seconds ) * 60 ) / BPM of track = ratio I need to increase/decrease sample length by

now i’ve got to turn this ratio into a Pitch increase/decrease in semitones and cents

2 ^ ( number of semitones to go up / 12 ) = ratio between note gap

a cent is about 1.0005777895% of a semitone

this is where I’ve cheated and worked out all the ratios of an octave manually (I’m guessing remembering how to use log would tidy that up a bit); then I can find a closest (lower) match to the ratio I need to match, then:

( ( ratio I need to increase or decrease sample length by - closest lower match ) / ( closest high match - closest lower match ) ) / 1.0005777895 = number of cents to increase by

Can anyone figure out a proper way to do this? (ideally in monkey language, so I can enter it straight into the Windows calculator without having to think)

Thanks!

The magic value I think you are looking for is: value = log(ratio) / log(2)

Or simply: value = log2(ratio)

Then…

semitones = value * 12

or

cents = value * 1200

PS. Grab CCalc… it rocks and you can use log2(ratio) natively there without manually bothering with log(ratio) / log(2)
http://ccalc.shanebweb.com/

PPS. This page contains a lot of useful info.

.

that’s fantastic, cheers!

should make life a lot easier