tomwalters@0
|
1 % tool
|
tomwalters@0
|
2 %
|
tomwalters@0
|
3 % INPUT VALUES:
|
tomwalters@0
|
4 %
|
tomwalters@0
|
5 % RETURN VALUE:
|
tomwalters@0
|
6 %
|
bleeck@3
|
7 % This external file is included as part of the 'aim-mat' distribution package
|
bleeck@3
|
8 % (c) 2011, University of Southampton
|
bleeck@3
|
9 % Maintained by Stefan Bleeck (bleeck@gmail.com)
|
bleeck@3
|
10 % download of current version is on the soundsoftware site:
|
bleeck@3
|
11 % http://code.soundsoftware.ac.uk/projects/aimmat
|
bleeck@3
|
12 % documentation and everything is on http://www.acousticscale.org
|
bleeck@3
|
13
|
tomwalters@0
|
14
|
tomwalters@0
|
15 function sig=transferetotune(tune,art)
|
tomwalters@0
|
16
|
tomwalters@0
|
17 % Tonlength:
|
tomwalters@0
|
18 % a=0.25
|
tomwalters@0
|
19 % b=0.5
|
tomwalters@0
|
20 % c=1
|
tomwalters@0
|
21 if nargin < 1
|
tomwalters@0
|
22 % tunes:
|
tomwalters@0
|
23 % Yankee Doodle
|
tomwalters@0
|
24 tune='aC5aC5aD5aE5aC5aE5aD5aG4aC5aC5aD5aE5aC5aC5aB4aG4aC5aC5aD5aE5aF5aE5aD5aC5aB4aG4aA4aB4aC5aC5aC5aC5';
|
tomwalters@0
|
25 % Frere Jackes
|
tomwalters@0
|
26 tune='aC5aD5aE5aC5aC5aD5aE5aC5aE5aF5aG5aE5aF5aG5');
|
tomwalters@0
|
27 end
|
tomwalters@0
|
28
|
tomwalters@0
|
29 if nargin<2
|
tomwalters@0
|
30 % art='decreaseoddamplitude';
|
tomwalters@0
|
31 art='decreaseoddphase';
|
tomwalters@0
|
32 % art='sinus';
|
tomwalters@0
|
33 % art='harmonic';
|
tomwalters@0
|
34 % art='clicktrain';
|
tomwalters@0
|
35 end
|
tomwalters@0
|
36
|
tomwalters@0
|
37 nr=size(tune,2);
|
tomwalters@0
|
38 duration=0.25;
|
tomwalters@0
|
39 sr=16000;
|
tomwalters@0
|
40 sig=signal(0,sr);
|
tomwalters@0
|
41
|
tomwalters@0
|
42 count=1;
|
tomwalters@0
|
43 notecount=0;
|
tomwalters@0
|
44 while count < nr-2
|
tomwalters@0
|
45 cur=tune(count);
|
tomwalters@0
|
46 if cur~='a' & cur~='b' & cur~='c'
|
tomwalters@0
|
47 error('Error in tune');
|
tomwalters@0
|
48 else
|
tomwalters@0
|
49 if cur=='a' duration=0.25;end
|
tomwalters@0
|
50 if cur=='b' duration=0.5;end
|
tomwalters@0
|
51 if cur=='c' duration=1;end
|
tomwalters@0
|
52 end
|
tomwalters@0
|
53 cur1=tune(count+1);
|
tomwalters@0
|
54 if cur1=='P';
|
tomwalters@0
|
55 fre=0;
|
tomwalters@0
|
56 count=count+2;
|
tomwalters@0
|
57 else
|
tomwalters@0
|
58 cur2=tune(count+2);
|
tomwalters@0
|
59 if count<nr-2
|
tomwalters@0
|
60 cur3=tune(count+3);
|
tomwalters@0
|
61 if strcmp(cur3,'#');
|
tomwalters@0
|
62 current=[cur1 cur2 cur3];
|
tomwalters@0
|
63 count=count+4;
|
tomwalters@0
|
64 notecount=notecount+1;
|
tomwalters@0
|
65 else
|
tomwalters@0
|
66 current=[cur1 cur2];
|
tomwalters@0
|
67 count=count+3;
|
tomwalters@0
|
68 notecount=notecount+1;
|
tomwalters@0
|
69 end
|
tomwalters@0
|
70 else
|
tomwalters@0
|
71 current=[cur1 cur2];
|
tomwalters@0
|
72 count=count+3;
|
tomwalters@0
|
73 notecount=notecount+1;
|
tomwalters@0
|
74 end
|
tomwalters@0
|
75 fre=note2fre(current);
|
tomwalters@0
|
76 end
|
tomwalters@0
|
77 freq(notecount)=fre;
|
tomwalters@0
|
78 end
|
tomwalters@0
|
79
|
tomwalters@0
|
80 mifre=min(freq);
|
tomwalters@0
|
81 for i=1:notecount
|
tomwalters@0
|
82 octab(i)=log2(freq(i)/mifre);
|
tomwalters@0
|
83 end
|
tomwalters@0
|
84 maxoct=max(octab);
|
tomwalters@0
|
85 for i=1:notecount
|
tomwalters@0
|
86 atten(i)=-(maxoct-octab(i))*20;
|
tomwalters@0
|
87 phase(i)=(maxoct-octab(i))*80;
|
tomwalters@0
|
88 end
|
tomwalters@0
|
89
|
tomwalters@0
|
90 for i=1:notecount
|
tomwalters@0
|
91 fre=freq(i);
|
tomwalters@0
|
92 if fre==0
|
tomwalters@0
|
93 ton=signal(duration,sr);
|
tomwalters@0
|
94 else
|
tomwalters@0
|
95 switch art
|
tomwalters@0
|
96 case 'sinus'
|
tomwalters@0
|
97 ton=sinus(duration,sr,fre);
|
tomwalters@0
|
98 case 'clicktrain'
|
tomwalters@0
|
99 ton=clicktrain(duration,sr,fre);
|
tomwalters@0
|
100 case 'harmonic'
|
tomwalters@0
|
101 bandwidth=1000; %fixed
|
tomwalters@0
|
102 df1=256;
|
tomwalters@0
|
103 df2=512;
|
tomwalters@0
|
104 fc=1000;
|
tomwalters@0
|
105 s=sprintf('genharmonics(signal(%f,%f),''fundamental'',''%f'',''filterprop'',[%f %f %f %f]);',duration,sr,fre,fc,df1,bandwidth,df2);
|
tomwalters@0
|
106 eval(sprintf('ton=%s;',s));
|
tomwalters@0
|
107 case 'decreaseoddamplitude'
|
tomwalters@0
|
108 bandwidth=2000; %fixed
|
tomwalters@0
|
109 f0=125;
|
tomwalters@0
|
110 df1=256;
|
tomwalters@0
|
111 df2=512;
|
tomwalters@0
|
112 fc=1000;
|
tomwalters@0
|
113 type='decreaseoddamplitude';
|
tomwalters@0
|
114 amp=atten(i);
|
tomwalters@0
|
115 s=sprintf('genharmonics(signal(%f,%f),''fundamental'',''%f'',''type'',''%s'',''changeby'',''%f'',''filterprop'',[%f %f %f %f]);',duration,sr,f0,type,amp,fc,df1,bandwidth,df2);
|
tomwalters@0
|
116 eval(sprintf('ton=%s;',s));
|
tomwalters@0
|
117 case 'decreaseoddphase'
|
tomwalters@0
|
118 bandwidth=2000; %fixed
|
tomwalters@0
|
119 f0=125;
|
tomwalters@0
|
120 df1=256;
|
tomwalters@0
|
121 df2=512;
|
tomwalters@0
|
122 fc=1000;
|
tomwalters@0
|
123 type='decreaseoddphase';
|
tomwalters@0
|
124 amp=phase(i);
|
tomwalters@0
|
125 s=sprintf('genharmonics(signal(%f,%f),''fundamental'',''%f'',''type'',''%s'',''changeby'',''%f'',''filterprop'',[%f %f %f %f]);',duration,sr,f0,type,amp,fc,df1,bandwidth,df2);
|
tomwalters@0
|
126 eval(sprintf('ton=%s;',s));
|
tomwalters@0
|
127 end
|
tomwalters@0
|
128 end
|
tomwalters@0
|
129 ton=rampamplitude(ton,0.02);
|
tomwalters@0
|
130 sig=append(sig,ton);
|
tomwalters@0
|
131 end
|
tomwalters@0
|
132
|
tomwalters@0
|
133 a=0;
|