Mercurial > hg > aimmat
annotate aim-mat/tools/note2fre.m @ 0:74dedb26614d
Initial checkin of AIM-MAT version 1.5 (6.4.2011).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 12:32:31 +0100 |
parents | |
children | 20ada0af3d7d |
rev | line source |
---|---|
tomwalters@0 | 1 % support file for 'aim-mat' |
tomwalters@0 | 2 % |
tomwalters@0 | 3 % This external file is included as part of the 'aim-mat' distribution package |
tomwalters@0 | 4 % http://www.pdn.cam.ac.uk/cnbh/aim2006 |
tomwalters@0 | 5 % $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ |
tomwalters@0 | 6 % $Revision: 585 $ |
tomwalters@0 | 7 |
tomwalters@0 | 8 function [fre,oct,nr_note]=note2fre(note) |
tomwalters@0 | 9 |
tomwalters@0 | 10 % translates the note to the frequency |
tomwalters@0 | 11 |
tomwalters@0 | 12 note_names=['A ';'B ';'C ';'C#';'D ';'D#';'E ';'F ';'F#';'G ';'G#';'H ']; |
tomwalters@0 | 13 lowest_note=27.5; % Hz =A1 440 Hz= a5 |
tomwalters@0 | 14 |
tomwalters@0 | 15 |
tomwalters@0 | 16 rnote=note(1); |
tomwalters@0 | 17 if strcmp(rnote(1),' ') || double(rnote(1))==9 |
tomwalters@0 | 18 note=note(2:end); |
tomwalters@0 | 19 rnote=note(1); |
tomwalters@0 | 20 end |
tomwalters@0 | 21 if strcmp(note(2),'#') |
tomwalters@0 | 22 rnote=[rnote '#']; |
tomwalters@0 | 23 octnum=note(3); |
tomwalters@0 | 24 elseif strcmp(note(2),'b') |
tomwalters@0 | 25 rnote=[rnote 'b']; |
tomwalters@0 | 26 octnum=note(3); |
tomwalters@0 | 27 else |
tomwalters@0 | 28 octnum=note(2); |
tomwalters@0 | 29 end |
tomwalters@0 | 30 |
tomwalters@0 | 31 |
tomwalters@0 | 32 % http://www.jita.com.cn/Seiten/Theorie/musik_theorie_1.htm |
tomwalters@0 | 33 switch rnote |
tomwalters@0 | 34 case {'A','a'} |
tomwalters@0 | 35 nr_note=1; |
tomwalters@0 | 36 case {'A#','a#','Bb','bb'} |
tomwalters@0 | 37 nr_note=2; |
tomwalters@0 | 38 case {'H','h','B','b'} |
tomwalters@0 | 39 nr_note=3; |
tomwalters@0 | 40 case {'C','c'} |
tomwalters@0 | 41 nr_note=4; |
tomwalters@0 | 42 case {'C#','c#','Db','db'} |
tomwalters@0 | 43 nr_note=5; |
tomwalters@0 | 44 case {'D','d'} |
tomwalters@0 | 45 nr_note=6; |
tomwalters@0 | 46 case {'D#','d#','Eb','eb'} |
tomwalters@0 | 47 nr_note=7; |
tomwalters@0 | 48 case {'E','e'} |
tomwalters@0 | 49 nr_note=8; |
tomwalters@0 | 50 case {'F','f'} |
tomwalters@0 | 51 nr_note=9; |
tomwalters@0 | 52 case {'F#','f#','Gb','gb'} |
tomwalters@0 | 53 nr_note=10; |
tomwalters@0 | 54 case {'G','g'} |
tomwalters@0 | 55 nr_note=11; |
tomwalters@0 | 56 case {'G#','g#','Ab','ab'} |
tomwalters@0 | 57 nr_note=12; |
tomwalters@0 | 58 otherwise |
tomwalters@0 | 59 fre=0; |
tomwalters@0 | 60 return |
tomwalters@0 | 61 end |
tomwalters@0 | 62 |
tomwalters@0 | 63 oct=str2num(octnum); |
tomwalters@0 | 64 |
tomwalters@0 | 65 % compansate for that the octave changes at C |
tomwalters@0 | 66 if nr_note > 3 |
tomwalters@0 | 67 calcoct=oct-1; |
tomwalters@0 | 68 else |
tomwalters@0 | 69 calcoct=oct; |
tomwalters@0 | 70 end |
tomwalters@0 | 71 gescent=calcoct*1200+100*(nr_note-1); |
tomwalters@0 | 72 fre=cent2fre(lowest_note,gescent); |
tomwalters@0 | 73 |
tomwalters@0 | 74 |