olvb/phaze

Pitch Factor ?

Opened this issue · 4 comments

Hello there !

Your lib looks like what I need but I can't see any documentation.
Reading your sources, I can pretty much get how to use it but I'm wondering :

what is the relation between pitch factor and tones/octaves ?
I think climbing an octave multiplies frequency by 2... does that mean I have to set the pitch factor to 2 ? or 0.5 to go down an octave..

Thanks for your help ^^

olvb commented

Hi! You are correct, going up an octave means multiply the frequency by 2 and going down an octave by 0.5

Many thanks for your answer @olvb ^^

Just got into this, it's great! yeah if you're working with music and trying to transpose, it's a bit difficult because the relationship is nonlinear. here's what i believe is the relationship after a quick regression. semitones correspond to the related pitch factor.

const toneFactors = { "-12": 0.5, "-11": 0.5226, "-10": 0.5486, "-9": 0.5781, "-8": 0.6111, "-7": 0.6476, "-6": 0.6875, "-5": 0.7309, "-4": 0.7778, "-3": 0.8281, "-2": 0.8819, "-1": 0.9392, "0": 1.0, "1": 1.0642, "2": 1.1319, "3": 1.2031, "4": 1.2778, "5": 1.3559, "6": 1.4375, "7": 1.5226, "8": 1.6111, "9": 1.7031, "10": 1.7986, "11": 1.8976, "12": 2.0 };

It can be computed, a mathematician figured it out centuries ago I forget who, has to do with Pythagorean commas etc etc:

function semitonesToSpeed(semitones) {
	return Math.pow(2, (semitones/12));
}

function speedToSemitones(playbackRate) {
	return Math.log(playbackRate/1)/0.05776227;
}