Powers/Exponents?

Rob Reed's icon

Hi, i have a program that turns images into a simple melody. I want to be able to allow the user to change the key of the melody, but to do this i need to multiply a constant (1.059463) to the power of the amount of semitones above A4 (so A = 0, A# =1, B =2) etc... The base note frequency will also have to change as the program relies on it changing to operate.

In this example, the output will be the frequency value of C4: F = 440*(1.059463)³

F = Frequency
440 = base note frequency
1.059463 = Constant
³ = The amount of semitones up from A required to get to C

In my program, both the base note and the power are variables. If you check out my program it might make a bit more sense as i don't think im explaining myself well.

Attached is a picture for those who might just be skimming through

Max Patch
Copy patch and select New From Clipboard in Max.

TL;DR: How do you do exponents/powers?

Untitled.jpg
jpg
DK's icon

[pow] ?

Peter Castine's icon

Probably easier to do everything with MIDI values, where transposition is just adding a constant, then use [mtof] to convert to frequency.

The help file for [mtof] shows you how to use an [expr] that does the calculation. If you're determined to do the exponential calculations yourself, check mtof.maxhelp to see how it's done.

Peter Castine's icon

Also, as nice useful as [split] is, in that massive chain of [split] objects why don't you just send the input to the first split to a [/ 32] instead and use the output as an index to a [coll] object? The coll would look something like

0, 440;
1, 494;
2, 554;
3, 587;
...and so on...

Or you could use [table] instead of a [coll].

Wetterberg's icon

yeah, just use mtof/ftom. Peter's right on the money, imo.