function crosscorr_analysis_wrapper( recording_name, data_dir, framelength_sec, mic_list, output_filename, do_save_gcc )

% function crosscorr_analysis_wrapper( recording_name, data_dir, framelength_sec, mic_list, output_filename, do_save_gcc )
%
% Wrapper for "crosscorr_analysis.m": conduct a cross-correlation
% analysis between a lapel signal and a distant microphone signal, for
% a speaker at several locations in space.
%
% Check "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.
%
%   mic_list : array of integers, subset of 1:n_mic.
%
%   output_filename : string, for example 'DATA/seq01-1p-0000-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 < 5
    error( [ mfilename ' needs at least 5 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 "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' ] );

  n_dist_mic = numel( mic_list );

  p.distantmic_filename_list = cell( n_dist_mic, 1 );
  for a = 1:n_dist_mic
    p.distantmic_filename_list{ a } = sprintf( fullfile( data_dir, [ recording_name '_array%d_mic%d.wav' ] ), 1 + ( mic_list( a ) > 8 ), 1 + mod( mic_list( a ) - 1, 8 ) );
  end
  
  p.mic_list = mic_list;

  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 = 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
  