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