Subsections

周波数とMIDIノート番号 / Frequency and MIDI Note Number Converter

周波数からMIDIノート番号への変換 / Frequency to MIDI Note Number Converter

function [n,pb]=freq2note(f)
%FREQ2NOTE   Convert frequency to MIDI note number
%   n=freq2note(f) converts frequency to the closest MIDI note
%   number with pitch bend value for finer control.  'A' note above
%   the center 'C' correspond to the note number 69 (concert pitch
%   is set to 440Hz by default).  The default pitch bend range is 2
%   half tones above and below.
%
%   2005-10-13 by MARUI Atsushi

concert_pitch = 440;
bend_range = 2;   % 2 half tones below/above

x = log2(f / concert_pitch) * 12 + 69;
n = round(x);
pb = round((x - n) * 8192 / bend_range * 2);

MIDIノート番号から周波数への変換 / MIDI Note Number to Frequency Converter

function f=note2freq(n)
%NOTE2FREQ   Convert MIDI note number to frequency
%   f=note2freq(n) converts MIDI note number to frequency.
%   'A' note above the center 'C' correspond to the note number 69
%   (concert pitch is set to 440Hz by default).
%
%   2005-10-13 by MARUI Atsushi

concert_pitch = 440;
f = concert_pitch * 2 .^ ((n - 69)/12);



MARUI Atsushi
2023-12-05