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);
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);