Mercurial > hg > nimfks
comparison src/matlab/controller.m @ 0:c52bc3e8d3ad tip
user: boblsturm
branch 'default'
added README.md
added assets/.DS_Store
added assets/playButton.jpg
added assets/stopButton.png
added assets/swapButton.jpg
added data/.DS_Store
added data/fiveoctaves.mp3
added data/glock2.wav
added data/sinScale.mp3
added data/speech_female.mp3
added data/sweep.wav
added nimfks.m.lnk
added src/.DS_Store
added src/matlab/.DS_Store
added src/matlab/AnalysisCache.m
added src/matlab/CSS.m
added src/matlab/DataHash.m
added src/matlab/ExistsInCache.m
added src/matlab/KLDivCost.m
added src/matlab/LoadFromCache.m
added src/matlab/SA_B_NMF.m
added src/matlab/SaveInCache.m
added src/matlab/Sound.m
added src/matlab/SynthesisCache.m
added src/matlab/chromagram_E.m
added src/matlab/chromagram_IF.m
added src/matlab/chromagram_P.m
added src/matlab/chromsynth.m
added src/matlab/computeSTFTFeat.m
added src/matlab/controller.m
added src/matlab/decibelSliderReleaseCallback.m
added src/matlab/drawClickCallBack.m
added src/matlab/fft2chromamx.m
added src/matlab/hz2octs.m
added src/matlab/ifgram.m
added src/matlab/ifptrack.m
added src/matlab/istft.m
added src/matlab/nimfks.fig
added src/matlab/nimfks.m
added src/matlab/nmfFn.m
added src/matlab/nmf_beta.m
added src/matlab/nmf_divergence.m
added src/matlab/nmf_euclidean.m
added src/matlab/prune_corpus.m
added src/matlab/rot_kernel.m
added src/matlab/templateAdditionResynth.m
added src/matlab/templateDelCb.m
added src/matlab/templateScrollCb.m
author | boblsturm |
---|---|
date | Sun, 18 Jun 2017 06:26:13 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c52bc3e8d3ad |
---|---|
1 function controller(action, handles) | |
2 | |
3 switch action | |
4 case 'openTarget' | |
5 [filename pathname] = uigetfile({'*.wav;*.mp3;'}, 'File Selector'); | |
6 targetpathname= strcat(pathname, filename); | |
7 handles.Sound_target = Sound(targetpathname); | |
8 set(handles.txt_targetfile, 'String', filename); | |
9 set(handles.txt_targetfile,'TooltipString',filename); | |
10 case 'openSource' | |
11 [filenames pathname]= uigetfile({'*.wav;*.mp3;'}, 'File Selector', 'MultiSelect','on'); | |
12 | |
13 if( iscell( filenames ) ) | |
14 for i = 1:length( filenames ) | |
15 sourcepathname = strcat(pathname, filenames{i}); | |
16 tmp_snd = Sound(sourcepathname); | |
17 if isfield(handles, 'Sound_corpus') | |
18 handles.Sound_corpus = handles.Sound_corpus.concat( tmp_snd ); | |
19 else | |
20 handles.Sound_corpus = tmp_snd; | |
21 end | |
22 end | |
23 | |
24 cat_files = strjoin(filenames,'\n'); | |
25 set(handles.txt_corpusfile, 'String', cat_files); | |
26 set(handles.txt_corpusfile,'TooltipString', char(cat_files)); | |
27 else | |
28 sourcepathname = strcat(pathname, filenames); | |
29 handles.Sound_corpus = Sound(sourcepathname); | |
30 set(handles.txt_corpusfile, 'String', filenames); | |
31 set(handles.txt_corpusfile,'TooltipString', filenames); | |
32 end | |
33 | |
34 case 'swapSourceAndTarget' | |
35 tmp = handles.Sound_target; | |
36 handles.Sound_target = handles.Sound_corpus; | |
37 handles.Sound_corpus = tmp; | |
38 | |
39 corpus_displayName = get( handles.txt_corpusfile, 'String' ); | |
40 corpus_tooltip = get( handles.txt_corpusfile, 'TooltipString' ); | |
41 target_displayName = get( handles.txt_targetfile, 'String' ); | |
42 target_tooltip = get( handles.txt_targetfile, 'TooltipString' ); | |
43 | |
44 set(handles.txt_targetfile, 'String', corpus_displayName); | |
45 set(handles.txt_targetfile,'TooltipString', corpus_tooltip); | |
46 set(handles.txt_corpusfile, 'String', target_displayName); | |
47 set(handles.txt_corpusfile,'TooltipString', target_tooltip); | |
48 case 'playTarget' | |
49 handles.Sound_target.control_audio('play'); | |
50 case 'stopTarget' | |
51 handles.Sound_target.control_audio('stop'); | |
52 case 'playSynthesis' | |
53 handles.Sound_synthesis.control_audio('play'); | |
54 case 'stopSynthesis' | |
55 handles.Sound_synthesis.control_audio('stop'); | |
56 case 'runAnalysis' | |
57 waitbarHandle = waitbar(0.15, 'Verifying parameters...'); | |
58 spectTypeSelected=get(handles.pop_specttype, 'Value'); | |
59 spectTypes=get(handles.pop_specttype, 'String'); | |
60 | |
61 winTypeSelected=get(handles.pop_wintype, 'Value'); | |
62 winTypes=get(handles.pop_wintype, 'String'); | |
63 | |
64 win.Length = str2num(get(handles.edt_winlen, 'String'))*44100/1000; | |
65 win.Hop = str2num(get(handles.edt_overlap, 'String'))*44100/1000; | |
66 win.Type = cell2mat(winTypes(winTypeSelected)); | |
67 | |
68 CacheObj = AnalysisCache(handles.Sound_corpus.Signal, handles.Sound_target.Signal, ... | |
69 winTypeSelected, win.Length, win.Hop); | |
70 handles.CurrentAnalysisCache = CacheObj; | |
71 if( strcmp(get(handles.tool_menu_dev_cacheEnable, 'Checked'), 'on') ) | |
72 waitbar(0.33, waitbarHandle,'Checking cache...'); | |
73 | |
74 GenerateHash(CacheObj); | |
75 Cached = ExistsInCache(CacheObj.Hash, handles, 'Analysis'); | |
76 | |
77 if( ~Cached ) | |
78 waitbar(0.66, waitbarHandle, 'Analyzing corpus...') | |
79 handles.Sound_corpus.computeFeatures(win, spectTypes(spectTypeSelected)); | |
80 | |
81 waitbar(0.95, waitbarHandle, 'Analyzing target...') | |
82 handles.Sound_target.computeFeatures(win, spectTypes(spectTypeSelected)); | |
83 | |
84 waitbar(0.98, waitbarHandle, 'Saving in cache...') | |
85 | |
86 DataToCache = struct( ... | |
87 'Corpus', handles.Sound_corpus, ... | |
88 'Target', handles.Sound_target ... | |
89 ); | |
90 handles.Cache = SaveInCache( CacheObj, handles, 'Analysis', DataToCache ); | |
91 else | |
92 waitbar(0.75, waitbarHandle, 'Hooray, exists in cache! Loading...') | |
93 FromCache = LoadFromCache( CacheObj.Hash, 'Analysis' ); | |
94 handles.Sound_corpus = FromCache.Corpus; | |
95 handles.Sound_target = FromCache.Target; | |
96 end | |
97 else | |
98 waitbar(0.66, waitbarHandle, 'Analyzing corpus...') | |
99 handles.Sound_corpus.computeFeatures(win, spectTypes(spectTypeSelected)); | |
100 | |
101 waitbar(0.95, waitbarHandle, 'Analyzing target...') | |
102 handles.Sound_target.computeFeatures(win, spectTypes(spectTypeSelected)); | |
103 end | |
104 close(waitbarHandle); | |
105 case 'runSynthesis' | |
106 waitbarHandle = waitbar(0.15, 'Checking cache...'); | |
107 costMetricSelected=get(handles.pop_cost, 'Value'); | |
108 costMetrics=get(handles.pop_cost, 'String'); | |
109 | |
110 actPatternSelected=get(handles.pop_pattern, 'Value'); | |
111 actPatterns=get(handles.pop_pattern, 'String'); | |
112 | |
113 nmf_params.Algorithm = cell2mat(costMetrics(costMetricSelected)); | |
114 nmf_params.Iterations = str2num(get(handles.edt_iter, 'String')); | |
115 nmf_params.Convergence_criteria = str2double(get(handles.edt_conv, 'String')); | |
116 nmf_params.Repition_restriction = str2double(get(handles.edt_mod_rep, 'String')); | |
117 nmf_params.Polyphony_restriction = str2double(get(handles.edt_mod_poly, 'String')); | |
118 nmf_params.Continuity_enhancement = str2double(get(handles.edt_mod_cont, 'String')); | |
119 nmf_params.Continuity_enhancement_rot = str2double(get(handles.edt_mod_cont_rot, 'String')); | |
120 nmf_params.Diagonal_pattern = cell2mat(actPatterns(actPatternSelected)); | |
121 nmf_params.Modification_application = get(handles.chk_endtime, 'Value'); | |
122 nmf_params.Random_seed = str2double(get(handles.edt_rand, 'String')); | |
123 nmf_params.Lambda = str2double(get(handles.edt_sparse_lambda, 'String')); | |
124 | |
125 resynthMethodSelected=get(handles.pop_synthmethod, 'Value'); | |
126 resynthMethods=get(handles.pop_synthmethod, 'String'); | |
127 | |
128 pct_prune = ( 100 - str2double(get(handles.edt_prune, 'String')) )/100; | |
129 synth = CSS(nmf_params, cell2mat(resynthMethods(resynthMethodSelected))); | |
130 | |
131 % Cache related operations | |
132 % if( strcmp(get(handles.tool_menu_dev_cacheEnable, 'Checked'), 'on') ) | |
133 GenerateHash(handles.CurrentAnalysisCache); | |
134 CacheObj = SynthesisCache( ... | |
135 nmf_params.Iterations, nmf_params.Random_seed, nmf_params.Convergence_criteria, ... | |
136 costMetricSelected, nmf_params.Repition_restriction, nmf_params.Polyphony_restriction, ... | |
137 nmf_params.Continuity_enhancement, actPatternSelected, nmf_params.Continuity_enhancement_rot, ... | |
138 nmf_params.Modification_application, nmf_params.Lambda, pct_prune, handles.CurrentAnalysisCache.Hash ); | |
139 | |
140 GenerateHash(CacheObj); | |
141 Cached = ExistsInCache(CacheObj.Hash, handles, 'Synthesis'); | |
142 disp( CacheObj.Hash ); | |
143 | |
144 if( ~Cached ) | |
145 waitbar(0.5, waitbarHandle, 'Not found in cache. Running NMF...') | |
146 synth.nmf(handles.Sound_corpus, handles.Sound_target, pct_prune); | |
147 | |
148 waitbar(0.75, waitbarHandle, 'Saving in cache...') | |
149 DataToCache = struct( ... | |
150 'Activations', synth.Activations, ... | |
151 'Cost', synth.Cost ... | |
152 ); | |
153 | |
154 handles.Cache = SaveInCache( CacheObj, handles, 'Synthesis', DataToCache ); | |
155 else | |
156 waitbar(0.75, waitbarHandle, 'Hooray, exists in cache! Loading...') | |
157 FromCache = LoadFromCache( CacheObj.Hash, 'Synthesis' ); | |
158 synth.Activations = FromCache.Activations; | |
159 synth.Cost = FromCache.Cost; | |
160 end | |
161 % else | |
162 % synth.nmf(handles.Sound_corpus, handles.Sound_target); | |
163 % end | |
164 | |
165 synth.synthesize(handles.Sound_corpus); | |
166 | |
167 winTypeSelected=get(handles.pop_wintype, 'Value'); | |
168 winTypes=get(handles.pop_wintype, 'String'); | |
169 | |
170 win.Length = str2num(get(handles.edt_winlen, 'String'))*44100/1000; | |
171 win.Hop = str2num(get(handles.edt_overlap, 'String'))*44100/1000; | |
172 win.Type = cell2mat(winTypes(winTypeSelected)); | |
173 | |
174 spectTypeSelected=get(handles.pop_specttype, 'Value'); | |
175 spectTypes=get(handles.pop_specttype, 'String'); | |
176 | |
177 handles.SynthesisObject = synth; | |
178 handles.Sound_synthesis = Sound(synth.Synthesis, handles.Sound_corpus.Sampling_rate); | |
179 handles.Sound_synthesis.computeFeatures(win, spectTypes(spectTypeSelected)); | |
180 | |
181 close(waitbarHandle); | |
182 case 'savePlot' | |
183 case 'exportResynth' | |
184 case 'switchPlot' | |
185 selectedPlot=get(handles.pop_plot, 'Value'); | |
186 plotOptions=get(handles.pop_plot, 'String'); | |
187 delete(handles.axes2.Children); | |
188 cla(gca,'reset') | |
189 plotRequest = plotOptions(selectedPlot); | |
190 switch(plotRequest{1}) | |
191 case 'Synthesis Plot' | |
192 view(gca, 2); | |
193 handles.Sound_synthesis.plot_signal; | |
194 set(handles.tbl_plotdata, 'Data', handles.Sound_synthesis.Signal'); | |
195 case 'Cost' | |
196 view(gca, 2); | |
197 handles.SynthesisObject.plot_cost; | |
198 set(handles.tbl_plotdata, 'Data', handles.SynthesisObject.Cost'); | |
199 case 'Activations' | |
200 view(gca, 2); | |
201 handles.SynthesisObject.plot_activations(get(handles.sld_maxdb, 'Value')); | |
202 set(handles.tbl_plotdata, 'Data', handles.SynthesisObject.Activations); | |
203 case 'Corpus Spectrogram' | |
204 view(gca, 2); | |
205 handles.Sound_corpus.plot_spectrogram; | |
206 set(handles.tbl_plotdata, 'Data', abs(handles.Sound_corpus.Features.STFT.S)); | |
207 case 'Target Spectrogram' | |
208 view(gca, 2); | |
209 handles.Sound_target.plot_spectrogram; | |
210 set(handles.tbl_plotdata, 'Data', abs(handles.Sound_target.Features.STFT.S)); | |
211 case 'Synthesis Spectrogram' | |
212 view(gca, 2); | |
213 handles.Sound_synthesis.plot_spectrogram; | |
214 set(handles.tbl_plotdata, 'Data', abs(handles.Sound_synthesis.Features.STFT.S)); | |
215 case 'Templates' | |
216 view(gca, 3); | |
217 handles.Sound_corpus.plot_templates; | |
218 set(handles.tbl_plotdata, 'Data', abs(handles.Sound_corpus.Features.STFT.S)); | |
219 end | |
220 case 'resynthesize' | |
221 synth = handles.SynthesisObject; | |
222 synth.synthesize(handles.Sound_corpus); | |
223 handles.SynthesisObject = synth; | |
224 handles.Sound_synthesis.Audioplayer = audioplayer(handles.SynthesisObject.Synthesis, handles.Sound_corpus.Sampling_rate); | |
225 case 'rerun' | |
226 resynthMethodSelected=get(handles.pop_synthmethod, 'Value'); | |
227 resynthMethods=get(handles.pop_synthmethod, 'String'); | |
228 nmf_params = handles.SynthesisObject.NMF_features; | |
229 | |
230 pct_prune = ( 100 - str2double(get(handles.edt_prune, 'String')) )/100; | |
231 synth = CSS(nmf_params, cell2mat(resynthMethods(resynthMethodSelected))); | |
232 synth.nmf(handles.Sound_corpus, handles.Sound_target, pct_prune); | |
233 synth.synthesize(handles.Sound_corpus); | |
234 | |
235 handles.SynthesisObject = synth; | |
236 end | |
237 | |
238 guidata(handles.figure1, handles); | |
239 end |