function mono2stereo(folder)
% MONO2STEREO join any two mono files in folder ending on 'L' and 'R' to 
% one stereo file
%
% by Brecht De Man at Centre for Digital Music, 22 May 2013

list = dir([folder '/*.wav']);
for i = 2:length(list)
    if strcmp(list(i).name(1:end-4), [list(i-1).name(1:end-5) 'R'])
        if strcmp(list(i-1).name(1:end-4), [list(i).name(1:end-5) 'L'])
            [L,fs] = audioread([folder '/' list(i-1).name]);
            R      = audioread([folder '/' list(i).name]);
            audiowrite([folder '/' list(i).name(1:end-5) '.wav'], [L,R], fs, 'BitsPerSample', 24);
            delete([folder '/' list(i-1).name], [folder '/' list(i).name]); % delete original files
        end
    end
end

end