0001 function gui_model_cbk(src,eventdata,options)
0002 switch(get(src,'tag')),
0003 case 'menu',
0004
0005 targets=DIVA('AuditoryCortexCategorical','AuditoryTargets');
0006 for n=1:length(targets),
0007 names{n}=targets(n).label;
0008 end
0009 selIdx=get(src,'value');
0010 if(selIdx~=1)
0011 selected=get(src,'String');
0012 selStr=selected{selIdx};
0013 idx=findstr('(',selStr);
0014 match = strmatch(selStr(1:idx-2),names,'exact');
0015 DIVA('AuditoryCortexCategorical','match',match-1);
0016 DIVA('GUI','AC_WeightsFromTargets','target');
0017
0018 auTarget.filename=[selStr(1:idx-2),'.mat'];
0019 auTarget.pathname=['.',filesep,'Sessiontargets',filesep,'Session_',DIVA('SessionName'),filesep];
0020 DIVA('GUI','auTarget',auTarget);
0021 DIVA('GUI','train_sound',1);
0022
0023
0024 matchstart = (match-1)*DIVA('AuditoryCortexCategorical','ntimepoints');
0025 motorweights=DIVA('MotorCortex','WeightsFromTargets');
0026 if(~isempty(motorweights))
0027 if(matchstart < size(motorweights,2) - ...
0028 DIVA('AuditoryCortexCategorical','ntimepoints')),...
0029 producef='on';
0030 else
0031 producef='off';
0032 end
0033 else
0034 producef='off';
0035 end
0036 if(exist(fullfile('RESULTS','movies',['Session_',DIVA('SessionName')],...
0037 [selStr(1:idx-2),'.mov']),'file'))
0038 playf='on';
0039 else
0040 playf='off';
0041 end
0042 DIVA('GUI','play',playf,'produce',producef);
0043 end
0044
0045
0046 case 'play',
0047 target=DIVA('AuditoryCortexCategorical','AuditoryTargets');
0048 trained_sound=target(DIVA('AuditoryCortexCategorical','match')+1).label;
0049
0050
0051 if(DIVA('GUI','AutoMovie'))
0052 if(exist(fullfile('RESULTS','movies',['Session_',DIVA('SessionName')]),'dir'))
0053 pname = fullfile('RESULTS','movies',['Session_',DIVA('SessionName')]);
0054 web(['file:///',pwd,filesep,pname,filesep,[trained_sound,'.mov']],'-browser');
0055 end
0056 else
0057 [sound,fs]=getSynthSound();
0058 soundview(sound,fs);
0059 end
0060
0061
0062
0063 case 'produce',
0064
0065
0066
0067 old_WeightLearn.motor=DIVA('MotorCortex','WeightLearn');
0068 old_WeightLearn.somato=DIVA('SomatosensoryCortex','eps_learn');
0069
0070
0071 DIVA('MotorCortex','WeightLearn',0);
0072 DIVA('SomatosensoryCortex','eps_learn',0);
0073
0074 old_blockmode=DIVA('BlockMode');
0075 DIVA('BlockMode',1);
0076
0077 target=DIVA('AuditoryCortexCategorical','AuditoryTargets');
0078 trained_sound=target(DIVA('AuditoryCortexCategorical','match')+1).label;
0079 DIVA('AuditoryCortexCategorical','target',trained_sound);
0080 DIVA('simulate');
0081
0082 searchTarg = DIVA('MotorCortex','target',[],DIVA('TimeStep')*(-1000:0));
0083 idx=getQueueIdx(searchTarg);
0084 motor = DIVA('VocalTract','motor',[],DIVA('TimeStep')*(-idx:0));
0085 targ = searchTarg(1000-idx+1:end);
0086 [targ motor]=chompIdx(targ,motor);
0087
0088
0089
0090
0091
0092 DIVA('MotorCortex','WeightLearn',old_WeightLearn.motor);
0093 DIVA('SomatosensoryCortex','eps_learn',old_WeightLearn.somato);
0094 DIVA('BlockMode',old_blockmode);
0095
0096 DIVA('GUI','AC_WeightsFromTargets','update');
0097 DIVA('GUI','other_weights',[]);
0098
0099
0100 DIVA('GUI','play','on');
0101 [y,fs,motor]=getSynthSound(trained_sound);
0102 DIVA('GUI','Cochlea_plot',y);
0103 if(DIVA('GUI','AutoMovie'))
0104 produceAutoMovie(y,fs,motor,trained_sound);
0105 end
0106
0107
0108
0109 case 'browse',
0110
0111 browse_files;
0112
0113
0114
0115 case 'mic',
0116
0117
0118
0119
0120 case 'acquire',
0121 train_sound=DIVA('GUI','train_sound');
0122
0123 if(train_sound == 1)
0124 fname=DIVA('GUI','current_file');
0125 au_info=load(fname);
0126 DIVA('SoundChannel','sound',au_info.f.mean');
0127 DIVA('AuditoryCortexCategorical','label',au_info.name);
0128 DIVA('simulate');
0129 DIVA('GUI','ACC_AuditoryTargets','update');
0130 end
0131
0132
0133
0134 case {'reset'}
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 DIVA('reset');
0159 DIVA('GUI','ACC_AuditoryTargets','update');
0160
0161
0162
0163 case {'train'},
0164
0165
0166 target=DIVA('AuditoryCortexCategorical','AuditoryTargets');
0167 trained_sound = target(DIVA('AuditoryCortexCategorical','match')+1).label;
0168 progWin = waitbar(0,sprintf('Training %d%% complete',0));
0169 nTrain = DIVA('GUI','nTrain');
0170
0171 for i=1:nTrain,
0172 DIVA('AuditoryCortexCategorical','target',trained_sound);
0173 DIVA('simulate');
0174 DIVA('GUI','AC_WeightsFromTargets','update');
0175 DIVA('GUI','other_weights',[]);
0176 waitbar(i/nTrain,progWin,sprintf('Training %d%% complete',round(100*i/nTrain)));
0177 [y,fs,motor]=getSynthSound(trained_sound);
0178 DIVA('GUI','Cochlea_plot',y);
0179 DIVA('GUI','ACC_AuditoryTargets','update');
0180
0181 end
0182 close(progWin);
0183
0184
0185 DIVA('GUI','play','on','produce','on');
0186 [y,fs,motor]=getSynthSound(trained_sound);
0187 DIVA('GUI','Cochlea_plot',y);
0188
0189
0190 if(DIVA('GUI','AutoMovie'))
0191 produceAutoMovie(y,fs,motor,trained_sound);
0192 end
0193
0194
0195
0196 case 'other',
0197 DIVA('GUI','other_weights',[]);
0198
0199 end
0200
0201 function produceAutoMovie(y,fs,motor,name)
0202
0203 h=figure('position',[50 50 640 480],'menubar','none','doublebuffer','on');
0204 wh=waitbar(0,sprintf('%d%% complete',0),'position',[50 700 300 70]);
0205 figure(h);
0206 if(~exist(fullfile('RESULTS','movies',['Session_',DIVA('SessionName')]),'dir'))
0207 mkdir(fullfile('RESULTS','movies',['Session_',DIVA('SessionName')]));
0208 end
0209 pname = fullfile('RESULTS','movies',['Session_',DIVA('SessionName')]);
0210 if(nargin==4)
0211 fname = [name,'.mov'];
0212 else
0213 fname ='lastheard.mov';
0214 end
0215 if(~isempty(fname))
0216 MakeQTMovie('start',[pname,filesep,fname]);
0217 MakeQTMovie('size',[640 480]);
0218 MakeQTMovie('quality',0.8);
0219 for n=1:5:length(motor),
0220 figure(h);
0221 if(size(motor,1)>DIVA('MotorCortex','nMotor'))
0222 DIVA('VocalTract','plot',motor(1:end-3,n)); axis equal; axis off;
0223 else
0224 DIVA('VocalTract','plot',motor(:,n)); axis equal; axis off;
0225 end
0226 MakeQTMovie('addaxes');
0227 waitbar(n/length(motor),wh,sprintf('%d%% complete',round(100*n/length(motor))));
0228 end
0229 MakeQTMovie('frameRate',200);
0230 MakeQTMovie('addsound',y,fs);
0231 MakeQTMovie('finish');
0232 end
0233 close(h);
0234 close(wh);
0235
0236
0237 web(['file:///',pwd,filesep,pname,filesep,fname],'-browser');
0238
0239
0240
0241
0242
0243
0244
0245
0246