( 変更履歴:
v0.4 [11/10/30] ctofの計算式を変更しました。)
Javaと同じく
サンダーソン氏の式から"うなり"を計算するプログラムです。
一行目の functionの後に「.m」を加えた「sand_beats.m」として
ファイルを作成して下さい。("#"以降は注釈文ですので省略可能です)
octaveの実行画面から
>> sand_beats
とする事で以下の様にグラフが表示されます。
function sand_beats # v0.3
global Pitch;
Pitch = 440;
intv = [24 4 1; 12 2 1; 7 3 2; 5 4 3; 4 5 4]; # ビートの順序
ints = {'2octave' 'Octave' 'P.5th' 'P.4th' 'Mj.3rd'}; # ビートの名前
for j = 1:length(intv)
be = getBeats(1:(88-intv(j,1)), intv(j,:)); # ビートを計算します
str = strcat(';', ints{j}, ';@', getCP(j)); # グラフの色と形と参照を作ります
plot(be, str) # グラフの表示です
hold on
end
hold off
grid on
axis([1 88 -25 25])
legend(2)
end
function beats = getBeats(key, inte)
beats = ctof(getFreq(key+inte(1)) .* inte(3),\
sanderson(key+inte(1), inte(3)))-\
ctof(getFreq(key) .* inte(2), sanderson(key, inte(2)));
end # 音程間のビートを計算します
function cent = sanderson(key, part)
cent = (4+part*part) .* pow2((key-49) ./ 12)-\
5+1.313 .* (1-pow2((49-key) ./ 12));
end # サンダーソン氏の式です
function f = ctof(freq, cent)
f = freq .* 2.^(cent/1200);
end # セント値から周波数に変換します
function freq = getFreq(key)
global Pitch;
freq = Pitch .* 2.^((key-49)./12);
end # キー番号から周波数を算出します
function cp = getCP(num)
colors = {'y', 'b', 'r', 'm', 'g', 'c'};
points = {'h', '+', 'x', '*', 'o', '^', 'v', '>', '<' ,'s', 'd', 'p'};
c = mod(num, length(colors))+1;
p = mod(num, length(points))+1;
cl = colors{c};
pt = points{p};
cp = strcat(cl, pt);
end # plotする点の色と形を決めます