Forums > MaxMSP

Changing speed by a "semitone"

Jun 24 2009 | 11:08 am

not reeeally a max related question here but i’m having difficulties.
I want to have a transposition dial in my app that will "speed" the sound file up by a multiple of semitones.
i figured that 1 is normal speed. 2 is double speed and therefore an octave up.
And octave is 12 semitones.
1/12 = 0.833333
So the number of the dial * 0.833 then + 1 so that 0 on the dial will play at normal speed.

-- Pasted Max Patch, click to expand. --

It just doesn’t work and i can’t think why. It’s probably something really obvious that i’ve missed but any helped would be great.

Jun 24 2009 | 11:39 am

This is leftover from the code I use for keyboard transposing in my own patches, but it should work fine….

— Pasted Max Patch, click to expand. —

Jun 24 2009 | 11:52 am

You can do it like that as well :

— Pasted Max Patch, click to expand. —


Jun 24 2009 | 12:00 pm

A simple [expr pow(2.,($f1/12))] will do the trick.


Jun 24 2009 | 12:04 pm

Thanks guys.
Ch, your one has a few errors. For example: if you put in 12 it should come out with 2 but its just a smidgen under.

Gregory, that’s a nice solution but not as elegant as the final one posted.

Thanks again everyone Very Happy

Jun 24 2009 | 7:50 pm wrote on Wed, 24 June 2009 14:00
A simple [expr pow(2.,($f1/12))] will do the trick.



[expr exp(.057762265*($f1-60.))]

where the 60 is the key number (middle C)


Jun 24 2009 | 8:11 pm

The [expr pow(2.,($f1/12))] solution is preferable because expr will perform the internal arithmetic in double-precision whereas values such as 0.057762 in an object or message box are initially parsed in single-precision. It is precisely the single-precision issue that leads to the minuscule (and absolutely inaudible) discrepancy noted in Ch’s example.

Of course, the easiest thing to do is to use [mtof]. That’s what it’s there for.

Jun 24 2009 | 8:25 pm

how would you do a more acccurate conversion for note
to rate? when i made mine last century i tested it against


and that gives the same results like using exp()

btw, isnt [mtof] doing the less exact calculation, too?


Jun 25 2009 | 9:03 am
Roman Thilenius wrote on Wed, 24 June 2009 22:25

and that gives the same results like using exp()

wow. uh oh.
of course i couldnt notice the difference when trying
only a few keys upwards. from 3 octaves on i do.


Jun 26 2009 | 10:57 am

[mtof] is (almost certainly) using an internal double-precision representation of pow(2, 1/12).

When you write 1.059463 (or any other float) in an object box, the object can only get a single-precision value. The content of an object box is passed to the object code in the form of atoms, and these can only contain 32-bit values.

This is all in the SDK documentation.

May 05 2016 | 12:59 pm

Could anyone help me out with the equation going the other way? I want to work out how much I alter the pitch of a file when i play it back over a shorter or longer time frame. For example the sample is 2000 msecs long, but i play i back over 700 msecs. How many semitones have I shifted the pitch?

May 06 2016 | 2:55 am

Take the ratio of original length to new length and feed it into [expr (log($f1)/0.693147)*12]. For 2000/700, the answer is 18.17.

— Pasted Max Patch, click to expand. —
May 06 2016 | 1:47 pm

Thanks! Perfect!

Viewing 13 posts - 1 through 13 (of 13 total)

Forums > MaxMSP