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