function gowave4(wavefile1,wavefile2,C,maxrange)



%gowave4
%
%   gowave4(wavefile1,wavefile2,c,maxrange) reads from 2 wavefiles to
%   simulate a stream of audio data from 4 mics.  gowave4 then breaks
%   the signal into blocks, processes them, and
%   displays the possible source positions to a plot.  The blocks
%   overlap by half of a block size, so no impulse is lost becaust it
%   fell between blocks.

% NOTE: should take in 2 STEREO wavefiles
% C is the distance between microphones
% maxrange is the maximum range to display on the plot

if exist('maxrange') == 0, maxrange = 6;, end


EBlockSize=2^11;
ablocksize=2*EBlockSize;

%Check for stereo wavefile
siz1 = wavread(wavefile1,'size');
if siz1(2) ~= 2, 'Input wavefile1 must be stereo', return, end
siz2 = wavread(wavefile2,'size');
if siz2(2) ~= 2, 'Input wavefile2 must be stereo', return, end
%Must base all counts on the smaller wavefile, since i don't want to over run EOF.
BigN = min(siz1(1),siz2(1));

FullEBlocks=floor(BigN/EBlockSize);
if FullEBlocks == 0, 'Please use larger signals', return, end

%initialize the polar plot
initpolar(C,maxrange);
hold on;
title('Plots of Possible Signal Source Position')

%plot the microphone positions
polar(0,C,'*');
polar(2*pi/3,C,'*');
polar(4*pi/3,C,'*');



qblock = zeros(2,5);
qpoint = 1;

%Begin calculating on the blocks
for i = 0:FullEBlocks-2; %must stop short because of the staggered blocks.

   Startindex=i*EBlockSize+1;
   
   Endindex=Startindex + ablocksize-1;
   
   [input1, SF1, nbits1]  = wavread(wavefile1, [Startindex Endindex]);
   xleft1 = input1(:,1)';
   xright1 = input1(:,2)';
   
   [input2, SF2, nbits2] = wavread(wavefile2, [Startindex Endindex]);
   xleft2 = input2(:,1)';
   xright2 = input2(:,2)';
   
   if SF1~=SF2, 'Please ensure that the wavefiles have the same SF', return, end
   
   S1 = size(xleft1);
   lsx= ceil(log(S1(2))/log(2)); %Nearest Power of 2
   if S1(2) ~= 2^lsx, 'Incorrect block sizes. Check lines 37-40 in gowave4.m', return, end
   
   
   %%/*THESE LINES ADD NOISE!!! For testing purposes only!
   %xleft1 = xleft1 + noise(norm(xleft1)/100,max(size(xleft1)));
   %xright1 = xright1 + noise(norm(xright1)/100,max(size(xright1)));
   %xleft2 = xleft2 + noise(norm(xleft2)/100,max(size(xleft2)));
   %xright2 = xright2 + noise(norm(xright2)/100,max(size(xright2)));
   %%*/THESE LINES ADD NOISE!!!!
   
   %micA = xleft1
   %micB = xright1
   %micC = xleft2
   %micD = xright2
   
   %		B
   %		
   %
   %
   %			D	   A
   %
   %
   %
   %		C		
         
   

%Need to ensure that this will return the appropriate sign convention.   
   
   T1 = -fshift(xleft1,xright2);
   T2 = -fshift(xright1,xright2);
   T3 = -fshift(xleft2,xright2);
   
   
   q = quadmath(T1,T2,T3,C,SF1);
   theta = q(1);
   R = q(2);
   if and(theta ~= NaN, R ~= NaN), qblock(:,qpoint) = q';, end
   qpoint = qpoint +1;
   if qpoint == 6, qpoint = 1;, hold on, polar(qblock(1,:), qblock(2,:),'.');,pause(.1),end
end
polar(qblock(1,:), qblock(2,:),'.');
hold off


Number_Of_Blocks_Computed = FullEBlocks-1