function info = sound_file_info(f)

% sound_file_info - get sound file information
% --------------------------------------------
%
% info = sound_file_info(f)
%
% Input:
% ------
%  f - file locations
%
% Output:
% -------
%  info - normalized sound file info

%--------------------------------
% Author: Harold Figueroa
%--------------------------------
% $Revision: 498 $
% $Date: 2005-02-03 19:53:25 -0500 (Thu, 03 Feb 2005) $
%--------------------------------

%---------------------------------------------
% HANDLE INPUT
%---------------------------------------------

%--
% handle multiple files recursively
%--

if iscell(f)
	
	j = 1;
	
	for k = 1:length(f)
		
		% NOTE: we handle this exception to deal with corrupt files
		
		try
			
			info(j) = sound_file_info(f{k});
			j = j + 1;
			
		catch 
			
			disp(' ');
			disp(['Unable to get sound file information from:']);
			disp(['''', f{k}, '''.']);
			disp(' ');
			
		end
		
	end
	
	%--
	% return empty
	%--
	
	if (j == 1)
		info = [];
	end
	
	return;
	
end
		
%---------------------------------------------
% GET FORMAT SPECIFIC INFO
%---------------------------------------------

%--
% try to get format handler 
%--

format = get_file_format(f);

%--
% read file using handler
%--

info = format.info(f);

% NOTE: this override of the lower format info is dubious

info.format = format.name;

%---------------------------------------------
% NORMALIZE INFO
%---------------------------------------------

% TODO: put this into a separate function and use 'struct_copy' when it is ready

% NOTE: the only requirement for this to work is that info fields are named the same

ninfo = info_create;

ninfo_field = fieldnames(ninfo);

info_field = fieldnames(info);

%--
% copy common fields from info to normalized info
%--

% TODO: consider making this type of copy a function

for k = 1:length(info_field)
	
	if ~isempty(find(strcmp(info_field{k}, ninfo_field)))
		ninfo.(info_field{k}) = info.(info_field{k});
	end
		
end

%--
% copy format specific fields into the 'info' output field
%--

format_field = setdiff(info_field, ninfo_field);

if ~isempty(format_field)
	
	for k = 1:length(format_field)
		ninfo.info.(format_field{k}) = info.(format_field{k});
	end
	
end

%--
% output standardized info structure
%--

info = ninfo;

%---------------------------------------------
% ADD SYSTEM INFORMATION
%---------------------------------------------

info.file = f;

% TODO: consider an option to skip this

if (1)
	
	sys = dir(f);
	
	info.name = sys.name;
	
	info.date = sys.date;
	
	info.bytes = sys.bytes;

end

