b@2: function autoalign(folderName, masterIndex) b@2: % AUTOALIGN aligns audio in folder with selected file (index 'masterIndex') b@2: % by inserting zeros at the start of the other files. b@2: % b@2: % by Brecht De Man at Centre for Digital Music on 17 November 2014 b@2: b@2: error('Work in progress, function not finished'); b@2: b@2: tic; % start measuring time b@2: list = dir([foldername '\*.wav']); % get names of files b@2: b@2: % remove hidden files from list b@2: % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220 b@2: for k = length(list):-1:1 b@2: fname = list(k).name; b@2: if fname(1) == '.' b@2: list(k) = [ ]; b@2: end b@2: end b@2: b@2: % load master file b@2: masterAudioChannels = audioread([foldername '/' list(masterIndex).name]); b@2: masterAudio = sum(masterAudioChannels, 2); % sum to mono b@2: disp(['Aligning audio files with ' list(masterIndex).name '...']); b@2: b@2: % for each other file: b@2: for i = 1:length(list) b@2: b@2: slaveAudioChannels = audioread([foldername '/' list(i).name]); % read file b@2: slaveAudio = sum(slaveAudioChannels, 2); % sum to mono b@2: b@2: % check sampling rate is the same b@2: % ... b@2: b@2: % crosscorrelation function b@2: xcorr(masterAudio, slaveAudio); b@2: b@2: % add zeros to beginning b@2: b@2: % monitoring/debugging b@2: b@2: end b@2: b@2: elapsedTime = toc; % stop measuring time b@2: disp(['autoalign took ' elapsedTime ' seconds to align the files in folder ' ... b@2: folderName ' with master file ' list(masterIndex).name]); b@2: b@2: end