function finddouble(foldername)
% FINDDOUBLE spots doubles of audio files in the same folder
% 
% by Brecht De Man at Centre for Digital Music on 15 July 2013


list = dir([foldername '/*.wav']);  % find wav file names in folder

% remove hidden files from list
% see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220
for k = length(list):-1:1
    fname = list(k).name;
    if fname(1) == '.'
        list(k) = [ ];
    end
end

sums = zeros(length(list));       % number for every file

for i = 1:length(list)
    audio = audioread([foldername '/' list(i).name]); 
    sums(i) = sum(sum(audio.^2));
end

for i = 1:length(list)
    for j = i+1:length(list)
        if sums(i) == sums(j)
            disp(['ERROR: ' list(i).name ' = ' list(j).name])
        end
    end
end

end

% TODO: expand to more folders