tomwalters@0: % support file for 'aim-mat' tomwalters@0: % bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: tomwalters@0: tomwalters@0: function [str,oct,nr_note]=fre2note(fre) tomwalters@0: tomwalters@0: % translates the fre to the nearest real note in a-g tomwalters@0: tomwalters@0: if fre==0 tomwalters@0: str='no'; tomwalters@0: oct=0; tomwalters@0: nr_note=-1; tomwalters@0: return tomwalters@0: end tomwalters@0: tomwalters@0: note_names=['A ';'A#';'B ';'C ';'C#';'D ';'D#';'E ';'F ';'F#';'G ';'G#']; tomwalters@0: lowest_note=27.5; % Hz =A1 440 Hz= a4 tomwalters@0: tomwalters@0: for i=1:length(fre) tomwalters@0: if fre(i)>0 tomwalters@0: cent(i)=fre2cent(lowest_note,fre(i)); tomwalters@0: % how many octaves? tomwalters@0: nr_octs(i)=round(cent(i)/1200)-1; tomwalters@0: oct(i)=nr_octs(i)+1; tomwalters@0: tomwalters@0: % how many tones? tomwalters@0: cento(i)=mod(cent(i),1200)/100; tomwalters@0: nr_note(i)=round(cento(i)+1); tomwalters@0: if nr_note(i)>12 tomwalters@0: nr_note(i)=1; tomwalters@0: end tomwalters@0: % nr_note(find(nr_note>12))=1; tomwalters@0: else tomwalters@0: nr_note(i)=0; tomwalters@0: end tomwalters@0: end tomwalters@0: % compansate for that the octave changes at C tomwalters@0: for i=1:length(fre) tomwalters@0: if nr_note(i) > 3 && nr_note(i) < 7 tomwalters@0: nr_octs(i)=nr_octs(i)+1; tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: for i=1:length(fre) tomwalters@0: if nr_note(i)==0 tomwalters@0: str{i}=['00']; tomwalters@0: elseif strcmp(note_names(nr_note(i),2),' ') tomwalters@0: if nr_octs(i)<0 tomwalters@0: str{i}=[note_names(nr_note(i)) '0']; tomwalters@0: else tomwalters@0: str{i}=[note_names(nr_note(i)) num2str(nr_octs(i))+1]; tomwalters@0: end tomwalters@0: else tomwalters@0: if nr_octs(i)<0 tomwalters@0: str{i}=[note_names(nr_note(i),1:2) '0']; tomwalters@0: else tomwalters@0: str{i}=[note_names(nr_note(i),1:2) num2str(nr_octs(i))+1]; tomwalters@0: end tomwalters@0: end tomwalters@0: end