function theoretical_crosscorr_analysis_wrapper( recording_name, data_dir, framelength_sec, output_filename, do_save_gcc )

% function theoretical_crosscorr_analysis_wrapper( recording_name, data_dir, framelength_sec, output_filename, do_save_gcc )
%
% Wrapper for "theoretical_crosscorr_analysis.m": simulate a
% cross-correlation analysis between a lapel signal and a distant
% microphone signal, in the case of a spherical wave emitted by a
% point source and travelling through a free field.
% 
% Check "theoretical_crosscorr_analysis.m" for more details.
% 
% Input:
%   
%   recording_name : string, for example 'seq01-1p-0000'.
%
%   data_dir : string, for example 'DATA'.
%
%   framelength_sec : float, length of a time frame in seconds, for
%   example 0.016 or 0.032.
%
%   output_filename : string, for example 'DATA/seq01-1p-0000-theoretical_crosscorr_analysis.mat'
% 
% Optional input:
% 
%   do_save_gcc : binary flag (0 or 1, default 1), telling whether we
%   save the cross-correlogram or not.
% 
% Output:
% 
%   A MATLAB object is stored as the binary file, with name "output_filename".
% 
% By Guillaume Lathoud, 2006  (email address in "my_email_address.jpg")

  if nargin < 4
    error( [ mfilename ' needs at least 4 input arguments.' ] );
  end
  
  if ~exist( 'do_save_gcc' )
    do_save_gcc = 1;
  end

  % Make sure that the output file does not exist already

  if exist( output_filename, 'file' )
    error( [ mfilename ': output file already exists ("' output_filename '").' ] );
  end
  
  % Prepare the parameters for "theoretical_crosscorr_analysis.m"

  p = [];
  p.static_gt_filename = fullfile( data_dir, [ recording_name '_gt.mat' ] );

  p.lapelmic_filename  = fullfile( data_dir, [ recording_name '_lapel1.wav' ] );

  p.framelength_sec = framelength_sec;
  
  p.save_gcc = do_save_gcc;
  
  p.verbose = 1;
  
  % Some verbosity
  if p.verbose
    disp( ' ' );
    disp( [ mfilename ': input:  recording "' recording_name '".' ] );
    disp( [ mfilename ': output: MATLAB binary data file "' output_filename '".' ] );
  end
  
  % Call it
  out = theoretical_crosscorr_analysis( p );
  
  % Add the base recording name
  out.recording_name = recording_name;
  
  % Write out the result
  save( output_filename, 'out' );
  
  if p.verbose
    disp( ' ' );
    disp( [ mfilename ' wrote out "' output_filename '".' ] );
  end
  