matthiasm@0: function [f_audio_out,timepositions_afterDegr] = applyDegradation(degradationname, f_audio, samplingFreq, timepositions_beforeDegr) matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: % Name: applyDegradation matthiasm@0: % Date of Revision: 2013-04 matthiasm@0: % Programmer: Sebastian Ewert matthiasm@0: % matthiasm@0: % Description: matthiasm@0: % - in the ADT, (high-level) degradations are usually combinations of several matthiasm@0: % degradation units, using specific parameters matthiasm@0: % - the "degradations" directory contains various degradations. They look like this: matthiasm@0: % ----------------------------------------------------------------% matthiasm@0: % degradation_config(1).methodname = 'degradationUnit_applyImpulseResponse'; matthiasm@0: % degradation_config(1).parameter.loadInternalIR = 1; matthiasm@0: % degradation_config(1).parameter.internalIR = 'GreatHall1'; matthiasm@0: % matthiasm@0: % degradation_config(2).methodname = 'degradationUnit_addNoise'; matthiasm@0: % degradation_config(2).parameter.snrRatio = 40; % in dB matthiasm@0: % ----------------------------------------------------------------% matthiasm@0: % - This degradation specifies that f_audio should first be degraded using the matthiasm@0: % degradation unit degradationUnit_applyImpulseResponse and subsequently matthiasm@0: % using degradationUnit_addNoise. This works like a chain matthiasm@0: % - To specify which degradation to use simply set degradationname accordingly. matthiasm@0: % - If you specify timepositions_beforeDegr, then timepositions_afterDegr matthiasm@0: % will contain the corresponding time position in the output audio file. matthiasm@0: % Set f_audio=[] and samplingFreq=0 if you want to process only time matthiasm@0: % positions matthiasm@0: % matthiasm@0: % Input: matthiasm@0: % f_audio - audio signal \in [-1,1]^{NxC} with C being the number of matthiasm@0: % channels matthiasm@0: % samplingFreq - sampling frequency of f_audio matthiasm@0: % timepositions_beforeDegr - some degradations delay the input signal. If matthiasm@0: % some points in time are given via this matthiasm@0: % parameter, timepositions_afterDegr will matthiasm@0: % return the corresponding positions in the matthiasm@0: % output. Set to [] if unavailable. Set f_audio matthiasm@0: % and samplingFreq to [] to compute only matthiasm@0: % timepositions_afterDegr. matthiasm@0: % Output: matthiasm@0: % f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number matthiasm@0: % of channels matthiasm@0: % timepositions_afterDegr - time positions corresponding to timepositions_beforeDegr matthiasm@0: % after all degradations are applied matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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@0: if nargin<4 matthiasm@0: timepositions_beforeDegr=[]; matthiasm@0: end matthiasm@0: if nargin<3 matthiasm@0: error('Please specify the required input variables') matthiasm@0: end matthiasm@0: matthiasm@0: % the degradations are in a subdirectory called "degradations" of the folder this matthiasm@0: % function is in matthiasm@0: fullFilenameMfile = mfilename('fullpath'); matthiasm@0: [pathstr,name,ext] = fileparts(fullFilenameMfile); matthiasm@0: dirDegradations = fullfile(pathstr,'degradations'); matthiasm@0: matthiasm@0: % add dirDegradations to matlab path if it is not included yet. Otherwise we matthiasm@0: % cannot call the degradation functions matthiasm@0: addpath(dirDegradations); matthiasm@0: matthiasm@0: % retrieve the degradation configuration matthiasm@0: degradationFunction = str2func(degradationname); matthiasm@0: degradation_config = degradationFunction(); matthiasm@0: matthiasm@0: % traverse degradation_config and call all the degradation units specified in there matthiasm@0: numDegradationUnits = length(degradation_config); matthiasm@0: f_audio_out = f_audio; matthiasm@0: timepositions_afterDegr = timepositions_beforeDegr; matthiasm@0: for n=1:numDegradationUnits matthiasm@0: degradationFunction = str2func(degradation_config(n).methodname); matthiasm@0: [f_audio_out,timepositions_afterDegr] = degradationFunction(f_audio_out, samplingFreq, timepositions_afterDegr, degradation_config(n).parameter); matthiasm@0: end matthiasm@0: matthiasm@0: end matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: