% This function is to read the signal at win_center_time
%  
function read_signal(num_chans, start_sample, end_sample,end_file_sample, fid);

bytes_per_sample = 2;
% open the audio file
%
fid = fopen('test.raw','r');

% set file pointers to required location in input file
%
fread(fid, inf, 'bit16');

% check the bounds of start and end sample
%
new_start = start_sample;
new_end   = end_sample;
num_samples = 0;

if (start_sample < 0) 
  for i=start_sample:1,
	 signal_window(i) = 0;
  end
  new_start =0;
end

if (end_sample > end_file_sample) 
  new_end = end_file_sample;
end

if (new_start > new_end) 
  fprintf(1,' start sample is greater than end sample\n');
end

% seek to the point in the file we want to read the
% data
fseek(fid, new_start * bytes_per_sample * num_chans, 0);
samples_read = (new_end - new_start) * num_chans;

% read these values 
%
[C, count] = fread(fid, samples_read, 'short');

% convert the short int to floating point values
%
for i=1:samples_read
signal_window(num_samples) = C(i);
end;

% pad it with 0s if window ends after file ends
%
if (end_sample > end_file_sample) 
  for i=end_file_sample:end_sample,
	 signal_window(num_samples) =0;
  end
end

fprintf(1, 'read signal success');
fclose(fid);





