% file: stereo_to_mono.m
%
% this function converts a stereo raw data file into two single channel raw
% data files.  the stereo file id left intact.
%
% arguments:
%  stereo_file		filename of the stereo raw data file
%  left_side		filename for the left channel raw data file
%  right_side		filename for the right channel raw data file
%
% outputs:
%  two single channel raw data files
%

function stereo_to_mono(stereo_file, left_side, right_side)

% open the stereo raw data file for reading
%
stereo_fp = fopen('stereo_file','r');

% open the single side raw data files for writing
%
left_fp = fopen('left_side','a');
right_fp = fopen('right_side','a');


% read in the stereo data 4-bytes/time 
% write to the appropriate channel (left/right)
%
while (~feof(stereo_fp))

   % read in the raw data (16-bit int) 4 bytes at a time
   %
   [stereo_raw,count] = fread(stereo_fp,2,'int16');

   % write the first 2 bytes to the left channel
   % 
   fwrite(left_fp,stereo_raw[1],'int16');
   
   % write the last 2 bytes to the right channel
   %
   fwrite(right_fp,stereo_raw[2],'int16');

end

% close the raw data files
%
fclose(stereo_fp);
fclose(left_fp);
fclose(right_fp);




