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 'radioBroadcast', ...
|
matthiasm@13
|
45 'smartPhonePlayback', ...
|
matthiasm@13
|
46 'smartPhoneRecording', ...
|
matthiasm@13
|
47 'strongMp3Compression', ...
|
matthiasm@13
|
48 'vinylRecording', ...
|
matthiasm@14
|
49 'unit_addNoise', ...
|
matthiasm@13
|
50 'unit_addSound', ...
|
matthiasm@14
|
51 'unit_applyAliasing', ...
|
matthiasm@14
|
52 'unit_applyClippingAlternative', ...
|
matthiasm@15
|
53 'unit_applyHarmonicDistortion', ...
|
matthiasm@15
|
54 'unit_applyMp3Compression', ...
|
matthiasm@18
|
55 'unit_applySpeedup', ...
|
matthiasm@18
|
56 'unit_applyWowResampling',...
|
matthiasm@20
|
57 'unit_applyDelay', ...
|
matthiasm@20
|
58 'unit_applyHighpassFilter', ...
|
matthiasm@20
|
59 'unit_applyLowpassFilter'};
|
matthiasm@13
|
60 nDegradation = length(degradationnames);
|
matthiasm@0
|
61
|
matthiasm@0
|
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@0
|
65
|
matthiasm@0
|
66 % read list of files to process
|
matthiasm@0
|
67 fid = fopen(filename_listOfFiles);
|
matthiasm@0
|
68 files=textscan(fid,'%s %s','delimiter',';');
|
matthiasm@0
|
69 fclose(fid);
|
matthiasm@0
|
70 numLines = length(files{1});
|
matthiasm@0
|
71 if length(files)>1 && (length(files{2}) < numLines)
|
matthiasm@0
|
72 files{2}{length(files{2})+1:numLines} = '';
|
matthiasm@0
|
73 end
|
matthiasm@0
|
74 files{1} = strtrim(files{1});
|
matthiasm@0
|
75 files{2} = strtrim(files{2});
|
matthiasm@0
|
76
|
matthiasm@0
|
77 % create outputDirectory if necessary
|
matthiasm@0
|
78 if ~exist(outputDirectory,'dir')
|
matthiasm@0
|
79 mkdir(outputDirectory);
|
matthiasm@0
|
80 end
|
matthiasm@0
|
81
|
matthiasm@0
|
82 % loop over files to process
|
matthiasm@0
|
83 parfor k=1:numLines % use this if you have the parallel computing toolbox
|
matthiasm@0
|
84 % for k=1:numLines
|
matthiasm@0
|
85 [path1,name1,ext1] = fileparts(files{1}{k});
|
matthiasm@0
|
86 [path2,name2,ext2] = fileparts(files{2}{k});
|
matthiasm@0
|
87
|
matthiasm@0
|
88 % check whether a wav and/or csv file is given
|
matthiasm@0
|
89 audiofilename = []; audiopath = []; csvfilename=[]; csvpath = [];
|
matthiasm@0
|
90 if strcmpi(ext1,'.csv')
|
matthiasm@0
|
91 csvpath = path1;
|
matthiasm@0
|
92 csvfilename = [name1,ext1];
|
matthiasm@0
|
93 elseif strcmpi(ext1,'.wav')
|
matthiasm@0
|
94 audiopath = path1;
|
matthiasm@0
|
95 audiofilename = [name1,ext1];
|
matthiasm@0
|
96 end
|
matthiasm@0
|
97 if strcmpi(ext2,'.csv')
|
matthiasm@0
|
98 csvpath = path2;
|
matthiasm@0
|
99 csvfilename = [name2,ext2];
|
matthiasm@0
|
100 elseif strcmpi(ext2,'.wav')
|
matthiasm@0
|
101 audiopath = path2;
|
matthiasm@0
|
102 audiofilename = [name2,ext2];
|
matthiasm@0
|
103 end
|
matthiasm@0
|
104
|
matthiasm@0
|
105 % Read audio and CSV data
|
matthiasm@0
|
106 f_audio = []; samplingFreq = []; nbits = [];
|
matthiasm@0
|
107 timepositions_beforeDegr = []; remainingColumns = [];
|
matthiasm@0
|
108 if ~isempty(audiofilename)
|
matthiasm@0
|
109 fprintf('Reading %s\n',audiofilename);
|
matthiasm@0
|
110 [f_audio,samplingFreq,nbits] = wavread(fullfile(audiopath,audiofilename));
|
matthiasm@0
|
111 end
|
matthiasm@0
|
112 if ~isempty(csvfilename)
|
matthiasm@0
|
113 fprintf('Reading %s\n',csvfilename);
|
matthiasm@0
|
114
|
matthiasm@0
|
115 fid = fopen(fullfile(csvpath,csvfilename));
|
matthiasm@0
|
116 linestring = fgetl(fid);
|
matthiasm@0
|
117 numberOfColumns = length(strfind(linestring,','))+1;
|
matthiasm@0
|
118 fclose(fid);
|
matthiasm@0
|
119
|
matthiasm@0
|
120 fid = fopen(fullfile(csvpath,csvfilename));
|
matthiasm@0
|
121 data = textscan(fid,['%f' repmat('%s', 1, numberOfColumns-1) '%*[^\n]'], 'delimiter', ',', 'collectoutput', true);
|
matthiasm@0
|
122 fclose(fid);
|
matthiasm@0
|
123
|
matthiasm@0
|
124 timepositions_beforeDegr = data{1};
|
matthiasm@0
|
125 remainingColumns = data{2};
|
matthiasm@0
|
126 end
|
matthiasm@0
|
127
|
matthiasm@13
|
128 % apply degradations
|
matthiasm@0
|
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
matthiasm@13
|
130 for iDegradation = 1:nDegradation
|
matthiasm@13
|
131 degradationname = degradationnames{iDegradation};
|
matthiasm@13
|
132 PathToOutput = fullfile(outputDirectory,degradationname);
|
matthiasm@13
|
133 if ~exist(PathToOutput,'dir') mkdir(PathToOutput); end
|
matthiasm@13
|
134 [f_audio_out,timepositions_afterDegr] = applyDegradation(degradationname, f_audio, samplingFreq, timepositions_beforeDegr);
|
matthiasm@13
|
135
|
matthiasm@13
|
136 if ~isempty(audiofilename)
|
matthiasm@13
|
137 wavwrite(f_audio_out,samplingFreq,nbits,fullfile(PathToOutput,audiofilename));
|
matthiasm@13
|
138 end
|
matthiasm@13
|
139 if ~isempty(csvfilename)
|
matthiasm@13
|
140 writeCsvFile(fullfile(PathToOutput,csvfilename),timepositions_afterDegr,remainingColumns);
|
matthiasm@13
|
141 end
|
matthiasm@0
|
142 end
|
matthiasm@0
|
143 end
|
matthiasm@0
|
144
|
matthiasm@0
|
145 end
|
matthiasm@0
|
146
|
matthiasm@0
|
147
|