Finding Octave Number

stringtapper's icon

I'm making a patch to explore just tuning and while my algorithm might not be so efficient (any comments on that welcome) it's brought to a point where I need to find the octave of the input note since my algorithm has to mod-12 the input in order to derive the correct ratio from the coll object. Any ideas on how to find which octave a note is in and then multiply its (just tuned) frequency to get that octave?

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

Peter Castine's icon

[/ 12] will give you the octave number of your MIDI note number.

As for the rest of your patch, that's one way of doing it. Another alternative would be to store the floating point values of the ratios in your coll rather than the numerator/denominator pairs of the fractions. Something like

0, 1.;
1, 1.0666667;
2, 1.125;
3, 1.2;
4, 1.25;

etc. That would allow you to cut out three objects from the patch.

stringtapper's icon

Duh, it's funny how I had already figured out how the math worked going in one direction but couldn't apply it in the other.

And double duh with the floating values. It's not my day. Thanks, Peter.

Here's the patch. Monophonic just intonation. Currently uses C as the base note (1/1).

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

Luke Hall's icon

You could replace the [coll] on the left with [expr pow(2,$i1)] and get the same outcomes.

stringtapper's icon

Thank you Luke. Thinking mathematically to make things more efficient is one of my biggest hurdles. This helps a lot.