changeset 6:ed0a8621b96a

prepare2listen small fixes, manual, standard target loudness (-23 dBLUFS)
author Brecht De Man <b.deman@qmul.ac.uk>
date Mon, 24 Nov 2014 16:55:55 +0000
parents 85bff3d1b6fe
children d113f0626fe3
files MANUAL.txt aux/autoalign.m aux/clipfade.m aux/loudnesstest.m aux/prepare2listen.m
diffstat 5 files changed, 63 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/MANUAL.txt	Sun Nov 23 23:24:35 2014 +0000
+++ b/MANUAL.txt	Mon Nov 24 16:55:55 2014 +0000
@@ -9,6 +9,17 @@
 >> close all force;
 in the console. 
 
+PREPARE AUDIO FILES FOR EVALUATION
+In ‘aux’, the function ‘prepare2listen(foldername)’ prepares audio files for listening tests, by calling the following functions (also in ‘aux’):
+batchresample(foldername, fs, bitdepth)		% ensure all files are on same fs/bit depth
+finddouble(foldername); 			% find unintentional doubles
+stripzeros(foldername); 			% strip subsequent zeros at the very beginning and end of a file
+autoalign(foldername); 				% automatically align audio files by measuring their crosscorrelation
+clipfade(foldername, starttime, endtime, fadetime, fs, bitdepth);
+						% clip desired fragment and fade in/out
+
+and by setting all files at the same loudness (measured by ‘getloudness’). 
+
 
 SESSION SCRIPTS, TEST CONFIGURATION AND SOUND LISTS
 To start session, type ‘launch’. 
--- a/aux/autoalign.m	Sun Nov 23 23:24:35 2014 +0000
+++ b/aux/autoalign.m	Mon Nov 24 16:55:55 2014 +0000
@@ -58,7 +58,7 @@
     maxlag = min(shiftvec); 
     for i = 1:length(list)
         [audio, fs] = audioread([foldername '/' list(i).name]);
