Mercurial > hg > ape
changeset 4:b28ffd29e6e1
Audio file preparation for listening test
author | Brecht De Man <b.deman@qmul.ac.uk> |
---|---|
date | Wed, 19 Nov 2014 18:59:51 +0000 |
parents | 1f7b986dab05 |
children | 85bff3d1b6fe |
files | aux/clipfade.m aux/finddouble.m aux/getLoudness.m aux/prepare2listen.m |
diffstat | 4 files changed, 100 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/aux/clipfade.m Mon Nov 17 23:01:09 2014 +0000 +++ b/aux/clipfade.m Wed Nov 19 18:59:51 2014 +0000 @@ -1,4 +1,4 @@ -function clipfade(folder, startTime, endTime, fs) +function clipfade(folder, starttime, endtime, fadetime, fs, bitdepth) % CLIPFADE clips and fades a fragment [start end] of all audio files in % a folder. % @@ -8,24 +8,22 @@ % % by Brecht De Man at Centre for Digital Music on 25 October 2013 -if nargin < 4 - fs = 96000; +if nargin < 6 + bitDepth = 24; end - -fadeTime = 1; % fade time in seconds -bitDepth = 16; -slash = '/'; % depending on OS - -%newFolder = 'Clips'; % folder where output files will be stored -% MODIFICATION: store in place, do not keep unclipped files! +slash = '/'; % list all audio files list = dir([folder slash '*.wav']); -% make new folder if not present yet -% if ~exist([folder slash newFolder], 'dir') % make output folder if not there -% mkdir(folder, newFolder); -% end +% 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 for i = 1:length(list) if strcmp(list(i).name, 'bounce.wav')
--- a/aux/finddouble.m Mon Nov 17 23:01:09 2014 +0000 +++ b/aux/finddouble.m Wed Nov 19 18:59:51 2014 +0000 @@ -4,11 +4,21 @@ % by Brecht De Man at Centre for Digital Music on 15 July 2013 -list = dir([foldername '\*.wav']); % find wav file names in folder -sums = zeros(length(list)); % array for every file (don't count '.') +list = dir([foldername '/*.wav']); % find wav file names in folder + +% 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 + +sums = zeros(length(list)); % number for every file for i = 1:length(list) - audio = audioread([foldername '\' list(i).name]); + audio = audioread([foldername '/' list(i).name]); sums(i) = sum(sum(audio.^2)); end
--- a/aux/getLoudness.m Mon Nov 17 23:01:09 2014 +0000 +++ b/aux/getLoudness.m Wed Nov 19 18:59:51 2014 +0000 @@ -1,4 +1,4 @@ -function result = getLoudness( vector, Fs, timescale, plotBOOL ) +function result = getloudness( vector, Fs, timescale, plotBOOL ) %GETLOUDNESS returns loudness levels according to EBU R 128 specification % Function getLoudness accepts an audio file vector (vector), a sampling % rate (Fs), a timescale ('M' - Momentary, 'S' - Short, 'I' - Integrated) @@ -29,7 +29,7 @@ rlbAcoeffs = [1, -1.98992552008493, 0.989976013945421]; % loudness prefilter function below this one (see Pestana 2013) - [prefilterBcoeffs, prefilterAcoeffs] = getLoudnessPreFilter(10, Fs); + [prefilterBcoeffs, prefilterAcoeffs] = getloudnessprefilter(10, Fs); % Weighting coefficients with channel format [L, R, C, Ls, Rs] @@ -229,7 +229,7 @@ -function [prefilterBcoeffs, prefilterAcoeffs] = getLoudnessPreFilter(gainIndB, fs) +function [prefilterBcoeffs, prefilterAcoeffs] = getloudnessprefilter(gainIndB, fs) % GET LOUDNESS calculates coefficients for prefilter with arbitrary gain as % specified in EBU R 128 and the modification proposed in Pestana 2013. %
--- a/aux/prepare2listen.m Mon Nov 17 23:01:09 2014 +0000 +++ b/aux/prepare2listen.m Wed Nov 19 18:59:51 2014 +0000 @@ -1,40 +1,81 @@ -function prepare2listen -% PREPARE2LISTEN equalises loudness of files to prepare for -% listening test. +function prepare2listen(foldername) +% PREPARE2LISTEN batch processes all audio files in a folder to prepare for +% a listening test, by +% - making sure everything is at the same sampling rate and bit depth; +% - removing subsequent zeros at the start and the end; +% - ensuring none of the files are equal to each other; +% - clipping the desired region from the file; +% - adding a fade in and fade out; and +% - setting the loudness at a predefined value. +% It then saves the result in a folder within the audio folder. % % by Brecht De Man at Centre for Digital Music, 5 June 2013 -folder = '/Users/Brecht/Documents/MATLAB/McGillTest2014/listeningTest/AUDIO/SR2_UnderACoveredSky/Clips/'; -newfolder = 'equalloudness'; -list = dir([folder '/*.wav']); -slash = '/'; + % PARAMETERS + newfolder = 'fragments'; + fs = 96000; % Hz + bitdepth = 24; + starttime = 0; % seconds + endtime = 10; % seconds + fadetime = 1; % seconds + loudness = -18; % dBLU + format = '.wav'; + slash = '/'; + + % get files + list = dir([foldername '/*.' format]); + + % 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]; + for k = length(list):-1:1 + fname = list(k).name; + if fname(1) == '.' + list(k) = []; + else + copyfile([foldername slash list(k).name], ... + [newfoldername slash list(k).name]); + end + end + + % set at same sampling rate and bit depth + batchresample(newfoldername, fs, bitdepth); + + % strip zeros off beginning and end + stripzeros(newfoldername); + + % find doubles + finddouble(newfoldername); + + % clip and fade desired fragments + clipfade(folder, starttime, endtime, fadetime, fs, bitdepth); -% open files and calculate minimum loudness -MIN = 0; -x = struct([]); -for i = 1:length(list) - disp([folder newfolder slash list(i).name]); % DEBUG - [x{i}.audio,fs] = audioread([folder list(i).name]); - x{i}.loudness = loudness_itu(x{i}.audio, fs); - MIN = min(MIN, floor(x{i}.loudness)); % compute minimum loudness -end + % open files and calculate minimum loudness + MIN = 0; + x = struct([]); + for i = 1:length(list) + disp([foldername newfolder slash list(i).name]); % DEBUG + [x{i}.audio,fs] = audioread([foldername list(i).name]); + x{i}.loudness = loudness_itu(x{i}.audio, fs); + MIN = min(MIN, floor(x{i}.loudness)); % compute minimum loudness + end -% make folder -if ~exist([folder 'equalloudness'], 'dir') % make folder 'equalloudness' if not there - mkdir(folder, 'equalloudness'); -end + % make folder inside audio file folder + if ~exist([foldername newfolder], 'dir') % make new folder if not there + mkdir(foldername, newfolder); + end -% equalise loudness -MAX = 0; -for i = 1:length(list) - x{i}.equalised = loudness_match(x{i}.audio, fs, MIN)*x{i}.audio; - MAX = max(MAX, max(max(abs(x{i}.equalised)))); -end + % equalise loudness + MAX = 0; + for i = 1:length(list) + x{i}.equalised = loudness_match(x{i}.audio, fs, MIN)*x{i}.audio; + MAX = max(MAX, max(max(abs(x{i}.equalised)))); + end -% normalise (keeping relative loudness) and save -for i = 1:length(list) - audiowrite([folder newfolder '\' list(i).name], x{i}.equalised/MAX, ... - fs, 'BitsPerSample', 24); -end + % normalise (keeping relative loudness) and save + for i = 1:length(list) + audiowrite([foldername newfolder slash list(i).name], x{i}.equalised/MAX, ... + fs, 'BitsPerSample', 24); + end end \ No newline at end of file