a string format for musical scales, consisting of a sequence of newline-separated math expressions corresponding to the frequency interval of each scale degree (ending with the octave).
Try it out in Frequency Explorer.
2^(1/12)
9/8
5/4
4/3
3/2
5/3
15/8
2
int baseNote, the note number of the tonic.double baseFreq, the frequency of the tonic.size_t scaleSize, the number of degrees inscale(at least1).double* scale, an array containing the frequency ratio of each scale degree, ending with the octave.
- Returns a
tuningspecified by:baseNoteExpr, a math expression forbaseNote(rounded to nearest integer).baseFreqExpr, a math expression forbaseFreq.scaleExpr, math expressions for eachscaledegree, separated by\n.
- Math expressions are parsed by TinyExpr.
- Be sure to call
free(tuning.scale)when you're done with it to prevent a memory leak.
- Returns the frequency of a
noteaccording to atuning.
#include "scalemap.h"
int main() {
tuning t = newTuning("69","440","2^(1/12)");
noteToFreq(60, t); // returns 261.626
free(t.scale);
}Defines all the same functions and types as in C, plus the Tuning convenience class:
Tuning(std::string baseNoteExpr, std::string baseFreqExpr, std::string scaleExpr)int baseNotedouble baseFreqstd::vector<double> scalenoteToFreq(int note)
#include "scalemap.h"
int main() {
Tuning t ("69","440","2^(1/12)");
t.noteToFreq(60); // returns 261.626
}Ported to WebAssembly with Emscripten
- Returns the Number result of parsing the String
mathExprusing TinyExpr - If the math expression is invalid, returns
0
Tuning(baseNoteExpr, baseFreqExpr, scaleExpr)(Object)baseNote(Number)baseFreq(Number)scale(Array of Numbers)noteToFreq(note)(Number)
<script src="scalemap.js"></script>
<script>
Module.onRuntimeInitialized = function() { // wait for WebAssembly to initialize
var t = new Tuning("69","440","2^(1/12)");
t.noteToFreq(60); // returns 261.626
}
</script>