セント値と周波数の変換計算の修正です。(その13)
これまで Javaプログラムで使用して来た `ctof'のメソッド
private final double ML = Math.log(2)/1200/Math.log(10); public double ctof(double freq, double cent) { return freq*Math.pow(10, cent*ML); }
を以下のように修正します。
public double ctof(double freq, double cent) { return freq*Math.pow(2, cent/1200); }
又 `Octave'で使用して来た `ctof'と`f2c'も
MC = 1200/log(2); ML = log10(2)/1200; function f = ctof(freq, cent) global ML; f = freq.*10.^(cent*ML); end function cent = f2c(key, freq) global MC; cent = MC*log(freq./GetFreq(key)); end
以下の様に修正します。
function f = ctof(freq, cent) f = freq.*2.^(cent/1200); end function cent = f2c(key, freq) cent = 1200*log2(freq./GetFreq(key)); end
結果はどちらでも同じです。
これまでのプログラムでは随時変更して行くつもりです。
`Octave'での比較です。
--------ここから------- function cf_test global ML MC; MC = 1200/log(2); ML = log10(2)/1200; key = 46:52; f = getFreq(key) c = 100; disp("Old_type:") ctof_old(f, c) f2c_old(key, 442) disp("New_type:") ctof_new(f, c) f2c_new(key, 442) end function f = ctof_old(freq, cent) global ML; f = freq.*10.^(cent*ML); end function cent = f2c_old(key, freq) global MC; cent = MC*log(freq./getFreq(key)); end function f = ctof_new(freq, cent) f = freq.*2.^(cent/1200); end function cent = f2c_new(key, freq) cent = 1200*log2(freq./getFreq(key)); end function freq = getFreq(key) freq = 440.*2.^((key-49)./12); end --------ここまで-------- octave[]> cf_test f = 369.99 392.00 415.30 440.00 466.16 493.88 523.25 Old_type: ans = 392.00 415.30 440.00 466.16 493.88 523.25 554.37 ans = 307.8514 207.8514 107.8514 7.8514 -92.1486 -192.1486 -292.1486 New_type: ans = 392.00 415.30 440.00 466.16 493.88 523.25 554.37 ans = 307.8514 207.8514 107.8514 7.8514 -92.1486 -192.1486 -292.1486
変更履歴: v0.1 ['11/10/03]