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