diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aux/autoalign.m	Mon Nov 17 19:43:43 2014 +0000
@@ -0,0 +1,48 @@
+function autoalign(folderName, masterIndex)
+% AUTOALIGN aligns audio in folder with selected file (index 'masterIndex')
+% by inserting zeros at the start of the other files. 
+%
+% by Brecht De Man at Centre for Digital Music on 17 November 2014
+
+    error('Work in progress, function not finished');
+    
+    tic;                                % start measuring time
+    list = dir([foldername '\*.wav']);  % get names of files
+    
+    % 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
+
+    % load master file
+    masterAudioChannels = audioread([foldername '/' list(masterIndex).name]); 
+    masterAudio         = sum(masterAudioChannels, 2); % sum to mono
+    disp(['Aligning audio files with ' list(masterIndex).name '...']);
+    
+    % for each other file:
+    for i = 1:length(list)
+        
+        slaveAudioChannels = audioread([foldername '/' list(i).name]); % read file
+        slaveAudio         = sum(slaveAudioChannels, 2); % sum to mono
+        
+        % check sampling rate is the same
+        % ... 
+
+        % crosscorrelation function
+        xcorr(masterAudio, slaveAudio); 
+        
+        % add zeros to beginning 
+        
+        % monitoring/debugging
+        
+    end
+
+    elapsedTime = toc;  % stop measuring time
+    disp(['autoalign took ' elapsedTime ' seconds to align the files in folder ' ...
+        folderName ' with master file ' list(masterIndex).name]);
+
+end
\ No newline at end of file