0001 function out=DIVA_SoundChannel(varargin);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 out=[];
0022 global DIVA_SoundChannel_data
0023
0024 indexargin=1;
0025 switch(varargin{indexargin}),
0026 case 'init',
0027 SessionFolder=strcat(DIVA('SessionFolder'),filesep);
0028 if nargin<indexargin+1 | isempty(varargin{indexargin+1}),
0029 initfile='';
0030 else,
0031 initfile=[SessionFolder,'Session_',varargin{indexargin+1},filesep,mfilename,'.mat'];
0032 end
0033
0034 if isempty(initfile) || isempty(dir(initfile)),
0035 disp([mfilename, ' : Defining new session...']);
0036
0037 DIVA_SoundChannel_data.params=struct(...
0038 'fs',DIVA('Cochlea','fs'),...
0039 'delayToCochlea',.0);
0040
0041
0042 else,
0043 data=load(initfile,'-mat');
0044 DIVA_SoundChannel_data.params=data.params;
0045 end
0046
0047 DIVA_SoundChannel_data.params.current=struct(...
0048 'sound',[],...
0049 'fs',[],...
0050 'delay',[]);
0051
0052
0053
0054 out={};
0055
0056
0057 case 'save',
0058 SessionFolder=strcat(DIVA('SessionFolder'),filesep);
0059 if nargin<indexargin+1,
0060 initfile=[SessionFolder,'Session_','default',filesep,mfilename,'.mat'];
0061 else,
0062 initfile=[SessionFolder,'Session_',varargin{indexargin+1},filesep,mfilename,'.mat'];
0063 end
0064 params=DIVA_SoundChannel_data.params;
0065 save(initfile,'params');
0066
0067 case 'exit',
0068 clear DIVA_SoundChannel_data;
0069
0070
0071
0072 case 'disp',
0073 disp(DIVA_SoundChannel_data.params);
0074 out=fieldnames(DIVA_SoundChannel_data.params);
0075
0076
0077
0078 case {'sound','noise'},
0079 DIVA_SoundChannel_data.current.sound=varargin{indexargin+1};
0080 if nargin<indexargin+2 | isempty(varargin{indexargin+2}),
0081 DIVA_SoundChannel_data.current.fs=DIVA_SoundChannel_data.params.fs;
0082 else,
0083 DIVA_SoundChannel_data.current.fs=varargin{indexargin+2};
0084 end
0085
0086 if nargin<indexargin+3 | isempty(varargin{indexargin+3}),
0087 DIVA_SoundChannel_data.current.delay=0;
0088 else,
0089 DIVA_SoundChannel_data.current.delay=varargin{indexargin+3};
0090 end
0091
0092 DIVA_SoundChannel_data.current.delay=...
0093 DIVA_SoundChannel_data.current.delay+...
0094 DIVA_SoundChannel_data.params.delayToCochlea;
0095
0096 if ~nargout,
0097 DIVA('Cochlea',varargin{indexargin},DIVA_SoundChannel_data.current.sound,...
0098 DIVA_SoundChannel_data.current.fs,DIVA_SoundChannel_data.current.delay);
0099 else,
0100 out={DIVA_SoundChannel_data.current.sound};
0101 end
0102
0103
0104 otherwise,
0105 if isfield(DIVA_SoundChannel_data.params,varargin{indexargin}),
0106 if indexargin==nargin,
0107 out=DIVA_SoundChannel_data.params.(varargin{indexargin});
0108 else,
0109 DIVA_SoundChannel_data.params.(varargin{indexargin})=varargin{indexargin+1};
0110 end
0111 else,
0112 warning('DIVA_SoundChannel: wrong argument');
0113 end
0114 end
0115