-        audiowrite([foldername '/SHIFT' list(i).name], ... % remove SHIFT
+        audiowrite([foldername '/' list(i).name], ...
             [zeros(-maxlag + shiftvec(i), size(audio, 2)) ; audio], ...
             fs, 'BitsPerSample', 24);
     end
--- a/aux/clipfade.m	Sun Nov 23 23:24:35 2014 +0000
+++ b/aux/clipfade.m	Mon Nov 24 16:55:55 2014 +0000
@@ -9,7 +9,7 @@
 % by Brecht De Man at Centre for Digital Music on 25 October 2013
 
 if nargin < 6
-    bitDepth = 24;
+    bitdepth = 24;
 end
 slash    = '/';
 
@@ -26,23 +26,18 @@
 end
 
 for i = 1:length(list)
-    if strcmp(list(i).name, 'bounce.wav')
-        %disp(['     ' folder slash list(i).name]); % DEBUG 
-
-        [audio,fsfile] = audioread([folder slash list(i).name], [startTime*fs+1 endTime*fs]); % read part of file
+        [audio,fsfile] = audioread([folder slash list(i).name], [starttime*fs+1 endtime*fs]); % read part of file
         assert(fsfile == fs); % check file has expected sampling rate
 
-        Nfade = fadeTime*fs; % make fade vector (based on sampling rate)
-        fadeVector = [(1:Nfade)/Nfade ones(1,length(audio)-2*Nfade) (Nfade:-1:1)/Nfade];
+        Nfade = fadetime*fs; % make fade vector (based on sampling rate)
+        fadevector = [(1:Nfade)/Nfade ones(1,length(audio)-2*Nfade) (Nfade:-1:1)/Nfade];
 
         % apply fading and write to new folder
         if size(audio,2) == 2 % if stereo
             audiowrite([folder slash list(i).name], ... %[folder slash newFolder slash list(i).name]
-                [fadeVector'.*audio(:,1) fadeVector'.*audio(:,2)], fs, 'BitsPerSample', bitDepth);
+                [fadevector'.*audio(:,1) fadevector'.*audio(:,2)], fs, 'BitsPerSample', bitdepth);
         else % if mono
             audiowrite([folder slash list(i).name], ... %[folder slash newFolder slash list(i).name]
-                fadeVector'.*audio, fs, 'BitsPerSample', bitDepth);
+                fadevector'.*audio, fs, 'BitsPerSample', bitdepth);
         end
-    
-    end
 end
\ No newline at end of file
--- a/aux/loudnesstest.m	Sun Nov 23 23:24:35 2014 +0000
+++ b/aux/loudnesstest.m	Mon Nov 24 16:55:55 2014 +0000
@@ -1,8 +1,10 @@
 % test loudness mod
 
+tic; 
+
 % target loudness and test file
 target_loudness = -18;  % dBLU
-filename = '';
+filename = 'pro.wav';
 
 % import sound file
 [audio, fs] = audioread(filename); 
@@ -14,9 +16,12 @@
 % apply gain
 difference_loudness = target_loudness - initial_loudness;
 disp(['Difference in loudness: ' num2str(difference_loudness)]);
-audio = 10^(difference_loudness/10) .* audio;
-disp(['Gain: ' num2str(10^(difference_loudness/10))]);
+audio = 10^(difference_loudness/20) .* audio;
+disp(['Gain: ' num2str(10^(difference_loudness/20))]);
 
 % measure and display loudness (should be equal to target loudness)
 resulting_loudness = getloudness(audio, fs, 'ITU', 0);
-disp(['Resulting loudness: ' num2str(resulting_loudness)]);
\ No newline at end of file
+disp(['Resulting loudness: ' num2str(resulting_loudness)]);
+
+elapsed_time = toc;
+disp(['Elapsed time: ' num2str(elapsed_time)]);
\ No newline at end of file
--- a/aux/prepare2listen.m	Sun Nov 23 23:24:35 2014 +0000
+++ b/aux/prepare2listen.m	Mon Nov 24 16:55:55 2014 +0000
@@ -15,20 +15,23 @@
     newfolder   = 'fragments';
     fs          = 96000;    % Hz
     bitdepth    = 24; 
-    starttime   = 0;        % seconds
-    endtime     = 10;       % seconds
+    starttime   = 76;  % SR1 88;       % seconds
+    endtime     = 152; % SR1 142;      % seconds
     fadetime    = 1;        % seconds
-    format      = '.wav';
+    format      = 'wav';
     slash       = '/';
     
-    target_loudness    = -18;      % dBLU
+    target_loudness = -23;  % dBLU (https://tech.ebu.ch/loudness)
     
-    % get files
-    list = dir([foldername '/*.' format]);
+    tic;                                    % measure time
+    list = dir([foldername '/*.' format]);  % get files
     
     % remove hidden files from list, and copy to new folder
     % see http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/258220
-    newfoldername = [foldername slash newfolder];
+    newfoldername = [foldername slash newfolder]; % within original folder
+    if ~exist(newfoldername, 'dir')   % if it doesn't exist yet
+        mkdir(foldername, newfolder); % make newfolder within folder
+    end
     for k = length(list):-1:1
         fname = list(k).name;
         if fname(1) == '.'
@@ -40,30 +43,50 @@
     end
     
     % set at same sampling rate and bit depth
+    disp(['-- Ensuring audio is at ' num2str(fs) 'Hz / ' ...
+        num2str(bitdepth) ' bit...']);
     batchresample(newfoldername, fs, bitdepth); 
+    % NOTE: clipfade(...) also tests sampling rate, but does not resample
+    
+    % find doubles
+    disp('-- Checking for doubles...');
+    finddouble(newfoldername);
     
     % strip zeros off beginning and end
+    disp('-- Stripping off leading and trailing zeros...');
     stripzeros(newfoldername); 
     
-    % find doubles
-    finddouble(newfoldername); 
+    % align all audio files
+    disp('-- Aligning audio files...');
+    autoalign(newfoldername); 
     
     % clip and fade desired fragments
+    startmin = floor(starttime/60);
+    startsec = mod(starttime, 60);
+    endmin   = floor(endtime/60);
+    endsec   = mod(endtime, 60);
+    disp(['-- Fading in (' num2str(fadetime) 's) at ' num2str(startmin) ...
+        ':' num2str(startsec) ', fading out (' num2str(fadetime) 's) at '...
+        num2str(endmin) ':' num2str(endsec) '...']);
     clipfade(newfoldername, starttime, endtime, fadetime, fs, bitdepth); 
 
     % open files and calculate their loudness, then adjust
+    disp(['-- Setting each file at ' num2str(target_loudness) 'dBLU ...']);
     for i = 1:length(list)
         disp([newfoldername slash list(i).name]); % DEBUG
-        audio = audioread([newfoldername list(i).name]);
+        audio = audioread([newfoldername slash list(i).name]);
         initial_loudness   = getloudness( audio, fs, 'ITU', 0); 
         
         % calculate difference in loudness
         difference_loudness = target_loudness - initial_loudness; 
         
         % write back with adjusted loudness
+        newaudio = 10^(difference_loudness/20) .* audio;
         audiowrite([newfoldername slash list(i).name],...
-            10^(difference_loudness/10) .* audio, ...
-            fs, 'BitsPerSample', bitdepth);
+            newaudio, fs, 'BitsPerSample', bitdepth);
     end
-
+    
+    elapsed_time = toc;
+    disp(['prepare2listen took ' num2str(elapsed_time) ...
+        ' seconds on folder ' foldername]); 
 end
\ No newline at end of file