function [frameDelayVec]=gccPHATFunc_win(x,frameSize,hopSize,windowShape)
% calculate the GCC-PHAT delay estimation on frames of data
%
% Input:
%   - x: stereo audio file. x(:,2) is delayed
%   - frameSize: size of frames (samples)
%   - hopSize: overlap between frames (samples)
%   - windowShape: string passed to window()
%
% Output:
%   - frameDelayVec: array of delay estimation for each frame
%
% Developers:  - Alice Clifford (alice.clifford@eecs.qmul.ac.uk)

[xMat,numFrames]=createMat(x,frameSize,hopSize);

w=repmat(window(windowShape,frameSize),[1 2 numFrames]);

X=fft(xMat.*w); %FFT of each frame with window applied

for n=1:numFrames
    
    %GCC-PHAT
    Sxs=X(:,2,n).*conj(X(:,1,n));
        
    S=Sxs./abs(Sxs);
    
    s=ifft(S);

    [dummy,frameDelay]=max(s(1:frameSize/2)); %assume delay in first frameSize/2 samples
    
    frameDelayVec(n)=frameDelay-1; %compensate for index starting at 1


end
