matthiasm@0
|
1 function demo_batchProcessing()
|
matthiasm@0
|
2
|
matthiasm@0
|
3 % This is an example script to process a whole dataset using the Audio
|
matthiasm@0
|
4 % Degradation Toolbox including code to translate given ground truth
|
matthiasm@0
|
5 % annotations.
|
matthiasm@0
|
6
|
matthiasm@0
|
7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
8 % Audio Degradation Toolbox
|
matthiasm@0
|
9 %
|
matthiasm@0
|
10 % Centre for Digital Music, Queen Mary University of London.
|
matthiasm@0
|
11 % This file copyright 2013 Sebastian Ewert, Matthias Mauch and QMUL.
|
matthiasm@0
|
12 %
|
matthiasm@0
|
13 % This program is free software; you can redistribute it and/or
|
matthiasm@0
|
14 % modify it under the terms of the GNU General Public License as
|
matthiasm@0
|
15 % published by the Free Software Foundation; either version 2 of the
|
matthiasm@0
|
16 % License, or (at your option) any later version. See the file
|
matthiasm@0
|
17 % COPYING included with this distribution for more information.
|
matthiasm@0
|
18 %
|
matthiasm@0
|
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
20
|
matthiasm@13
|
21 addpath(genpath(fullfile(pwd,'AudioDegradationToolbox')));
|
matthiasm@0
|
22
|
matthiasm@0
|
23 % the following file should list all the files to process. Every line
|
matthiasm@0
|
24 % should specify one audio file, one audio file and a ground truth file in
|
matthiasm@0
|
25 % CSV format, or just the ground truth file. This example scripts treats
|
matthiasm@0
|
26 % the first column of a CSV file as time information that needs to be
|
matthiasm@0
|
27 % adjusted. If this is not correct, the script needs to be adapted.
|
matthiasm@0
|
28 filename_listOfFiles = 'listOfFiles.txt';
|
matthiasm@0
|
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
30 % 1 testdata/472TNA3M_snippet.wav
|
matthiasm@0
|
31 % 2 testdata/clarinet.wav
|
matthiasm@0
|
32 % 3 testdata/p009m_drum.wav
|
matthiasm@0
|
33 % 4 testdata/RWC-C08.wav ; testdata/RWC-C08.csv
|
matthiasm@0
|
34 % 5 testdata/p009m_drum.csv
|
matthiasm@0
|
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
36 % line 1-3: just process audio, line 4: process audio and ground truth data
|
matthiasm@0
|
37 % at the same time, line 5: process only ground truth data
|
matthiasm@0
|
38
|
matthiasm@0
|
39 % destination directory
|
matthiasm@0
|
40 outputDirectory = 'demoOutput/';
|
matthiasm@0
|
41
|
matthiasm@13
|
42 % desired degradations
|
matthiasm@13
|
43 degradationnames = {'liveRecording', ...
|
matthiasm@13
|
44 'pubEnvironment', ...
|
matthiasm@13
|
45 'radioBroadcast', ...
|
matthiasm@13
|
46 'smartPhonePlayback', ...
|
matthiasm@13
|
47 'smartPhoneRecording', ...
|
matthiasm@13
|
48 'strongMp3Compression', ...
|
matthiasm@13
|
49 'vinylRecording', ...
|
matthiasm@14
|
50 'unit_addNoise', ...
|
matthiasm@13
|
51 'unit_addSound', ...
|
matthiasm@14
|
52 'unit_applyAliasing', ...
|
matthiasm@14
|
53 'unit_applyClippingAlternative', ...
|
matthiasm@14
|
54 'unit_applyHarmonicDistortion'};
|
matthiasm@13
|
55 nDegradation = length(degradationnames);
|
matthiasm@0
|
56
|
matthiasm@0
|
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
60
|
matthiasm@0
|
61 % read list of files to process
|
matthiasm@0
|
62 fid = fopen(filename_listOfFiles);
|
matthiasm@0
|
63 files=textscan(fid,'%s %s','delimiter',';');
|
matthiasm@0
|
64 fclose(fid);
|
matthiasm@0
|
65 numLines = length(files{1});
|
matthiasm@0
|
66 if length(files)>1 && (length(files{2}) < numLines)
|
matthiasm@0
|
67 files{2}{length(files{2})+1:numLines} = '';
|
matthiasm@0
|
68 end
|
matthiasm@0
|
69 files{1} = strtrim(files{1});
|
matthiasm@0
|
70 files{2} = strtrim(files{2});
|
matthiasm@0
|
71
|
matthiasm@0
|
72 % create outputDirectory if necessary
|
matthiasm@0
|
73 if ~exist(outputDirectory,'dir')
|
matthiasm@0
|
74 mkdir(outputDirectory);
|
matthiasm@0
|
75 end
|
matthiasm@0
|
76
|
matthiasm@0
|
77 % loop over files to process
|
matthiasm@0
|
78 parfor k=1:numLines % use this if you have the parallel computing toolbox
|
matthiasm@0
|
79 % for k=1:numLines
|
matthiasm@0
|
80 [path1,name1,ext1] = fileparts(files{1}{k});
|
matthiasm@0
|
81 [path2,name2,ext2] = fileparts(files{2}{k});
|
matthiasm@0
|
82
|
matthiasm@0
|
83 % check whether a wav and/or csv file is given
|
matthiasm@0
|
84 audiofilename = []; audiopath = []; csvfilename=[]; csvpath = [];
|
matthiasm@0
|
85 if strcmpi(ext1,'.csv')
|
matthiasm@0
|
86 csvpath = path1;
|
matthiasm@0
|
87 csvfilename = [name1,ext1];
|
matthiasm@0
|
88 elseif strcmpi(ext1,'.wav')
|
matthiasm@0
|
89 audiopath = path1;
|
matthiasm@0
|
90 audiofilename = [name1,ext1];
|
matthiasm@0
|
91 end
|
matthiasm@0
|
92 if strcmpi(ext2,'.csv')
|
matthiasm@0
|
93 csvpath = path2;
|
matthiasm@0
|
94 csvfilename = [name2,ext2];
|
matthiasm@0
|
95 elseif strcmpi(ext2,'.wav')
|
matthiasm@0
|
96 audiopath = path2;
|
matthiasm@0
|
97 audiofilename = [name2,ext2];
|
matthiasm@0
|
98 end
|
matthiasm@0
|
99
|
matthiasm@0
|
100 % Read audio and CSV data
|
matthiasm@0
|
101 f_audio = []; samplingFreq = []; nbits = [];
|
matthiasm@0
|
102 timepositions_beforeDegr = []; remainingColumns = [];
|
matthiasm@0
|
103 if ~isempty(audiofilename)
|
matthiasm@0
|
104 fprintf('Reading %s\n',audiofilename);
|
matthiasm@0
|
105 [f_audio,samplingFreq,nbits] = wavread(fullfile(audiopath,audiofilename));
|
matthiasm@0
|
106 end
|
matthiasm@0
|
107 if ~isempty(csvfilename)
|
matthiasm@0
|
108 fprintf('Reading %s\n',csvfilename);
|
matthiasm@0
|
109
|
matthiasm@0
|
110 fid = fopen(fullfile(csvpath,csvfilename));
|
matthiasm@0
|
111 linestring = fgetl(fid);
|
matthiasm@0
|
112 numberOfColumns = length(strfind(linestring,','))+1;
|
matthiasm@0
|
113 fclose(fid);
|
matthiasm@0
|
114
|
matthiasm@0
|
115 fid = fopen(fullfile(csvpath,csvfilename));
|
matthiasm@0
|
116 data = textscan(fid,['%f' repmat('%s', 1, numberOfColumns-1) '%*[^\n]'], 'delimiter', ',', 'collectoutput', true);
|
matthiasm@0
|
117 fclose(fid);
|
matthiasm@0
|
118
|
matthiasm@0
|
119 timepositions_beforeDegr = data{1};
|
matthiasm@0
|
120 remainingColumns = data{2};
|
matthiasm@0
|
121 end
|
matthiasm@0
|
122
|
matthiasm@13
|
123 % apply degradations
|
matthiasm@0
|
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@13
|
125 for iDegradation = 1:nDegradation
|
matthiasm@13
|
126 degradationname = degradationnames{iDegradation};
|
matthiasm@13
|
127 PathToOutput = fullfile(outputDirectory,degradationname);
|
matthiasm@13
|
128 if ~exist(PathToOutput,'dir') mkdir(PathToOutput); end
|
matthiasm@13
|
129 [f_audio_out,timepositions_afterDegr] = applyDegradation(degradationname, f_audio, samplingFreq, timepositions_beforeDegr);
|
matthiasm@13
|
130
|
matthiasm@13
|
131 if ~isempty(audiofilename)
|
matthiasm@13
|
132 wavwrite(f_audio_out,samplingFreq,nbits,fullfile(PathToOutput,audiofilename));
|
matthiasm@13
|
133 end
|
matthiasm@13
|
134 if ~isempty(csvfilename)
|
matthiasm@13
|
135 writeCsvFile(fullfile(PathToOutput,csvfilename),timepositions_afterDegr,remainingColumns);
|
matthiasm@13
|
136 end
|
matthiasm@0
|
137 end
|
matthiasm@0
|
138 end
|
matthiasm@0
|
139
|
matthiasm@0
|
140 end
|
matthiasm@0
|
141
|
matthiasm@0
|
142
|
matthiasm@0
|
143 function writeCsvFile(filename, cols_numeric, remainingColsCell)
|
matthiasm@0
|
144
|
matthiasm@0
|
145 numberOfAdditionalColumns = size(remainingColsCell,2);
|
matthiasm@0
|
146
|
matthiasm@0
|
147 fid = fopen(filename,'w');
|
matthiasm@0
|
148 for m=1:size(cols_numeric,1)
|
matthiasm@0
|
149 fprintf(fid,'%f',cols_numeric(m,1));
|
matthiasm@0
|
150 for n=2:size(cols_numeric,2)
|
matthiasm@0
|
151 fprintf(fid,' %f',cols_numeric(m,n));
|
matthiasm@0
|
152 end
|
matthiasm@0
|
153 for n=1:numberOfAdditionalColumns
|
matthiasm@0
|
154 fprintf(fid,' %s',remainingColsCell{m,n});
|
matthiasm@0
|
155 end
|
matthiasm@0
|
156 fprintf(fid,'\n');
|
matthiasm@0
|
157 end
|
matthiasm@0
|
158 fclose(fid);
|
matthiasm@0
|
159
|
matthiasm@0
|
160 end
|
matthiasm@0
|
161
|
matthiasm@0
|
162
|