Home > . > DIVA_SoundChannel.m

DIVA_SoundChannel

PURPOSE ^

DIVA_SoundChannel DIVA Sound-Channel module.

SYNOPSIS ^

function out=DIVA_SoundChannel(varargin);

DESCRIPTION ^

 DIVA_SoundChannel DIVA Sound-Channel module.

 This module incorporates any sound transformations due to the
 channel between the sound produced by the model vocal tract
 and the sound perceived by the model cochlea.

 DIVA_SoundChannel('init' [,SessionName]);          Initializes the module
 DIVA_SoundChannel('save' [,SessionName] );         Saves state
 DIVA_SoundChannel('exit');                         Exits the module (without saving)
 DIVA_SoundChannel(PropertyName [,PropertyValue] )  Reads and writes internal model properties

 DIVA_Cochlea('sound',s,fs,delay);
 DIVA_Cochlea('noise',s,fs);
 Forwards its input to the Cochlea module with a given delay (defined by
 the 'delayToCochlea' module property)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function out=DIVA_SoundChannel(varargin);
0002 % DIVA_SoundChannel DIVA Sound-Channel module.
0003 %
0004 % This module incorporates any sound transformations due to the
0005 % channel between the sound produced by the model vocal tract
0006 % and the sound perceived by the model cochlea.
0007 %
0008 % DIVA_SoundChannel('init' [,SessionName]);          Initializes the module
0009 % DIVA_SoundChannel('save' [,SessionName] );         Saves state
0010 % DIVA_SoundChannel('exit');                         Exits the module (without saving)
0011 % DIVA_SoundChannel(PropertyName [,PropertyValue] )  Reads and writes internal model properties
0012 %
0013 % DIVA_Cochlea('sound',s,fs,delay);
0014 % DIVA_Cochlea('noise',s,fs);
0015 % Forwards its input to the Cochlea module with a given delay (defined by
0016 % the 'delayToCochlea' module property)
0017 
0018 % Dependencies:
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     % INITIALIZES INTERNAL MODULE PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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   % INITIALIZES OTHER (TEMPORAL) PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0047   DIVA_SoundChannel_data.params.current=struct(...
0048       'sound',[],...
0049       'fs',[],...
0050       'delay',[]);
0051   % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0052 
0053   % LIST OF MODULE CHANNELS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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   % CODE FOR CLEARING MEMORY OR THE LIKE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0070   % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0071 
0072  case 'disp',
0073   disp(DIVA_SoundChannel_data.params);
0074   out=fieldnames(DIVA_SoundChannel_data.params);
0075 
0076   % CODE IMPLEMENTING THIS MODULE PROCESS(ES) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0077   % Note: use DIVA(ModuleName,ChannelName,data,delay) to comunicate with other DIVA modules
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

Generated on Tue 27-Mar-2007 12:06:24 by m2html © 2003