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@0
|
21 addpath(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@0
|
42
|
matthiasm@0
|
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
46
|
matthiasm@0
|
47 % read list of files to process
|
matthiasm@0
|
48 fid = fopen(filename_listOfFiles);
|
matthiasm@0
|
49 files=textscan(fid,'%s %s','delimiter',';');
|
matthiasm@0
|
50 fclose(fid);
|
matthiasm@0
|
51 numLines = length(files{1});
|
matthiasm@0
|
52 if length(files)>1 && (length(files{2}) < numLines)
|
matthiasm@0
|
53 files{2}{length(files{2})+1:numLines} = '';
|
matthiasm@0
|
54 end
|
matthiasm@0
|
55 files{1} = strtrim(files{1});
|
matthiasm@0
|
56 files{2} = strtrim(files{2});
|
matthiasm@0
|
57
|
matthiasm@0
|
58 % create outputDirectory if necessary
|
matthiasm@0
|
59 if ~exist(outputDirectory,'dir')
|
matthiasm@0
|
60 mkdir(outputDirectory);
|
matthiasm@0
|
61 end
|
matthiasm@0
|
62
|
matthiasm@0
|
63 % loop over files to process
|
matthiasm@0
|
64 parfor k=1:numLines % use this if you have the parallel computing toolbox
|
matthiasm@0
|
65 % for k=1:numLines
|
matthiasm@0
|
66 [path1,name1,ext1] = fileparts(files{1}{k});
|
matthiasm@0
|
67 [path2,name2,ext2] = fileparts(files{2}{k});
|
matthiasm@0
|
68
|
matthiasm@0
|
69 % check whether a wav and/or csv file is given
|
matthiasm@0
|
70 audiofilename = []; audiopath = []; csvfilename=[]; csvpath = [];
|
matthiasm@0
|
71 if strcmpi(ext1,'.csv')
|
matthiasm@0
|
72 csvpath = path1;
|
matthiasm@0
|
73 csvfilename = [name1,ext1];
|
matthiasm@0
|
74 elseif strcmpi(ext1,'.wav')
|
matthiasm@0
|
75 audiopath = path1;
|
matthiasm@0
|
76 audiofilename = [name1,ext1];
|
matthiasm@0
|
77 end
|
matthiasm@0
|
78 if strcmpi(ext2,'.csv')
|
matthiasm@0
|
79 csvpath = path2;
|
matthiasm@0
|
80 csvfilename = [name2,ext2];
|
matthiasm@0
|
81 elseif strcmpi(ext2,'.wav')
|
matthiasm@0
|
82 audiopath = path2;
|
matthiasm@0
|
83 audiofilename = [name2,ext2];
|
matthiasm@0
|
84 end
|
matthiasm@0
|
85
|
matthiasm@0
|
86 % Read audio and CSV data
|
matthiasm@0
|
87 f_audio = []; samplingFreq = []; nbits = [];
|
matthiasm@0
|
88 timepositions_beforeDegr = []; remainingColumns = [];
|
matthiasm@0
|
89 if ~isempty(audiofilename)
|
matthiasm@0
|
90 fprintf('Reading %s\n',audiofilename);
|
matthiasm@0
|
91 [f_audio,samplingFreq,nbits] = wavread(fullfile(audiopath,audiofilename));
|
matthiasm@0
|
92 end
|
matthiasm@0
|
93 if ~isempty(csvfilename)
|
matthiasm@0
|
94 fprintf('Reading %s\n',csvfilename);
|
matthiasm@0
|
95
|
matthiasm@0
|
96 fid = fopen(fullfile(csvpath,csvfilename));
|
matthiasm@0
|
97 linestring = fgetl(fid);
|
matthiasm@0
|
98 numberOfColumns = length(strfind(linestring,','))+1;
|
matthiasm@0
|
99 fclose(fid);
|
matthiasm@0
|
100
|
matthiasm@0
|
101 fid = fopen(fullfile(csvpath,csvfilename));
|
matthiasm@0
|
102 data = textscan(fid,['%f' repmat('%s', 1, numberOfColumns-1) '%*[^\n]'], 'delimiter', ',', 'collectoutput', true);
|
matthiasm@0
|
103 fclose(fid);
|
matthiasm@0
|
104
|
matthiasm@0
|
105 timepositions_beforeDegr = data{1};
|
matthiasm@0
|
106 remainingColumns = data{2};
|
matthiasm@0
|
107 end
|
matthiasm@0
|
108
|
matthiasm@0
|
109 % Start the degradation process
|
matthiasm@0
|
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
111 degradationname = 'liveRecording';
|
matthiasm@0
|
112 PathToOutput = fullfile(outputDirectory,degradationname);
|
matthiasm@0
|
113 if ~exist(PathToOutput,'dir') mkdir(PathToOutput); end
|
matthiasm@0
|
114 [f_audio_out,timepositions_afterDegr] = applyDegradation(degradationname, f_audio, samplingFreq, timepositions_beforeDegr);
|
matthiasm@0
|
115
|
matthiasm@0
|
116 if ~isempty(audiofilename)
|
matthiasm@0
|
117 wavwrite(f_audio_out,samplingFreq,nbits,fullfile(PathToOutput,audiofilename));
|
matthiasm@0
|
118 end
|
matthiasm@0
|
119 if ~isempty(csvfilename)
|
matthiasm@0
|
120 writeCsvFile(fullfile(PathToOutput,csvfilename),timepositions_afterDegr,remainingColumns);
|
matthiasm@0
|
121 end
|
matthiasm@0
|
122
|
matthiasm@0
|
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
124 degradationname = 'strongMp3Compression';
|
matthiasm@0
|
125 PathToOutput = fullfile(outputDirectory,degradationname);
|
matthiasm@0
|
126 if ~exist(PathToOutput,'dir') mkdir(PathToOutput); end
|
matthiasm@0
|
127 [f_audio_out,timepositions_afterDegr] = applyDegradation(degradationname, f_audio, samplingFreq, timepositions_beforeDegr);
|
matthiasm@0
|
128
|
matthiasm@0
|
129 if ~isempty(audiofilename)
|
matthiasm@0
|
130 wavwrite(f_audio_out,samplingFreq,nbits,fullfile(PathToOutput,audiofilename));
|
matthiasm@0
|
131 end
|
matthiasm@0
|
132 if ~isempty(csvfilename)
|
matthiasm@0
|
133 writeCsvFile(fullfile(PathToOutput,csvfilename),timepositions_afterDegr,remainingColumns);
|
matthiasm@0
|
134 end
|
matthiasm@0
|
135
|
matthiasm@0
|
136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
137 degradationname = 'vinylRecording';
|
matthiasm@0
|
138 PathToOutput = fullfile(outputDirectory,degradationname);
|
matthiasm@0
|
139 if ~exist(PathToOutput,'dir') mkdir(PathToOutput); end
|
matthiasm@0
|
140 [f_audio_out,timepositions_afterDegr] = applyDegradation(degradationname, f_audio, samplingFreq, timepositions_beforeDegr);
|
matthiasm@0
|
141
|
matthiasm@0
|
142 if ~isempty(audiofilename)
|
matthiasm@0
|
143 wavwrite(f_audio_out,samplingFreq,nbits,fullfile(PathToOutput,audiofilename));
|
matthiasm@0
|
144 end
|
matthiasm@0
|
145 if ~isempty(csvfilename)
|
matthiasm@0
|
146 writeCsvFile(fullfile(PathToOutput,csvfilename),timepositions_afterDegr,remainingColumns);
|
matthiasm@0
|
147 end
|
matthiasm@0
|
148
|
matthiasm@0
|
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
150 degradationname = 'radioBroadcast';
|
matthiasm@0
|
151 PathToOutput = fullfile(outputDirectory,degradationname);
|
matthiasm@0
|
152 if ~exist(PathToOutput,'dir') mkdir(PathToOutput); end
|
matthiasm@0
|
153 [f_audio_out,timepositions_afterDegr] = applyDegradation(degradationname, f_audio, samplingFreq, timepositions_beforeDegr);
|
matthiasm@0
|
154
|
matthiasm@0
|
155 if ~isempty(audiofilename)
|
matthiasm@0
|
156 wavwrite(f_audio_out,samplingFreq,nbits,fullfile(PathToOutput,audiofilename));
|
matthiasm@0
|
157 end
|
matthiasm@0
|
158 if ~isempty(csvfilename)
|
matthiasm@0
|
159 writeCsvFile(fullfile(PathToOutput,csvfilename),timepositions_afterDegr,remainingColumns);
|
matthiasm@0
|
160 end
|
matthiasm@0
|
161
|
matthiasm@0
|
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
163 degradationname = 'smartPhoneRecording';
|
matthiasm@0
|
164 PathToOutput = fullfile(outputDirectory,degradationname);
|
matthiasm@0
|
165 if ~exist(PathToOutput,'dir') mkdir(PathToOutput); end
|
matthiasm@0
|
166 [f_audio_out,timepositions_afterDegr] = applyDegradation(degradationname, f_audio, samplingFreq, timepositions_beforeDegr);
|
matthiasm@0
|
167
|
matthiasm@0
|
168 if ~isempty(audiofilename)
|
matthiasm@0
|
169 wavwrite(f_audio_out,samplingFreq,nbits,fullfile(PathToOutput,audiofilename));
|
matthiasm@0
|
170 end
|
matthiasm@0
|
171 if ~isempty(csvfilename)
|
matthiasm@0
|
172 writeCsvFile(fullfile(PathToOutput,csvfilename),timepositions_afterDegr,remainingColumns);
|
matthiasm@0
|
173 end
|
matthiasm@0
|
174
|
matthiasm@0
|
175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
176 degradationname = 'smartPhonePlayback';
|
matthiasm@0
|
177 PathToOutput = fullfile(outputDirectory,degradationname);
|
matthiasm@0
|
178 if ~exist(PathToOutput,'dir') mkdir(PathToOutput); end
|
matthiasm@0
|
179 [f_audio_out,timepositions_afterDegr] = applyDegradation(degradationname, f_audio, samplingFreq, timepositions_beforeDegr);
|
matthiasm@0
|
180
|
matthiasm@0
|
181 if ~isempty(audiofilename)
|
matthiasm@0
|
182 wavwrite(f_audio_out,samplingFreq,nbits,fullfile(PathToOutput,audiofilename));
|
matthiasm@0
|
183 end
|
matthiasm@0
|
184 if ~isempty(csvfilename)
|
matthiasm@0
|
185 writeCsvFile(fullfile(PathToOutput,csvfilename),timepositions_afterDegr,remainingColumns);
|
matthiasm@0
|
186 end
|
matthiasm@0
|
187
|
matthiasm@0
|
188 end
|
matthiasm@0
|
189
|
matthiasm@0
|
190 end
|
matthiasm@0
|
191
|
matthiasm@0
|
192
|
matthiasm@0
|
193 function writeCsvFile(filename, cols_numeric, remainingColsCell)
|
matthiasm@0
|
194
|
matthiasm@0
|
195 numberOfAdditionalColumns = size(remainingColsCell,2);
|
matthiasm@0
|
196
|
matthiasm@0
|
197 fid = fopen(filename,'w');
|
matthiasm@0
|
198 for m=1:size(cols_numeric,1)
|
matthiasm@0
|
199 fprintf(fid,'%f',cols_numeric(m,1));
|
matthiasm@0
|
200 for n=2:size(cols_numeric,2)
|
matthiasm@0
|
201 fprintf(fid,' %f',cols_numeric(m,n));
|
matthiasm@0
|
202 end
|
matthiasm@0
|
203 for n=1:numberOfAdditionalColumns
|
matthiasm@0
|
204 fprintf(fid,' %s',remainingColsCell{m,n});
|
matthiasm@0
|
205 end
|
matthiasm@0
|
206 fprintf(fid,'\n');
|
matthiasm@0
|
207 end
|
matthiasm@0
|
208 fclose(fid);
|
matthiasm@0
|
209
|
matthiasm@0
|
210 end
|
matthiasm@0
|
211
|
matthiasm@0
|
212
|