%Script to run analysis of 20 audio samples. GCC-PHAT is calculated for
%each audio sample using all framesizes in frameSizeVec and windows in
%winShapes


% Developer:  - Alice Clifford (alice.clifford@eecs.qmul.ac.uk)


close all
clear all

Fs=44100;


frameSizeVec=[128 256 512 1024 2048 4096 8192]; %framesizes to test

winShapes={ %window shapes to test
    'blackman',
    'blackmanharris',
    'flattopwin',
    'gausswin',
    'hamming',
    'hann',
    'rectwin',
    };

ds=50;  %actual delay derived from visual analysis

PATH='audio/';
fid=fopen('analysisFileNames_041112.txt');
tempNames=textscan(fid,'%s');

numFiles=length(tempNames{1});

fileNames=cell(numFiles,1);


for f=1:length(frameSizeVec)
    f
    frameSize=frameSizeVec(f);
    hopSize=frameSize/4;
    
    for n=1:numFiles
        n
        fileNames{n}=tempNames{1}{n};
        fullPath=strcat(PATH,fileNames{n});
        
        
        
        [x,Fs]=wavread(fullPath);
        
        for w=1:length(winShapes)
            w
            
            delayVec(:,n,w)=gccPHATFunc_win(x,frameSize,hopSize,winShapes{w});
            percHitsMat(n,w)=percCorr(delayVec(:,n,w),ds,2); %estimate percentage correct
        end
        
        
        
        
    end
    
    
%     save(strcat('Results/accuracyData_240512_framesize',int2str(frameSize)))
%     %uncomment to save results
    
    clear delayVec percHitsMat mseMat euclidMat
    
    
    
    
    
    
    
end

display('Instrument audio analysis complete')
