annotate aim-mat/gui/loadsignalfile.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % procedure for 'aim-mat'
tomwalters@0 2 %
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 %
tomwalters@0 5 % RETURN VALUE:
tomwalters@0 6 %
tomwalters@0 7 % load the signal file and all files, that are in this directory
tomwalters@0 8 % set the project variables accordingly.
tomwalters@0 9 %
bleeck@3 10 %
tomwalters@0 11 % (c) 2011, University of Southampton
bleeck@3 12 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 13 % download of current version is on the soundsoftware site:
bleeck@3 14 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 15 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 16
tomwalters@0 17
tomwalters@0 18
tomwalters@0 19 function handles=loadsignalfile(handles,signame);
tomwalters@0 20
tomwalters@0 21
tomwalters@0 22 signalname=handles.info.signalname;
tomwalters@0 23 signalwavename=handles.info.signalwavename;
tomwalters@0 24 oldsignalwavename=handles.info.oldsignalwavename;
tomwalters@0 25 pcpname=handles.info.pcpname;
tomwalters@0 26 bmmname=handles.info.bmmname;
tomwalters@0 27 napname=handles.info.napname;
tomwalters@0 28 strobesname=handles.info.strobesname;
tomwalters@0 29 thresholdsname=handles.info.thresholdsname;
tomwalters@0 30 sainame=handles.info.sainame;
tomwalters@0 31 usermodulename=handles.info.usermodulename;
tomwalters@0 32 moviename=handles.info.moviename;
tomwalters@0 33
tomwalters@0 34
tomwalters@0 35 % load the parameterfile:
tomwalters@0 36 if fexist(handles.info.parameterfilename)
tomwalters@0 37 workdir=pwd;
tomwalters@0 38 cd(handles.info.directoryname);
tomwalters@0 39 [a,parfile,c,d]=fileparts(handles.info.parameterfilename);
tomwalters@0 40 clear all_options;
tomwalters@0 41 eval(parfile);
tomwalters@0 42 cd(workdir);
tomwalters@0 43 end
tomwalters@0 44
tomwalters@0 45
tomwalters@0 46
tomwalters@0 47 if fexist(signalname)
tomwalters@0 48 [sig,sigoptions]=aim_loadfile(signalname);
tomwalters@0 49 else
tomwalters@0 50 if fexist(signalwavename)
tomwalters@0 51 sig=loadwavefile(signal,signalwavename);
tomwalters@0 52 % and save the wavefile hinterher:
tomwalters@0 53 % nsf=sprintf('%s\\%s',handles.info.directoryname,signalwavename);
tomwalters@0 54 % copyfile(signalwavename,nsf);
tomwalters@0 55 % delete(signalwavename);
tomwalters@0 56 % signalwavename=nsf;
tomwalters@0 57 elseif fexist(oldsignalwavename)
tomwalters@0 58 sig=loadwavefile(signal,oldsignalwavename);
tomwalters@0 59 % and save the wavefile hinterher:
tomwalters@0 60 nsf=sprintf('%s\\%s',handles.info.directoryname,oldsignalwavename);
tomwalters@0 61 copyfile(oldsignalwavename,nsf);
tomwalters@0 62 % delete(oldsignalwavename);
tomwalters@0 63 signalwavename=nsf;
tomwalters@0 64 else
tomwalters@0 65 % handles=0;
tomwalters@0 66 return
tomwalters@0 67 end
tomwalters@0 68 end
tomwalters@0 69 handles.data.sig=sig;
tomwalters@0 70 len=getlength(sig);
tomwalters@0 71 if len<0.04
tomwalters@0 72 str=sprintf('Signal %s too short',signame);
tomwalters@0 73 er=errordlg(str,'File Error');
tomwalters@0 74 set(er,'WindowStyle','modal');
tomwalters@0 75 pause;
tomwalters@0 76 handles=0;
tomwalters@0 77 return
tomwalters@0 78 end
tomwalters@0 79
tomwalters@0 80
tomwalters@0 81 handles.info.signal_loaded=1;
tomwalters@0 82 % we add these parameters to the parameter file (for the future)
tomwalters@0 83 handles.all_options.signal.signal_filename=handles.info.oldsignalwavename;
tomwalters@0 84 handles.all_options.signal.start_time=0;
tomwalters@0 85 handles.all_options.signal.duration=getlength(sig);
tomwalters@0 86 handles.all_options.signal.samplerate=getsr(sig);
tomwalters@0 87 signalstruct.data=sig;
tomwalters@0 88 signalstruct.options=handles.all_options.signal;
tomwalters@0 89
tomwalters@0 90 % if the samplerate is too high, sample it down per default
tomwalters@0 91 sr=22050;
tomwalters@0 92 if handles.all_options.signal.samplerate>sr
tomwalters@0 93 % ask user if he wants that hi sample rate
tomwalters@0 94 srneu=input('The samplerate of the specified signal \nis higher then 22050 Hz. \nPlease insert a smaller samperate \n(or return for keeping the old one): ');
tomwalters@0 95 if ~isempty(srneu)
tomwalters@0 96 sig=changesr(sig,srneu);
tomwalters@0 97 handles.all_options.signal.samplerate=srneu;
tomwalters@0 98 signalstruct.data=sig;
tomwalters@0 99 handles.data.sig=sig;
tomwalters@0 100 end
tomwalters@0 101 end
tomwalters@0 102
tomwalters@0 103
tomwalters@0 104 save(signalname,'signalstruct');
tomwalters@0 105 savewave(sig,signalwavename,0);
tomwalters@0 106
tomwalters@0 107 if fexist(pcpname)
tomwalters@0 108 [pcp,type,options]=aim_loadfile(pcpname);
tomwalters@0 109 handles.data.pcp=pcp;
tomwalters@0 110 handles.info.pcp_loaded=1;
tomwalters@0 111 handles.info.calculated_pcp_module=type; % this one is really calculated
tomwalters@0 112 select(handles.listbox0,type);
tomwalters@0 113 if ~isempty(type)
tomwalters@0 114 str=sprintf('handles.all_options.pcpoptions.%s=options;',type);
tomwalters@0 115 eval(str);
tomwalters@0 116 else % old style
tomwalters@0 117 type='ELC';
tomwalters@0 118 handles.all_options.pcpoptions=options;
tomwalters@0 119 sai_savefile(pcp,pcpname,type,options,handles.all_options);
tomwalters@0 120 end
tomwalters@0 121 else
tomwalters@0 122 handles.info.pcp_loaded=0;
tomwalters@0 123 end
tomwalters@0 124
tomwalters@0 125 if fexist(bmmname)
tomwalters@0 126 [bmm,type,options]=aim_loadfile(bmmname);
tomwalters@0 127 handles.data.bmm=bmm;
tomwalters@0 128 handles.info.bmm_loaded=1;
tomwalters@0 129 handles.info.calculated_bmm_module=type; % this one is really calculated
tomwalters@0 130
tomwalters@0 131 select(handles.listbox1,type);
tomwalters@0 132 else
tomwalters@0 133 handles.info.bmm_loaded=0;
tomwalters@0 134 end
tomwalters@0 135 if fexist(napname)
tomwalters@0 136 [nap,type,options]=aim_loadfile(napname);
tomwalters@0 137 handles.data.nap=nap;
tomwalters@0 138 handles.info.nap_loaded=1;
tomwalters@0 139 select(handles.listbox2,type);
tomwalters@0 140 else
tomwalters@0 141 handles.info.nap_loaded=0;
tomwalters@0 142 end
tomwalters@0 143 if fexist(strobesname)
tomwalters@0 144 [strobes,type,options]=aim_loadfile(strobesname);
tomwalters@0 145 if fexist(thresholdsname)
tomwalters@0 146 thresholds=aim_loadfile(thresholdsname);
tomwalters@0 147 handles.data.thresholds=thresholds;
tomwalters@0 148 end
tomwalters@0 149 handles.data.strobes=strobes;
tomwalters@0 150 handles.info.strobes_loaded=1;
tomwalters@0 151 handles.info.calculated_strobes_module=type; % this one is really calculated
tomwalters@0 152 select(handles.listbox3,type);
tomwalters@0 153 else
tomwalters@0 154 handles.info.strobes_loaded=0;
tomwalters@0 155 end
tomwalters@0 156
tomwalters@0 157 if fexist(sainame)
tomwalters@0 158 [sai,type,options]=aim_loadfile(sainame);
tomwalters@0 159 handles.data.sai=sai;
tomwalters@0 160 handles.info.sai_loaded=1;
tomwalters@0 161 handles.info.calculated_sai_module=type; % this one is really calculated
tomwalters@0 162 select(handles.listbox4,type);
tomwalters@0 163
tomwalters@0 164 nr_frames=length(sai);
tomwalters@0 165 handles.slideredit_frames.minvalue=1;
tomwalters@0 166 handles.slideredit_frames.maxvalue=nr_frames;
tomwalters@0 167 % set the framecounter
tomwalters@0 168 handles.slideredit_frames=slidereditcontrol_set_value(handles.slideredit_frames,nr_frames); % set to the end
tomwalters@0 169 handles.slideredit_frames=slidereditcontrol_set_range(handles.slideredit_frames,nr_frames); % the duration
tomwalters@0 170
tomwalters@0 171 else
tomwalters@0 172 handles.info.sai_loaded=0;
tomwalters@0 173 end
tomwalters@0 174
tomwalters@0 175 if fexist(usermodulename)
tomwalters@0 176 [usermodule,type,options]=aim_loadfile(usermodulename);
tomwalters@0 177 handles.data.usermodule=usermodule;
tomwalters@0 178 handles.info.usermodule_loaded=1;
tomwalters@0 179 handles.info.calculated_usermodule_module=type; % this one is really calculated
tomwalters@0 180
tomwalters@0 181 select(handles.listbox6,type);
tomwalters@0 182 handles.info.usermodule_loaded=1;
tomwalters@0 183 else
tomwalters@0 184 handles.info.usermodule_loaded=0;
tomwalters@0 185 end
tomwalters@0 186
tomwalters@0 187 % TODO: only the first available movie is loaded. The others not
tomwalters@0 188 handles.info.movie_loaded=0;
tomwalters@0 189 if length(moviename)>1
tomwalters@0 190 for i=1:length(moviename)
tomwalters@0 191 cname=moviename{i};
tomwalters@0 192 if fexist(cname)
tomwalters@0 193 handles.info.movie_loaded=1;
tomwalters@0 194 handles.info.calculated_movie_module=cname; % this one is really calculated
tomwalters@0 195 break
tomwalters@0 196 end
tomwalters@0 197 end
tomwalters@0 198 end
tomwalters@0 199
tomwalters@0 200 % change the sliders according to the new signal:
tomwalters@0 201 % combi_start=handles.slideredit_start;
tomwalters@0 202 % combi_duration=handles.slideredit_start;
tomwalters@0 203
tomwalters@0 204 duration=0.04;
tomwalters@0 205 start_time=getminimumtime(sig);
tomwalters@0 206
tomwalters@0 207 handles.slideredit_duration.maxvalue=getlength(sig);
tomwalters@0 208 handles.slideredit_duration.minvalue=0.005;
tomwalters@0 209 handles.slideredit_start.minvalue=start_time;
tomwalters@0 210 handles.slideredit_start.maxvalue=getlength(sig);
tomwalters@0 211
tomwalters@0 212 handles.slideredit_start=slidereditcontrol_set_range(handles.slideredit_start,duration); % the duration
tomwalters@0 213 % handles.slideredit_duration=slidereditcontrol_set_range(handles.slideredit_duration,duration); % the duration
tomwalters@0 214 handles.slideredit_start=slidereditcontrol_set_value(handles.slideredit_start,start_time); % set to the beginning of the signal
tomwalters@0 215 handles.slideredit_duration=slidereditcontrol_set_value(handles.slideredit_duration,duration); % set to the beginning of the signal
tomwalters@0 216
tomwalters@0 217
tomwalters@0 218
tomwalters@0 219
tomwalters@0 220 set(handles.displayduration,'String',num2str(fround(getlength(sig)*1000,1)));
tomwalters@0 221
tomwalters@0 222
tomwalters@0 223
tomwalters@0 224 % % start_time=offset;
tomwalters@0 225 % set(handles.edit2,'String',num2str(start_time*1000));
tomwalters@0 226 % set(handles.edit3,'String',num2str(duration*1000));
tomwalters@0 227 %
tomwalters@0 228 %
tomwalters@0 229 % set(handles.slider3,'Value',0);
tomwalters@0 230 % set(handles.slider3,'Value',duration/max_duration);
tomwalters@0 231 %
tomwalters@0 232 % handles.data.min_duration=min_duration;
tomwalters@0 233 % handles.data.max_duration=max_duration;
tomwalters@0 234 % handles.data.max_start_time=max_start_time;
tomwalters@0 235 % handles.data.min_start_time=min_start_time;
tomwalters@0 236 %
tomwalters@0 237 % set(handles.edit1,'String',num2str(1));
tomwalters@0 238 % handles.data.min_scale=0.001;
tomwalters@0 239 % handles.data.max_scale=1000;
tomwalters@0 240 % set(handles.slider1,'Value',f2f(1,handles.data.min_scale,handles.data.max_scale,0,1,'loglin'));
tomwalters@0 241
tomwalters@0 242 % set(handles.pushbutton8,'Enable','on');
tomwalters@0 243 % set(handles.pushbutton9,'Enable','on');
tomwalters@0 244 % set(handles.pushbutton10,'Enable','on');
tomwalters@0 245 set(handles.edit1,'Enable','on');
tomwalters@0 246 set(handles.slider1,'Enable','on');
tomwalters@0 247 set(handles.edit2,'Enable','on');
tomwalters@0 248 set(handles.slider2,'Enable','on');
tomwalters@0 249 set(handles.edit3,'Enable','on');
tomwalters@0 250 set(handles.slider3,'Enable','on');
tomwalters@0 251
tomwalters@0 252
tomwalters@0 253 % aim_saveparameters(handles);
tomwalters@0 254
tomwalters@0 255
tomwalters@0 256 function select(hand,what)
tomwalters@0 257 str=get(hand,'String');
tomwalters@0 258 for i=1:length(str)
tomwalters@0 259 if strcmp(str,what)
tomwalters@0 260 set(hand,'Value',i);
tomwalters@0 261 return
tomwalters@0 262 end
tomwalters@0 263 end
tomwalters@0 264 return
tomwalters@0 265