matthiasm@0: function demo_batchProcessing() matthiasm@0: matthiasm@0: % This is an example script to process a whole dataset using the Audio matthiasm@0: % Degradation Toolbox including code to translate given ground truth matthiasm@0: % annotations. matthiasm@0: matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: % Audio Degradation Toolbox matthiasm@0: % matthiasm@0: % Centre for Digital Music, Queen Mary University of London. matthiasm@0: % This file copyright 2013 Sebastian Ewert, Matthias Mauch and QMUL. matthiasm@0: % matthiasm@0: % This program is free software; you can redistribute it and/or matthiasm@0: % modify it under the terms of the GNU General Public License as matthiasm@0: % published by the Free Software Foundation; either version 2 of the matthiasm@0: % License, or (at your option) any later version. See the file matthiasm@0: % COPYING included with this distribution for more information. matthiasm@0: % matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: matthiasm@13: addpath(genpath(fullfile(pwd,'AudioDegradationToolbox'))); matthiasm@0: matthiasm@0: % the following file should list all the files to process. Every line matthiasm@0: % should specify one audio file, one audio file and a ground truth file in matthiasm@0: % CSV format, or just the ground truth file. This example scripts treats matthiasm@0: % the first column of a CSV file as time information that needs to be matthiasm@0: % adjusted. If this is not correct, the script needs to be adapted. matthiasm@0: filename_listOfFiles = 'listOfFiles.txt'; matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: % 1 testdata/472TNA3M_snippet.wav matthiasm@0: % 2 testdata/clarinet.wav matthiasm@0: % 3 testdata/p009m_drum.wav matthiasm@0: % 4 testdata/RWC-C08.wav ; testdata/RWC-C08.csv matthiasm@0: % 5 testdata/p009m_drum.csv matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: % line 1-3: just process audio, line 4: process audio and ground truth data matthiasm@0: % at the same time, line 5: process only ground truth data matthiasm@0: matthiasm@0: % destination directory matthiasm@0: outputDirectory = 'demoOutput/'; matthiasm@0: matthiasm@13: % desired degradations matthiasm@13: degradationnames = {'liveRecording', ... matthiasm@13: 'radioBroadcast', ... matthiasm@13: 'smartPhonePlayback', ... matthiasm@13: 'smartPhoneRecording', ... matthiasm@13: 'strongMp3Compression', ... matthiasm@13: 'vinylRecording', ... matthiasm@14: 'unit_addNoise', ... matthiasm@13: 'unit_addSound', ... matthiasm@14: 'unit_applyAliasing', ... matthiasm@14: 'unit_applyClippingAlternative', ... matthiasm@15: 'unit_applyHarmonicDistortion', ... matthiasm@15: 'unit_applyMp3Compression', ... matthiasm@18: 'unit_applySpeedup', ... matthiasm@18: 'unit_applyWowResampling',... matthiasm@20: 'unit_applyDelay', ... matthiasm@20: 'unit_applyHighpassFilter', ... matthiasm@20: 'unit_applyLowpassFilter'}; matthiasm@13: nDegradation = length(degradationnames); matthiasm@0: matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: matthiasm@0: % read list of files to process matthiasm@0: fid = fopen(filename_listOfFiles); matthiasm@0: files=textscan(fid,'%s %s','delimiter',';'); matthiasm@0: fclose(fid); matthiasm@0: numLines = length(files{1}); matthiasm@0: if length(files)>1 && (length(files{2}) < numLines) matthiasm@0: files{2}{length(files{2})+1:numLines} = ''; matthiasm@0: end matthiasm@0: files{1} = strtrim(files{1}); matthiasm@0: files{2} = strtrim(files{2}); matthiasm@0: matthiasm@0: % create outputDirectory if necessary matthiasm@0: if ~exist(outputDirectory,'dir') matthiasm@0: mkdir(outputDirectory); matthiasm@0: end matthiasm@0: matthiasm@0: % loop over files to process matthiasm@0: parfor k=1:numLines % use this if you have the parallel computing toolbox matthiasm@0: % for k=1:numLines matthiasm@0: [path1,name1,ext1] = fileparts(files{1}{k}); matthiasm@0: [path2,name2,ext2] = fileparts(files{2}{k}); matthiasm@0: matthiasm@0: % check whether a wav and/or csv file is given matthiasm@0: audiofilename = []; audiopath = []; csvfilename=[]; csvpath = []; matthiasm@0: if strcmpi(ext1,'.csv') matthiasm@0: csvpath = path1; matthiasm@0: csvfilename = [name1,ext1]; matthiasm@0: elseif strcmpi(ext1,'.wav') matthiasm@0: audiopath = path1; matthiasm@0: audiofilename = [name1,ext1]; matthiasm@0: end matthiasm@0: if strcmpi(ext2,'.csv') matthiasm@0: csvpath = path2; matthiasm@0: csvfilename = [name2,ext2]; matthiasm@0: elseif strcmpi(ext2,'.wav') matthiasm@0: audiopath = path2; matthiasm@0: audiofilename = [name2,ext2]; matthiasm@0: end matthiasm@0: matthiasm@0: % Read audio and CSV data matthiasm@0: f_audio = []; samplingFreq = []; nbits = []; matthiasm@0: timepositions_beforeDegr = []; remainingColumns = []; matthiasm@0: if ~isempty(audiofilename) matthiasm@0: fprintf('Reading %s\n',audiofilename); matthiasm@0: [f_audio,samplingFreq,nbits] = wavread(fullfile(audiopath,audiofilename)); matthiasm@0: end matthiasm@0: if ~isempty(csvfilename) matthiasm@0: fprintf('Reading %s\n',csvfilename); matthiasm@0: matthiasm@0: fid = fopen(fullfile(csvpath,csvfilename)); matthiasm@0: linestring = fgetl(fid); matthiasm@0: numberOfColumns = length(strfind(linestring,','))+1; matthiasm@0: fclose(fid); matthiasm@0: matthiasm@0: fid = fopen(fullfile(csvpath,csvfilename)); matthiasm@0: data = textscan(fid,['%f' repmat('%s', 1, numberOfColumns-1) '%*[^\n]'], 'delimiter', ',', 'collectoutput', true); matthiasm@0: fclose(fid); matthiasm@0: matthiasm@0: timepositions_beforeDegr = data{1}; matthiasm@0: remainingColumns = data{2}; matthiasm@0: end matthiasm@0: matthiasm@13: % apply degradations matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@13: for iDegradation = 1:nDegradation matthiasm@13: degradationname = degradationnames{iDegradation}; matthiasm@13: PathToOutput = fullfile(outputDirectory,degradationname); matthiasm@13: if ~exist(PathToOutput,'dir') mkdir(PathToOutput); end matthiasm@13: [f_audio_out,timepositions_afterDegr] = applyDegradation(degradationname, f_audio, samplingFreq, timepositions_beforeDegr); matthiasm@13: matthiasm@13: if ~isempty(audiofilename) matthiasm@13: wavwrite(f_audio_out,samplingFreq,nbits,fullfile(PathToOutput,audiofilename)); matthiasm@13: end matthiasm@13: if ~isempty(csvfilename) matthiasm@13: writeCsvFile(fullfile(PathToOutput,csvfilename),timepositions_afterDegr,remainingColumns); matthiasm@13: end matthiasm@0: end matthiasm@0: end matthiasm@0: matthiasm@0: end matthiasm@0: matthiasm@0: