annotate aux/autoalign.m @ 2:5e72201496c8
Bug fixes, added stripzeros function, added new loudness function, moved general documentation to top level, MATLAB_R2014b compatibility
author |
Brecht De Man <b.deman@qmul.ac.uk> |
date |
Mon, 17 Nov 2014 19:43:43 +0000 |
parents |
|
children |
1f7b986dab05 |
rev |
line source |
b@2
|
1 function autoalign(folderName, masterIndex)
|
b@2
|
2 % AUTOALIGN aligns audio in folder with selected file (index 'masterIndex')
|
b@2
|
3 % by inserting zeros at the start of the other files.
|
b@2
|
4 %
|
b@2
|
5 % by Brecht De Man at Centre for Digital Music on 17 November 2014
|
b@2
|
6
|
b@2
|
7 error('Work in progress, function not finished');
|
b@2
|
8
|
b@2
|
9 tic; % start measuring time
|
b@2
|
10 list = dir([foldername '\*.wav']); % get names of files
|
b@2
|
11
|
b@2
|
12 % remove hidden files from list
|
b@2
|
13 % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220
|
b@2
|
14 for k = length(list):-1:1
|
b@2
|
15 fname = list(k).name;
|
b@2
|
16 if fname(1) == '.'
|
b@2
|
17 list(k) = [ ];
|
b@2
|
18 end
|
b@2
|
19 end
|
b@2
|
20
|
b@2
|
21 % load master file
|
b@2
|
22 masterAudioChannels = audioread([foldername '/' list(masterIndex).name]);
|
b@2
|
23 masterAudio = sum(masterAudioChannels, 2); % sum to mono
|
b@2
|
24 disp(['Aligning audio files with ' list(masterIndex).name '...']);
|
b@2
|
25
|
b@2
|
26 % for each other file:
|
b@2
|
27 for i = 1:length(list)
|
b@2
|
28
|
b@2
|
29 slaveAudioChannels = audioread([foldername '/' list(i).name]); % read file
|
b@2
|
30 slaveAudio = sum(slaveAudioChannels, 2); % sum to mono
|
b@2
|
31
|
b@2
|
32 % check sampling rate is the same
|
b@2
|
33 % ...
|
b@2
|
34
|
b@2
|
35 % crosscorrelation function
|
b@2
|
36 xcorr(masterAudio, slaveAudio);
|
b@2
|
37
|
b@2
|
38 % add zeros to beginning
|
b@2
|
39
|
b@2
|
40 % monitoring/debugging
|
b@2
|
41
|
b@2
|
42 end
|
b@2
|
43
|
b@2
|
44 elapsedTime = toc; % stop measuring time
|
b@2
|
45 disp(['autoalign took ' elapsedTime ' seconds to align the files in folder ' ...
|
b@2
|
46 folderName ' with master file ' list(masterIndex).name]);
|
b@2
|
47
|
b@2
|
48 end |