Mercurial > hg > audio-degradation-toolbox
changeset 13:1a058eb51073
degradation folder re-sort; towards more comprehensive batch processing demo
line wrap: on
line diff
--- a/AudioDegradationToolbox/degradationUnit_addNoise.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,166 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_addNoise(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_addNoise -% Date of Revision: 2013-01-23 -% Programmer: Sebastian Ewert -% -% Description: -% - adds white, pink, or brown noise to f_audio at specific SNR -% - white: white noise (same energy in every two spectral bands of same linear width) -% - pink: frequency spectrum inversely proportional to frequency (1/f) -% (i.e. 3db attenuation per octave). Same power level in all octaves -% - brown: noise produced by Brownian motion. Inversely proportional to -% frequency squared (1/f^2) (i.e. 6db attenuation per octave) -% - blue: +3db increase per octave (less long term effects) -% - violet: +6db increase per octave (equivalent to differentiating white noise) -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% samplingFreq - sampling frequency of f_audio -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .normalizeOutputAudio = 1 - peak normalize audio after adding the -% signals -% .snrRatio = 20 - in dB. -% noise is scaled such that a signal to noise ratio snr_ratio is obtained. -% .noiseColor = 'pink' % -% .filterOrderZeros = 3 - number of zeros in the IIR filter -% .filterOrderPoles = 6 - number of poles in the IIR filter -% .visualization = 0 - visualizes the magnitude response of the filter -% used -% -% Output: -% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number -% of channels -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'normalizeOutputAudio')==0 - parameter.normalizeOutputAudio = 1; -end -if isfield(parameter,'snrRatio')==0 - parameter.snrRatio = 20; % in dB -end -if isfield(parameter,'filterOrderZeros')==0 - parameter.filterOrderZeros = 3; -end -if isfield(parameter,'filterOrderPoles')==0 - parameter.filterOrderPoles = 6; -end -if isfield(parameter,'noiseColor')==0 - parameter.noiseColor = 'pink'; -end -if isfield(parameter,'visualization')==0 - parameter.visualization = 0; -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -f_audio_out = f_audio; -if ~isempty(f_audio) - - filterTheNoise = 1; - switch(lower( parameter.noiseColor)) - case 'white' - filterTheNoise = 0; - case 'pink' - freqExponent = 0.5; - case 'brown' - freqExponent = 1; - case 'blue' - freqExponent = -0.5; - case 'violet' - freqExponent = -1; - end - - f_noise = rand(size(f_audio))-0.5; - - if filterTheNoise - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % designing the filter - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - % building the magnitude response - Nfft = 8192; % FFT size to use during filter design - lengthMagResp = Nfft/2+1; - freqinfo = linspace(0,samplingFreq/2,lengthMagResp); - magResp = 1./freqinfo.^freqExponent; - magResp(1) = 1; - magRespFull = [magResp,magResp(lengthMagResp-1:-1:2)]; % add negative-frequencies - magRespFullDb = 20 * log10(magRespFull); - - % We want to use invfreqz as a filter design tool (least squares fit to - % given mag response). However, invfreqz also needs a phase response and is - % very sensitive to it. We use the cepstrum method to compute a min-phase - % frequency response from the mag response: - - % Fold cepstrum to reflect non-min-phase zeros inside unit circle: - cepstrum = ifft(magRespFullDb); % compute real cepstrum from log magnitude spectrum - cepstrumFolded = [cepstrum(1), cepstrum(2:lengthMagResp-1)+cepstrum(Nfft:-1:lengthMagResp+1), cepstrum(lengthMagResp), zeros(1,Nfft-lengthMagResp)]; - cepstrumFolded = fft(cepstrumFolded); - magRespFullDbNew = 10 .^ (cepstrumFolded/20); - - magRespFullDbNewPos = magRespFullDbNew(1:lengthMagResp); % nonnegative-frequency portion - weightVector = 1 ./ (freqinfo+1); % weighting the importance - freqinfo_rad = 2*pi*freqinfo/samplingFreq; - [B,A] = invfreqz(magRespFullDbNewPos,freqinfo_rad,parameter.filterOrderZeros,parameter.filterOrderPoles,weightVector); - - if parameter.visualization - fvtool(B,A); - end - - f_noise = filter(B,A,f_noise); - end - - parameter.loadInternalSound = 0; - parameter.addSound = f_noise; - parameter.addSoundSamplingFreq = samplingFreq; - f_audio_out = degradationUnit_addSound(f_audio_out, samplingFreq, [], parameter); - -end - - -% This degradation does not impose a delay -timepositions_afterDegr = timepositions_beforeDegr; - -end - - - -
--- a/AudioDegradationToolbox/degradationUnit_addSound.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,194 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_addSound(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_addSound -% Date of Revision: 2013-01-23 -% Programmer: Sebastian Ewert -% -% Description: -% - adds f_audioAdd to f_audio, looping f_audioAdd if necessary -% - sampling rate of f_audioAdd will be adjusted to be equal to samplingFreq -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% samplingFreq - sampling frequency of f_audio -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .normalizeOutputAudio = 1 - peak normalize audio after adding the -% signals -% .snrRatio = 10 - in dB. Treating "f_audioAdd" as noise, f_audioAdd is -% scaled such that a signal to noise ratio snr_ratio is obtained. -% Signal energy is the total energy for both signals (after f_audioAdd -% was looped if necessary) -% .transposeSignalsIfNecessary=1 - -% -% Output: -% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number -% of channels -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'loadInternalSound')==0 - parameter.loadInternalSound = 1; -end -if isfield(parameter,'internalSound')==0 - parameter.internalSound = 'OldDustyRecording'; -end -if isfield(parameter,'normalizeOutputAudio')==0 - parameter.normalizeOutputAudio = 1; -end -if isfield(parameter,'snrRatio')==0 - parameter.snrRatio = 0; % in dB -end -if isfield(parameter,'transposeSignalsIfNecessary')==0 - parameter.transposeSignalsIfNecessary = 1; -end -if isfield(parameter,'addSound')==0 - parameter.addSound = []; -end -if isfield(parameter,'addSoundSamplingFreq')==0 - parameter.addSoundSamplingFreq = 0; -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -f_audio_out = f_audio; -if ~isempty(f_audio) - - if parameter.loadInternalSound - % load sound included in toolbox - - fullFilenameMfile = mfilename('fullpath'); - [pathstr,name,ext] = fileparts(fullFilenameMfile); - dirRootIRs = fullfile(pathstr,'degradationData'); - - names_internalSounds = {'OldDustyRecording', 'PubEnvironment1', 'Hum50Hz'}; - indexSound = find(strcmpi(names_internalSounds,parameter.internalSound), 1); - if isempty(indexSound) - error('Please specify a valid internal name') - end - - switch indexSound - case 1 - file = fullfile(dirRootIRs,'VinylSim/old_dusty_vinyl_recording.wav'); - case 2 - file = fullfile(dirRootIRs,'PubSounds/restaurant08.wav'); - case 3 - file = fullfile(dirRootIRs,'PubSounds/hum_50Hz_from_headphone_plug.wav'); - end - [f_audioAdd,samplingFreqAdd] = wavread(file); - else - f_audioAdd = parameter.addSound; - samplingFreqAdd = parameter.addSoundSamplingFreq; - end - - if isempty(f_audioAdd) || (samplingFreqAdd == 0) - error('To use %s you must specify parameter.addSound and parameter.addSoundSamplingFreq',mfilename()); - end - - if parameter.transposeSignalsIfNecessary - if size(f_audio,1) < size(f_audio,2) - f_audio = f_audio'; - end - if size(f_audioAdd,1) < size(f_audioAdd,2) - f_audioAdd = f_audioAdd'; - end - end - - numLength1 = size(f_audio,1); - numLength2 = size(f_audioAdd,1); - numChannels1 = size(f_audio,2); - numChannels2 = size(f_audioAdd,2); - - if (numChannels2 ~= 1) && (numChannels1 ~= numChannels2) - error('number of channels in audio2 must either be 1 or the same as in audio1') - end - - if samplingFreq ~= samplingFreqAdd - f_audioAdd = resample(f_audioAdd,samplingFreq,samplingFreqAdd); - end - - numFullRepetitions = floor(numLength1/numLength2); - - totalAdditiveSound = zeros(numLength1,numChannels2); - totalAdditiveSound(1:numFullRepetitions*numLength2,:) = repmat(f_audioAdd,numFullRepetitions,1); - totalAdditiveSound(numFullRepetitions*numLength2+1:numLength1,:) = f_audioAdd(1:numLength1-numFullRepetitions*numLength2,:); - - if parameter.snrRatio == inf - scaler = 0; - prescaler = 1; - elseif parameter.snrRatio == -inf - scaler = 1; - prescaler = 0; - else - power1 = sum(f_audio.^2); - power2 = sum(totalAdditiveSound.^2); - if (numChannels2 == 1) - power2 = repmat(power2,1,numChannels1); - end - - destSnr = parameter.snrRatio; - - scaler = sqrt( power1 ./ (power2 * 10^(destSnr/10)) ); - prescaler = 1; - end - - f_audio_out = zeros(size(f_audio)); - if (numChannels2 == 1) - for nc=1:numChannels1 - f_audio_out(:,nc) = prescaler * f_audio(:,nc) + scaler(nc) * totalAdditiveSound; - end - else - for nc=1:numChannels1 - f_audio_out(:,nc) = prescaler * f_audio(:,nc) + scaler(nc) * totalAdditiveSound(:,nc); - end - end - - if parameter.normalizeOutputAudio - f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); - end - -end - -% This degradation does not impose a delay -timepositions_afterDegr = timepositions_beforeDegr; - -end - - - -
--- a/AudioDegradationToolbox/degradationUnit_applyAliasing.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyAliasing(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_applyAliasing -% Version: 1 -% Date: 2013-01-23 -% Programmer: Matthias Mauch -% -% Description: -% - downsamples without filtering, then upsamples again using S&H -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% samplingFreq - sampling frequency of f_audio -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .dsFrequency = 8000 - destination sampling frequency -% .normalizeOutputAudio = 1 - peak normalize output audio -% -% Output: -% f_audio - audio output signal -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'dsFrequency')==0 - parameter.dsFrequency = 8000; -end -if isfield(parameter,'normalizeOutputAudio')==0 - parameter.normalizeOutputAudio = 1; -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -f_audio_out = []; -if ~isempty(f_audio) - - % We cannot employ resample as it always imposes a lowpass pass filter to - % counter aliasing - - nSample = size(f_audio, 1); - nSampleNew = round(nSample / samplingFreq * parameter.dsFrequency); - - tOld = (0:(nSample-1))/samplingFreq; - tNew = (0:(nSampleNew-1))/parameter.dsFrequency; - - temp = interp1(tOld, f_audio, tNew, 'nearest'); - f_audio_out = resample(temp, samplingFreq, parameter.dsFrequency); - - if parameter.normalizeOutputAudio - f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); - end -end - -% This degradation does not impose a delay -timepositions_afterDegr = timepositions_beforeDegr; - -end
--- a/AudioDegradationToolbox/degradationUnit_applyClipping.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyClipping(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_applyClipping -% Version: 1 -% Date: 2013-01-23 -% Programmer: Matthias Mauch -% -% Description: -% - applies clipping by over-normalising -% - f_audio_out is the clipped audio -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% samplingFreq - sampling frequency of f_audio -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .preNormalization = -5 - db for 95% RMS quantile -% -% Output: -% f_audio - audio output signal -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'preNormalization')==0 - parameter.preNormalization = -5; % db for 95% RMS quantile -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -f_audio_out = []; -if ~isempty(f_audio) - quantMeasured = max(quantile(mean(f_audio.^2,2), 0.95),eps); - quantWanted = db2mag(parameter.preNormalization); - f_audio_out = f_audio * quantWanted / quantMeasured; - f_audio_out(f_audio_out < -1) = -1; - f_audio_out(f_audio_out > 1) = 1; - f_audio_out = f_audio_out * 0.99; -end - -% This degradation does not impose a delay -timepositions_afterDegr = timepositions_beforeDegr; - -end -
--- a/AudioDegradationToolbox/degradationUnit_applyClippingAlternative.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyClippingAlternative(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_applyClippingAlternative -% Date: 2013-04 -% Programmer: Sebastian Ewert -% -% Description: -% - applies clipping by over-normalising -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .clipAPercentageOfSamples = 1 - if set to zero a fixed number of -% samples will be clipped -% .parameter.percentOfSamples = 1 - used only if clipAPercentageOfSamples -% is 1 -% .parameter.numSamplesClipped = 1 - used only if clipAPercentageOfSamples -% is 0 -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output -% -% Output: -% f_audio_out - audio output signal -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'clipAPercentageOfSamples')==0 - parameter.clipAPercentageOfSamples = 1; -end -if isfield(parameter,'percentOfSamples')==0 - parameter.percentOfSamples = 1; -end -if isfield(parameter,'numSamplesClipped')==0 - parameter.numSamplesClipped = 10000; -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -f_audio_out = []; -if ~isempty(f_audio) - sortedValues = sort(abs(f_audio(:))); - numSamples = length(sortedValues); - if parameter.clipAPercentageOfSamples - idxStartSample = round( (1-parameter.percentOfSamples/100) * numSamples); - divisor = min(sortedValues(idxStartSample:numSamples)); - else - if parameter.numSamplesClipped > numSamples - numSamplesClipped = numSamples; - else - numSamplesClipped = parameter.numSamplesClipped; - end - divisor = min(sortedValues(numSamples-numSamplesClipped+1:numSamples)); - end - clear sortedValues - - divisor = max(divisor,eps); - f_audio_out = f_audio / divisor; - - f_audio_out(f_audio_out < -1) = -1; - f_audio_out(f_audio_out > 1) = 1; - f_audio_out = f_audio_out * 0.999; - -end - -% This degradation does not impose a delay -timepositions_afterDegr = timepositions_beforeDegr; - -end
--- a/AudioDegradationToolbox/degradationUnit_applyDynamicRangeCompression.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,181 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyDynamicRangeCompression(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_applyDynamicRangeCompression -% Version: 1 -% Date: 2013-01-23 -% Programmer: Matthias Mauch, Sebastian Ewert -% -% Description: -% - applies dynamic range compression to a signal -% - f_audio_out is the compressed audio -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% samplingFreq - sampling frequency of f_audio -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .preNormalization = 0; % db for 95% RMS quantile / 0 means "off" -% .forgettingTime = 0.1; % seconds -% .compressorThreshold = -40; % dB -% .compressorSlope = 0.9; -% .attackTime = 0.01; % seconds -% .releaseTime = 0.01; % seconds -% .delayTime = 0.01; % seconds -% .normalizeOutputAudio = 1; -% -% Output: -% f_audio_out - audio output signal -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'preNormalization')==0 - parameter.preNormalization = 0; % db for 95% RMS quantile / 0 means "off" -end -if isfield(parameter,'forgettingTime')==0 - parameter.forgettingTime = 0.1; % seconds -end -if isfield(parameter,'compressorThreshold')==0 - parameter.compressorThreshold = -40; % dB -end -if isfield(parameter,'compressorSlope')==0 - parameter.compressorSlope = 0.9; -end -if isfield(parameter,'attackTime')==0 - parameter.attackTime = 0.01; % seconds -end -if isfield(parameter,'releaseTime')==0 - parameter.releaseTime = 0.01; % seconds -end -if isfield(parameter,'delayTime')==0 - parameter.delayTime = 0.01; % seconds -end -if isfield(parameter,'normalizeOutputAudio')==0 - parameter.normalizeOutputAudio = 1; -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -f_audio_out = []; -if ~isempty(f_audio) - - %% secondary parameters - - AT = 1 - exp(-2.2/(samplingFreq*parameter.attackTime)); % attack parameter - RT = 1 - exp(-2.2/(samplingFreq*parameter.releaseTime)); % release parameter - FT = 1 - exp(-2.2/(samplingFreq*parameter.forgettingTime)); % forgetting parameter - - delay = floor(parameter.delayTime * samplingFreq); - - mono_audio = mean(f_audio, 2); - - if parameter.preNormalization < 0 - quantMeasured = max(quantile(abs(mono_audio), 0.95),eps); - quantWanted = db2mag(parameter.preNormalization); - f_audio = f_audio * quantWanted / quantMeasured; - mono_audio = mono_audio * quantWanted / quantMeasured; - end - - %% - - nSample = size(f_audio, 1); - nChannel = size(f_audio, 2); - - if AT == RT - % Vectorized version - %% - runningMS_all = filter(FT,[1 -(1-FT)],mono_audio.^2); - runningRMSdB_all = 10 * log10(runningMS_all); - gainDB_all = min([zeros(1,length(runningRMSdB_all));... - parameter.compressorSlope * (parameter.compressorThreshold - runningRMSdB_all(:)')]); - preGain_all = 10.^(gainDB_all/20); - gain_all = filter(AT,[1 -(1-AT)],[1/AT,preGain_all(2:end)]); - % The next line is equivalent to the behaviour of the serial version. Is that a bug? - %f_audio_out = repmat(gain_all(:),1,nChannel) .* [zeros(delay+1,nChannel);f_audio(1:end-(delay+1),:)]; - f_audio_out = repmat(gain_all(:),1,nChannel) .* [zeros(delay,nChannel);f_audio(1:end-delay,:)]; - else - % Serial version (The non-linearity 'if preGain < gain' does not seem to allow for a vectorization in all cases) - %% - runningMS = mono_audio(1)^2 * FT; - gain = 1; - buffer = zeros(delay + 1, nChannel); - f_audio_out = zeros(size(f_audio)); - - for iSample = 2:nSample - runningMS = ... - runningMS * (1-FT) +... - mono_audio(iSample)^2 * FT; - runningRMSdB = 10 * log10(runningMS); - - gainDB = min([0, ... - parameter.compressorSlope * (parameter.compressorThreshold - runningRMSdB)]); - preGain = 10^(gainDB/20); - - if preGain < gain % "gain" being old gain - coeff = AT; % we're in the attack phase - else - coeff = RT; % we're in the release phase - end - - % calculate new gain as mix of current gain (preGain) and old gain - gain = (1-coeff) * gain + coeff * preGain; - - f_audio_out(iSample, :) = gain * buffer(end,:); - if delay > 1 - buffer = [f_audio(iSample, :); buffer(1:end-1,:)]; - else - buffer = f_audio(iSample, :); - end - end - end - - if parameter.normalizeOutputAudio - f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); - end - -end - -% This degradation does impose a temporal distortion -timepositions_afterDegr = timepositions_beforeDegr + parameter.delayTime; - -end - - - -
--- a/AudioDegradationToolbox/degradationUnit_applyHarmonicDistortion.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyHarmonicDistortion(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_applyHarmonicDistortion -% Version: 1 -% Date: 2013-01-25 -% Programmer: Matthias Mauch -% -% Description: -% - applies quadratic distortion to the audio -% - f_audio_out is the distorted audio -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .nApplications = 3 - number of iterative applications. The higher the -% stronger -% .normalizeOutputAudio = 1 - normalize audio -% -% Output: -% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number -% of channels -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'nApplications')==0 - parameter.nApplications = 3; -end -if isfield(parameter,'normalizeOutputAudio')==0 - parameter.normalizeOutputAudio = 1; -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -f_audio_out = []; -if ~isempty(f_audio) - f_audio_out = f_audio; - for ii = 1:parameter.nApplications - f_audio_out = sin(f_audio_out * pi/2); - end - - if parameter.normalizeOutputAudio - f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); - end - -end - -% This degradation does not impose a delay -timepositions_afterDegr = timepositions_beforeDegr; - -end
--- a/AudioDegradationToolbox/degradationUnit_applyHighpassFilter.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyHighpassFilter(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_applyHighpassFilter -% Date: 2013-04 -% Programmer: Matthias Mauch -% -% Description: -% - applies a highpass filter to the audio -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .stopFrequency = 200 - stop band edge frequency in Hz -% .passFrequency = - pass band edge frequency in Hz, -% default is 2 x [stop band edge frequency] -% -% Output: -% f_audio_out - audio output signal -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'stopFrequency')==0 - parameter.stopFrequency = 200; -end -if isfield(parameter,'passFrequency')==0 - parameter.passFrequency = 2 * parameter.stopFrequency; -end - -if parameter.stopFrequency > parameter.passFrequency - error('Please choose a pass frequency greater than the stop frequency.'); -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -f_audio_out = []; -if ~isempty(f_audio) - - omega_stop = parameter.stopFrequency / samplingFreq * 2 * pi; % stopband omega - omega_pass = parameter.passFrequency / samplingFreq * 2 * pi; % passband omega - transition_width = abs(omega_stop-omega_pass); - - lobe_width = 3.32; - filter_order = ceil(lobe_width*pi/transition_width); % filter order via transition bandwidth (see lecture) - - - filter_length = 2*filter_order + 1; - - n = 0:(filter_length-1); - omega_cutoff = (omega_stop+omega_pass)/2; % cutoff frequency is mean of pass and stopband edges - alpha = (filter_length-1)/2; - m = n - alpha; % symmetricised indices - - hd = -omega_cutoff/pi * sinc(omega_cutoff/pi*m); - hd(alpha+1) = hd(alpha+1) + 1; - - window = hamming(filter_length)'; - h = hd .* window; - - f_audio_out = fftfilt(h, [f_audio; zeros([filter_order, size(f_audio,2)])]); - f_audio_out = f_audio_out((filter_order + 1):end, :); - - - f_audio_out(f_audio_out < -1) = -1; - f_audio_out(f_audio_out > 1) = 1; - f_audio_out = f_audio_out * 0.999; - -end - -% This degradation has no delay. -timepositions_afterDegr = timepositions_beforeDegr; - -end
--- a/AudioDegradationToolbox/degradationUnit_applyImpulseResponse.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,197 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyImpulseResponse(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_applyImpulseResponse -% Date of Revision: 2013-04 -% Programmer: Sebastian Ewert -% -% Description: -% - applies an FIR filter -% - takes care that f_audio and firfilter use same sampling frequency -% - set samplingFreqFilter = samplingFreq if you do not which to resample -% the filter -% - predefines IR: 'GreatHall1','Classroom1','Octagon1', -% 'GoogleNexusOneFrontSpeaker','GoogleNexusOneFrontMic' -% 'VinylPlayer1960' -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% samplingFreq - sampling frequency of f_audio -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .presetIR = 'GreatHall1'; - load IR from a ADT preset -% .impulseResponse = []; - IR to apply -% .impulseResponseSampFreq = 0; - sampling rate of IR -% .normalizeOutputAudio = 1 - normalize output -% .normalizeImpulseResponse = 0 - l1-normalize firfilter before -% application -% -% Output: -% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% timepositions_afterDegr - time positions corresponding to timepositions_beforeDegr -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end -if isfield(parameter,'loadInternalIR')==0 - parameter.loadInternalIR = 1; -end -if isfield(parameter,'internalIR')==0 - parameter.internalIR = 'GreatHall1'; -end -if isfield(parameter,'normalizeOutputAudio')==0 - parameter.normalizeOutputAudio = 1; -end -if isfield(parameter,'normalizeImpulseResponse')==0 - parameter.normalizeImpulseResponse = 0; -end -if isfield(parameter,'impulseResponse')==0 - parameter.impulseResponse = []; -end -if isfield(parameter,'impulseResponseSampFreq')==0 - parameter.impulseResponseSampFreq = 0; -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -if parameter.loadInternalIR - % load IR included in toolbox - - fullFilenameMfile = mfilename('fullpath'); - [pathstr,name,ext] = fileparts(fullFilenameMfile); - dirRootIRs = fullfile(pathstr,'degradationData'); - - names_internalIR = {'GreatHall1','Classroom1','Octagon1','GoogleNexusOneFrontSpeaker','GoogleNexusOneFrontMic','VinylPlayer1960'}; - indexIR = find(strcmpi(names_internalIR,parameter.internalIR), 1); - if isempty(indexIR) - error('Please specify a valid preset') - end - - switch indexIR - case 1 - file = fullfile(dirRootIRs,'RoomResponses/GreatHall_Omni_x06y06.wav'); - case 2 - file = fullfile(dirRootIRs,'RoomResponses/Classroom_Omni_30x20y.wav'); - case 3 - file = fullfile(dirRootIRs,'RoomResponses/Octagon_Omni_x06y06.wav'); - case 4 - file = fullfile(dirRootIRs,'PhoneResponses/IR_GoogleNexusOneFrontSpeaker.wav'); - case 5 - file = fullfile(dirRootIRs,'PhoneResponses/IR_GoogleNexusOneFrontMic.wav'); - case 6 - file = fullfile(dirRootIRs,'VinylSim/ImpulseReponseVinylPlayer1960_smoothed.wav'); - end - [parameter.impulseResponse,parameter.impulseResponseSampFreq] = wavread(file); -end - -fs = samplingFreq; -h = parameter.impulseResponse; -fs_h = parameter.impulseResponseSampFreq; -h_org = h; - -f_audio_out = []; -if ~isempty(f_audio) - - if (size(h,2) > 1) && (size(h,1) ~= 1) - error('Multichannel impulse responses are not supported'); - end - - if fs ~= fs_h - h = resample(h,fs,fs_h); - end - - if parameter.normalizeImpulseResponse - h = h / max(abs(h)); - end - - f_audio_out = fftfilt(h,f_audio); - - if parameter.normalizeOutputAudio - f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); - end -end - -% This degradation does impose a delay -timepositions_afterDegr = []; -if ~isempty(timepositions_beforeDegr) - % approximation via group delay - - [Gd,W] = mygrpdelay(h_org,1,fs_h,2048); - %[Gd,W] = grpdelay(h_org,1,1024); % Matlab's own group delay function. Failt for some filters considerably. - - %figure; - %plot(W,Gd/samplingFreqFilter) - - averageOfGroupDelays = mean(Gd); - timeOffset_sec = averageOfGroupDelays / fs_h; - - timepositions_afterDegr = timepositions_beforeDegr + timeOffset_sec; -end - -end - -function [gd,w] = mygrpdelay(b,a,Fs,nfft) -% see also https://ccrma.stanford.edu/~jos/fp/Group_Delay_Computation_grpdelay_m.html - -b = b(:); -a = a(:); - -w=Fs*[0:nfft-1]/nfft; -oa = length(a)-1; % order of a(z) -oc = oa + length(b)-1; % order of c(z) -c = conv(b,fliplr(a)); % c(z) = b(z)*a(1/z)*z^(-oa) -cr = c.*[0:oc]'; % derivative of c wrt 1/z -num = fft(cr,nfft); -den = fft(c,nfft); -minmag = 10*eps; -polebins = find(abs(den)<minmag); -num(polebins) = 0; -den(polebins) = 1; -gd = real(num ./ den) - oa; - -ns = nfft/2; % Matlab convention - should be nfft/2 + 1 -gd = gd(1:ns); -w = w(1:ns); - -w = w(:); % Matlab returns column vectors -gd = gd(:); - -end - - -
--- a/AudioDegradationToolbox/degradationUnit_applyMp3Compression.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,197 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyMp3Compression(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_applyMp3Compression -% Date: 2013-01-22 -% Programmer: Sebastian Ewert -% -% Description: -% - encodes audio using mp3 -% - f_audio_out is the decoded version of that mp3 -% - uses lame for mp3 handling -% - some binaries for lame are provided. Under linux it additionally tries -% to find a binary installed on the system. -% - if no suitable lame can be found please install one and point -% parameter.LocationLameBinary to it -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% samplingFreq - sampling frequency of f_audio -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .LocationLameBinary - not set. Use to specify path to lame -% .LameOptions = '--preset cbr 128' - lame encoding options -% .deleteIntermediateFiles = 1 - delete temporary files -% -% Output: -% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number -% of channels -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'LocationLameBinary')==0 - fullFilenameMfile = mfilename('fullpath'); - [pathstr,name,ext] = fileparts(fullFilenameMfile); - if ispc - parameter.LocationLameBinary = [pathstr,'\degradationData\Compressors\lame.exe']; - elseif isunix - if ismac - parameter.LocationLameBinary = [pathstr,'/degradationData/Compressors/lame.mac']; - else - % linux/unix - [status,result] = system('which lame'); - if status == 0 - parameter.LocationLameBinary = result; - else - parameter.LocationLameBinary = [pathstr,'/degradationData/Compressors/lame.linux']; - - [status,result] = system(parameter.LocationLameBinary); - if status > 1 - error(['Cannot find a valid lame binary. Possible solutions:',... - '1.) Install lame on your system using the package system. ',... - '2.) Compile a lame binary yourself and point parameter.LocationLameBinary ',... - 'to it. See also http://lame.sourceforge.net/']) - end - end - end - end - -else -end -if isfield(parameter,'compressionLevel')==0 - parameter.compressionLevel = 'strong'; % {'maximum','strong','medium','light','verylight'}; -end -if isfield(parameter,'LameOptions')==0 - parameter.LameOptions = []; % usually set via parameter.compressionLevel -end -if isfield(parameter,'deleteIntermediateFiles')==0 - parameter.deleteIntermediateFiles = 1; -end -if isfield(parameter,'normalizeOutputAudio')==0 - parameter.normalizeOutputAudio = 1; -end - -if ~exist(parameter.LocationLameBinary,'file') - error('audio_to_mp3: could not find Lame under %s .\n',parameter.LocationLameBinary); -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -f_audio_out = []; -if ~isempty(f_audio) - - if isempty(parameter.LameOptions) - compressionLevels = {'maximum','strong','medium','light','verylight'}; - indexLevel = find(strcmpi(compressionLevels,parameter.compressionLevel), 1); - if isempty(indexLevel) - error('Please specify a valid preset') - end - - switch indexLevel - case 1 - parameter.LameOptions = '--preset cbr 32'; - case 2 - parameter.LameOptions = '--preset cbr 64'; - case 3 - parameter.LameOptions = '--preset cbr 128'; - case 4 - parameter.LameOptions = '--preset cbr 192'; - case 5 - parameter.LameOptions = '--preset cbr 256'; - end - end - - wavFilenameAndPath = [tempname,'.wav']; - [tempdir,wavFilename,wavExt] = fileparts(wavFilenameAndPath); - wavwrite(f_audio,samplingFreq,24,wavFilenameAndPath); - - mp3FilenameAndPath = [tempdir,'/',wavFilename,'.mp3']; - [status,result] = system(sprintf('"%s" %s "%s" "%s"',parameter.LocationLameBinary,parameter.LameOptions,... - wavFilenameAndPath, mp3FilenameAndPath)); - if status ~= 0 - warning(sprintf('There has been an error during the creation of %s. Error message:\n%s\n',mp3FilenameAndPath,result)); - end - if parameter.deleteIntermediateFiles - delete(wavFilenameAndPath); - end - - [status,result] = system(sprintf('"%s" --decode "%s" "%s"',parameter.LocationLameBinary,... - mp3FilenameAndPath,wavFilenameAndPath )); - if status ~= 0 - warning(sprintf('There has been an error during the creation of %s. Error message:\n%s\n',wavFilenameAndPath,result)); - end - if parameter.deleteIntermediateFiles - delete(mp3FilenameAndPath); - end - - try - [f_audio_out, fs,nbits] = wavread(wavFilenameAndPath); - catch % fix incorrect chunk size, see http://www.mathworks.com/support/solutions/en/data/1-1BZMF/index.html - warning('lame returned an ill-formed audio file. Trying to correct the file header...') - d = dir(wavFilenameAndPath); - fileSize = d.bytes; - fid=fopen(wavFilenameAndPath,'r+','l'); - fseek(fid,4,-1); - fwrite(fid,fileSize-8,'uint32'); - fseek(fid,40,-1); - fwrite(fid,fileSize-44,'uint32'); - fclose(fid); - [f_audio_out, fs,nbits] = wavread(wavFilenameAndPath); - end - - if parameter.deleteIntermediateFiles - delete(wavFilenameAndPath); - end - - if fs ~= samplingFreq - f_audio_out = resample(f_audio_out,samplingFreq,fs); - end - - if parameter.normalizeOutputAudio - f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); - end - -end - -% This degradation does not impose a delay. -% Note: Remark that MP3 does impose a delay on the encoder as well as on -% the decoder side. In case of lame, the decoder delay is the negative to -% the encoder delay so both cancel each other out. -timepositions_afterDegr = timepositions_beforeDegr; - -end
--- a/AudioDegradationToolbox/degradationUnit_applySpeedup.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_applySpeedup(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_applySpeedup -% Version: 1 -% Date: 2013-01-23 -% Programmer: Sebastian Ewert -% -% Description: -% - changes the playback speed of f_audio via resampling -% - change is specified in percent: -% total length of f_audio after the degradation is -% (100 - parameter.changeInPercent)/100 * originalLength -% - positive values lead to a speed-up, while negative values lead to a -% slow-down -% - Note: Frequencies are shifted to 100/(100 - parameter.changeInPercent), -% i.e. the default of parameter.changeInPercent = +3 shifts all -% frequencies by about half a semitone -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .changeInPercent = +3 - see description -% .normalizeOutputAudio = 1 - normalize output -% -% Output: -% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number -% of channels -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'changeInPercent')==0 - parameter.changeInPercent = +3; -end -if isfield(parameter,'normalizeOutputAudio')==0 - parameter.normalizeOutputAudio = 1; -end -if isfield(parameter,'maxProblemComplexity')==0 - % lower this if you run into 'reduce problem complexity' problems - parameter.maxProblemComplexity = 2^27; % limit defined in resample: 2^31, however, that is still too large -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -f_audio_out = []; -if ~isempty(f_audio) - Q = round(sqrt(parameter.maxProblemComplexity * 100 / (100 - parameter.changeInPercent))); - P = round(parameter.maxProblemComplexity / Q); - - f_audio_out = resample(f_audio,P,Q); - - if parameter.normalizeOutputAudio - f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); - end -end - -% This degradation does impose a temporal distortion -timepositions_afterDegr = (100 - parameter.changeInPercent)/100 * timepositions_beforeDegr; - -end
--- a/AudioDegradationToolbox/degradationUnit_applyWowResampling.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyWowResampling(f_audio, samplingFreq, timepositions_beforeDegr, parameter) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Name: degradation_applyWowResampling -% Date of Revision: 2013-03 -% Programmer: Sebastian Ewert -% -% Description: -% - This is useful for wow and flutter simulations. -% - a playback speed of 1 is modulated by a cos signal via -% f(x) = a_m * cos(2*pi*f_m*x)+1 -% - the function mapping a position in the original recording -% to a position in the generated recording: -% F(x) = x + a_m * sin(2*pi*f_m*x) / (2*pi*f_m) -% - an optimal solution now would employ a sinc reconstruction of f_audio, -% sinc_fa, and sampling sinc_fa(F^-1(y)) equidistantly. -% - This implementation employs only an approximation by first upsampling -% f_audio and then sampling that using nearest neighbors -% -% Input: -% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of -% channels -% samplingFreq - sampling frequency of f_audio -% timepositions_beforeDegr - some degradations delay the input signal. If -% some points in time are given via this -% parameter, timepositions_afterDegr will -% return the corresponding positions in the -% output. Set to [] if unavailable. Set f_audio -% and samplingFreq to [] to compute only -% timepositions_afterDegr. -% -% Input (optional): parameter -% .intensityOfChange = 1.5 - a_m = parameter.intensityOfChange/100; stay below 100 -% .frequencyOfChange = 0.5 - f_m -% .upsamplingFactor = 5 - the higher the better the quality (and the more memory) -% .normalizeOutputAudio = 0 - normalize audio -% -% Output: -% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number -% of channels -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Check parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -if nargin<4 - parameter=[]; -end -if nargin<3 - timepositions_beforeDegr=[]; -end -if nargin<2 - error('Please specify input data'); -end - -if isfield(parameter,'intensityOfChange')==0 - parameter.intensityOfChange = 1.5; % a_m = parameter.intensityOfChange/100; %stay below 100 -end -if isfield(parameter,'frequencyOfChange')==0 - parameter.frequencyOfChange = 0.5; % f_m -end -if isfield(parameter,'upsamplingFactor')==0 - parameter.upsamplingFactor = 5; % the higher the better the quality (and the more memory) -end -if isfield(parameter,'normalizeOutputAudio')==0 - parameter.normalizeOutputAudio = 0; -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Main program -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -fs = samplingFreq; -fsOverSampled = fs * parameter.upsamplingFactor; -a_m = parameter.intensityOfChange / 100; -f_m = parameter.frequencyOfChange; - -f_audio_out = f_audio; -if ~isempty(f_audio) - numSamples = size(f_audio,1); - numChannels = size(f_audio,2); - length_sec = numSamples/fs; - numFullPeriods = floor(length_sec * f_m); - numSamplesToWarp = round(numFullPeriods *fs / f_m); - - oldSamplePositions_to_newOversampledPositions = round(timeAssignment_newToOld([1:numSamplesToWarp]/fs,a_m,f_m)*fsOverSampled); - - for ch=1:numChannels - audioUpsampled = resample(f_audio(:,ch),parameter.upsamplingFactor,1); - - f_audio_out(1:numSamplesToWarp,ch) = audioUpsampled(oldSamplePositions_to_newOversampledPositions); - - clear audioUpsampled - end - - if parameter.normalizeOutputAudio - f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); - end - -end - -%pitchShifted_semitones = getPitchShiftAtPositionsInNewFile([0:0.1:length_sec],a_m,f_m); % not used yet but might be useful later on - -%selftest(length_sec,a_m,f_m); - -% This degradation does impose a complex temporal distortion -timepositions_afterDegr = []; -if ~isempty(timepositions_beforeDegr) - timepositions_afterDegr = timeAssignment_oldToNew(timepositions_beforeDegr,a_m,f_m); -end - -end - - -function timeAssigned = timeAssignment_oldToNew(x,a_m,f_m) -% vectorized - -timeAssigned = x + a_m * sin(2*pi*f_m*x) / (2*pi*f_m); - -end - -function timeAssigned = timeAssignment_newToOld(y,a_m,f_m) -% vectorized -% SE: non linear equation: solved numerically (we are lucky: -% As G(x) := x - (F(x)-y) is a contraction for a_m<1 we can simply employ the Banach fixpoint theorem) - -timeAssigned = y; -for k=1:40 - timeAssigned = y - a_m * sin(2*pi*f_m*timeAssigned) / (2*pi*f_m); -end - -end - -function pitchShifted_semitones = getPitchShiftAtPositionsInNewFile(y,a_m,f_m) -% vectorized - -% maps times from new to old and takes a look at the value of the derivative -% there - -timeAssigned = timeAssignment_newToOld(y,a_m,f_m); - -derivative = 1 + a_m * cos(2*pi*f_m*timeAssigned); - -pitchShifted_semitones = log2(1./derivative)*12; - -end - -function selftest(length_sec,a_m,f_m) - -x0 = rand(10000,1) * length_sec; - -timeAssigned1 = timeAssignment_oldToNew(x0,a_m,f_m); -timeAssigned2 = timeAssignment_newToOld(timeAssigned1,a_m,f_m); - -figure; -plot(x0 - timeAssigned2); - -end - - - - - -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_addNoise.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,166 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_addNoise(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_addNoise +% Date of Revision: 2013-01-23 +% Programmer: Sebastian Ewert +% +% Description: +% - adds white, pink, or brown noise to f_audio at specific SNR +% - white: white noise (same energy in every two spectral bands of same linear width) +% - pink: frequency spectrum inversely proportional to frequency (1/f) +% (i.e. 3db attenuation per octave). Same power level in all octaves +% - brown: noise produced by Brownian motion. Inversely proportional to +% frequency squared (1/f^2) (i.e. 6db attenuation per octave) +% - blue: +3db increase per octave (less long term effects) +% - violet: +6db increase per octave (equivalent to differentiating white noise) +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% samplingFreq - sampling frequency of f_audio +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .normalizeOutputAudio = 1 - peak normalize audio after adding the +% signals +% .snrRatio = 20 - in dB. +% noise is scaled such that a signal to noise ratio snr_ratio is obtained. +% .noiseColor = 'pink' % +% .filterOrderZeros = 3 - number of zeros in the IIR filter +% .filterOrderPoles = 6 - number of poles in the IIR filter +% .visualization = 0 - visualizes the magnitude response of the filter +% used +% +% Output: +% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number +% of channels +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'normalizeOutputAudio')==0 + parameter.normalizeOutputAudio = 1; +end +if isfield(parameter,'snrRatio')==0 + parameter.snrRatio = 20; % in dB +end +if isfield(parameter,'filterOrderZeros')==0 + parameter.filterOrderZeros = 3; +end +if isfield(parameter,'filterOrderPoles')==0 + parameter.filterOrderPoles = 6; +end +if isfield(parameter,'noiseColor')==0 + parameter.noiseColor = 'pink'; +end +if isfield(parameter,'visualization')==0 + parameter.visualization = 0; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +f_audio_out = f_audio; +if ~isempty(f_audio) + + filterTheNoise = 1; + switch(lower( parameter.noiseColor)) + case 'white' + filterTheNoise = 0; + case 'pink' + freqExponent = 0.5; + case 'brown' + freqExponent = 1; + case 'blue' + freqExponent = -0.5; + case 'violet' + freqExponent = -1; + end + + f_noise = rand(size(f_audio))-0.5; + + if filterTheNoise + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % designing the filter + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % building the magnitude response + Nfft = 8192; % FFT size to use during filter design + lengthMagResp = Nfft/2+1; + freqinfo = linspace(0,samplingFreq/2,lengthMagResp); + magResp = 1./freqinfo.^freqExponent; + magResp(1) = 1; + magRespFull = [magResp,magResp(lengthMagResp-1:-1:2)]; % add negative-frequencies + magRespFullDb = 20 * log10(magRespFull); + + % We want to use invfreqz as a filter design tool (least squares fit to + % given mag response). However, invfreqz also needs a phase response and is + % very sensitive to it. We use the cepstrum method to compute a min-phase + % frequency response from the mag response: + + % Fold cepstrum to reflect non-min-phase zeros inside unit circle: + cepstrum = ifft(magRespFullDb); % compute real cepstrum from log magnitude spectrum + cepstrumFolded = [cepstrum(1), cepstrum(2:lengthMagResp-1)+cepstrum(Nfft:-1:lengthMagResp+1), cepstrum(lengthMagResp), zeros(1,Nfft-lengthMagResp)]; + cepstrumFolded = fft(cepstrumFolded); + magRespFullDbNew = 10 .^ (cepstrumFolded/20); + + magRespFullDbNewPos = magRespFullDbNew(1:lengthMagResp); % nonnegative-frequency portion + weightVector = 1 ./ (freqinfo+1); % weighting the importance + freqinfo_rad = 2*pi*freqinfo/samplingFreq; + [B,A] = invfreqz(magRespFullDbNewPos,freqinfo_rad,parameter.filterOrderZeros,parameter.filterOrderPoles,weightVector); + + if parameter.visualization + fvtool(B,A); + end + + f_noise = filter(B,A,f_noise); + end + + parameter.loadInternalSound = 0; + parameter.addSound = f_noise; + parameter.addSoundSamplingFreq = samplingFreq; + f_audio_out = degradationUnit_addSound(f_audio_out, samplingFreq, [], parameter); + +end + + +% This degradation does not impose a delay +timepositions_afterDegr = timepositions_beforeDegr; + +end + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_addSound.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,194 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_addSound(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_addSound +% Date of Revision: 2013-01-23 +% Programmer: Sebastian Ewert +% +% Description: +% - adds f_audioAdd to f_audio, looping f_audioAdd if necessary +% - sampling rate of f_audioAdd will be adjusted to be equal to samplingFreq +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% samplingFreq - sampling frequency of f_audio +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .normalizeOutputAudio = 1 - peak normalize audio after adding the +% signals +% .snrRatio = 10 - in dB. Treating "f_audioAdd" as noise, f_audioAdd is +% scaled such that a signal to noise ratio snr_ratio is obtained. +% Signal energy is the total energy for both signals (after f_audioAdd +% was looped if necessary) +% .transposeSignalsIfNecessary=1 - +% +% Output: +% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number +% of channels +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'loadInternalSound')==0 + parameter.loadInternalSound = 1; +end +if isfield(parameter,'internalSound')==0 + parameter.internalSound = 'OldDustyRecording'; +end +if isfield(parameter,'normalizeOutputAudio')==0 + parameter.normalizeOutputAudio = 1; +end +if isfield(parameter,'snrRatio')==0 + parameter.snrRatio = 0; % in dB +end +if isfield(parameter,'transposeSignalsIfNecessary')==0 + parameter.transposeSignalsIfNecessary = 1; +end +if isfield(parameter,'addSound')==0 + parameter.addSound = []; +end +if isfield(parameter,'addSoundSamplingFreq')==0 + parameter.addSoundSamplingFreq = 0; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +f_audio_out = f_audio; +if ~isempty(f_audio) + + if parameter.loadInternalSound + % load sound included in toolbox + + fullFilenameMfile = mfilename('fullpath'); + [pathstr,name,ext] = fileparts(fullFilenameMfile); + dirRootIRs = fullfile(pathstr,'../degradationData'); + + names_internalSounds = {'OldDustyRecording', 'PubEnvironment1', 'Hum50Hz'}; + indexSound = find(strcmpi(names_internalSounds,parameter.internalSound), 1); + if isempty(indexSound) + error('Please specify a valid internal name') + end + + switch indexSound + case 1 + file = fullfile(dirRootIRs,'VinylSim/old_dusty_vinyl_recording.wav'); + case 2 + file = fullfile(dirRootIRs,'PubSounds/restaurant08.wav'); + case 3 + file = fullfile(dirRootIRs,'PubSounds/hum_50Hz_from_headphone_plug.wav'); + end + [f_audioAdd,samplingFreqAdd] = wavread(file); + else + f_audioAdd = parameter.addSound; + samplingFreqAdd = parameter.addSoundSamplingFreq; + end + + if isempty(f_audioAdd) || (samplingFreqAdd == 0) + error('To use %s you must specify parameter.addSound and parameter.addSoundSamplingFreq',mfilename()); + end + + if parameter.transposeSignalsIfNecessary + if size(f_audio,1) < size(f_audio,2) + f_audio = f_audio'; + end + if size(f_audioAdd,1) < size(f_audioAdd,2) + f_audioAdd = f_audioAdd'; + end + end + + numChannels1 = size(f_audio,2); + numChannels2 = size(f_audioAdd,2); + + if (numChannels2 ~= 1) && (numChannels1 ~= numChannels2) + error('number of channels in audio2 must either be 1 or the same as in audio1') + end + + if samplingFreq ~= samplingFreqAdd + f_audioAdd = resample(f_audioAdd,samplingFreq,samplingFreqAdd); + end + + numLength1 = size(f_audio,1); + numLength2 = size(f_audioAdd,1); + numFullRepetitions = floor(numLength1/numLength2); + + totalAdditiveSound = zeros(numLength1,numChannels2); + totalAdditiveSound(1:numFullRepetitions*numLength2,:) = repmat(f_audioAdd,numFullRepetitions,1); + totalAdditiveSound(numFullRepetitions*numLength2+1:numLength1,:) = f_audioAdd(1:numLength1-numFullRepetitions*numLength2,:); + + if parameter.snrRatio == inf + scaler = 0; + prescaler = 1; + elseif parameter.snrRatio == -inf + scaler = 1; + prescaler = 0; + else + power1 = sum(f_audio.^2); + power2 = sum(totalAdditiveSound.^2); + if (numChannels2 == 1) + power2 = repmat(power2,1,numChannels1); + end + + destSnr = parameter.snrRatio; + + scaler = sqrt( power1 ./ (power2 * 10^(destSnr/10)) ); + prescaler = 1; + end + + f_audio_out = zeros(size(f_audio)); + if (numChannels2 == 1) + for nc=1:numChannels1 + f_audio_out(:,nc) = prescaler * f_audio(:,nc) + scaler(nc) * totalAdditiveSound; + end + else + for nc=1:numChannels1 + f_audio_out(:,nc) = prescaler * f_audio(:,nc) + scaler(nc) * totalAdditiveSound(:,nc); + end + end + + if parameter.normalizeOutputAudio + f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); + end + +end + +% This degradation does not impose a delay +timepositions_afterDegr = timepositions_beforeDegr; + +end + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_applyAliasing.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,93 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyAliasing(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_applyAliasing +% Version: 1 +% Date: 2013-01-23 +% Programmer: Matthias Mauch +% +% Description: +% - downsamples without filtering, then upsamples again using S&H +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% samplingFreq - sampling frequency of f_audio +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .dsFrequency = 8000 - destination sampling frequency +% .normalizeOutputAudio = 1 - peak normalize output audio +% +% Output: +% f_audio - audio output signal +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'dsFrequency')==0 + parameter.dsFrequency = 8000; +end +if isfield(parameter,'normalizeOutputAudio')==0 + parameter.normalizeOutputAudio = 1; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +f_audio_out = []; +if ~isempty(f_audio) + + % We cannot employ resample as it always imposes a lowpass pass filter to + % counter aliasing + + nSample = size(f_audio, 1); + nSampleNew = round(nSample / samplingFreq * parameter.dsFrequency); + + tOld = (0:(nSample-1))/samplingFreq; + tNew = (0:(nSampleNew-1))/parameter.dsFrequency; + + temp = interp1(tOld, f_audio, tNew, 'nearest'); + f_audio_out = resample(temp, samplingFreq, parameter.dsFrequency); + + if parameter.normalizeOutputAudio + f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); + end +end + +% This degradation does not impose a delay +timepositions_afterDegr = timepositions_beforeDegr; + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_applyClipping.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,81 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyClipping(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_applyClipping +% Version: 1 +% Date: 2013-01-23 +% Programmer: Matthias Mauch +% +% Description: +% - applies clipping by over-normalising +% - f_audio_out is the clipped audio +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% samplingFreq - sampling frequency of f_audio +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .preNormalization = -5 - db for 95% RMS quantile +% +% Output: +% f_audio - audio output signal +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'preNormalization')==0 + parameter.preNormalization = -5; % db for 95% RMS quantile +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +f_audio_out = []; +if ~isempty(f_audio) + quantMeasured = max(quantile(mean(f_audio.^2,2), 0.95),eps); + quantWanted = db2mag(parameter.preNormalization); + f_audio_out = f_audio * quantWanted / quantMeasured; + f_audio_out(f_audio_out < -1) = -1; + f_audio_out(f_audio_out > 1) = 1; + f_audio_out = f_audio_out * 0.99; +end + +% This degradation does not impose a delay +timepositions_afterDegr = timepositions_beforeDegr; + +end +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_applyClippingAlternative.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,109 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyClippingAlternative(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_applyClippingAlternative +% Date: 2013-04 +% Programmer: Sebastian Ewert +% +% Description: +% - applies clipping by over-normalising +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .clipAPercentageOfSamples = 1 - if set to zero a fixed number of +% samples will be clipped +% .parameter.percentOfSamples = 1 - used only if clipAPercentageOfSamples +% is 1 +% .parameter.numSamplesClipped = 1 - used only if clipAPercentageOfSamples +% is 0 +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output +% +% Output: +% f_audio_out - audio output signal +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'clipAPercentageOfSamples')==0 + parameter.clipAPercentageOfSamples = 1; +end +if isfield(parameter,'percentOfSamples')==0 + parameter.percentOfSamples = 1; +end +if isfield(parameter,'numSamplesClipped')==0 + parameter.numSamplesClipped = 10000; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +f_audio_out = []; +if ~isempty(f_audio) + sortedValues = sort(abs(f_audio(:))); + numSamples = length(sortedValues); + if parameter.clipAPercentageOfSamples + idxStartSample = round( (1-parameter.percentOfSamples/100) * numSamples); + divisor = min(sortedValues(idxStartSample:numSamples)); + else + if parameter.numSamplesClipped > numSamples + numSamplesClipped = numSamples; + else + numSamplesClipped = parameter.numSamplesClipped; + end + divisor = min(sortedValues(numSamples-numSamplesClipped+1:numSamples)); + end + clear sortedValues + + divisor = max(divisor,eps); + f_audio_out = f_audio / divisor; + + f_audio_out(f_audio_out < -1) = -1; + f_audio_out(f_audio_out > 1) = 1; + f_audio_out = f_audio_out * 0.999; + +end + +% This degradation does not impose a delay +timepositions_afterDegr = timepositions_beforeDegr; + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_applyDynamicRangeCompression.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,181 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyDynamicRangeCompression(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_applyDynamicRangeCompression +% Version: 1 +% Date: 2013-01-23 +% Programmer: Matthias Mauch, Sebastian Ewert +% +% Description: +% - applies dynamic range compression to a signal +% - f_audio_out is the compressed audio +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% samplingFreq - sampling frequency of f_audio +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .preNormalization = 0; % db for 95% RMS quantile / 0 means "off" +% .forgettingTime = 0.1; % seconds +% .compressorThreshold = -40; % dB +% .compressorSlope = 0.9; +% .attackTime = 0.01; % seconds +% .releaseTime = 0.01; % seconds +% .delayTime = 0.01; % seconds +% .normalizeOutputAudio = 1; +% +% Output: +% f_audio_out - audio output signal +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'preNormalization')==0 + parameter.preNormalization = 0; % db for 95% RMS quantile / 0 means "off" +end +if isfield(parameter,'forgettingTime')==0 + parameter.forgettingTime = 0.1; % seconds +end +if isfield(parameter,'compressorThreshold')==0 + parameter.compressorThreshold = -40; % dB +end +if isfield(parameter,'compressorSlope')==0 + parameter.compressorSlope = 0.9; +end +if isfield(parameter,'attackTime')==0 + parameter.attackTime = 0.01; % seconds +end +if isfield(parameter,'releaseTime')==0 + parameter.releaseTime = 0.01; % seconds +end +if isfield(parameter,'delayTime')==0 + parameter.delayTime = 0.01; % seconds +end +if isfield(parameter,'normalizeOutputAudio')==0 + parameter.normalizeOutputAudio = 1; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +f_audio_out = []; +if ~isempty(f_audio) + + %% secondary parameters + + AT = 1 - exp(-2.2/(samplingFreq*parameter.attackTime)); % attack parameter + RT = 1 - exp(-2.2/(samplingFreq*parameter.releaseTime)); % release parameter + FT = 1 - exp(-2.2/(samplingFreq*parameter.forgettingTime)); % forgetting parameter + + delay = floor(parameter.delayTime * samplingFreq); + + mono_audio = mean(f_audio, 2); + + if parameter.preNormalization < 0 + quantMeasured = max(quantile(abs(mono_audio), 0.95),eps); + quantWanted = db2mag(parameter.preNormalization); + f_audio = f_audio * quantWanted / quantMeasured; + mono_audio = mono_audio * quantWanted / quantMeasured; + end + + %% + + nSample = size(f_audio, 1); + nChannel = size(f_audio, 2); + + if AT == RT + % Vectorized version + %% + runningMS_all = filter(FT,[1 -(1-FT)],mono_audio.^2); + runningRMSdB_all = 10 * log10(runningMS_all); + gainDB_all = min([zeros(1,length(runningRMSdB_all));... + parameter.compressorSlope * (parameter.compressorThreshold - runningRMSdB_all(:)')]); + preGain_all = 10.^(gainDB_all/20); + gain_all = filter(AT,[1 -(1-AT)],[1/AT,preGain_all(2:end)]); + % The next line is equivalent to the behaviour of the serial version. Is that a bug? + %f_audio_out = repmat(gain_all(:),1,nChannel) .* [zeros(delay+1,nChannel);f_audio(1:end-(delay+1),:)]; + f_audio_out = repmat(gain_all(:),1,nChannel) .* [zeros(delay,nChannel);f_audio(1:end-delay,:)]; + else + % Serial version (The non-linearity 'if preGain < gain' does not seem to allow for a vectorization in all cases) + %% + runningMS = mono_audio(1)^2 * FT; + gain = 1; + buffer = zeros(delay + 1, nChannel); + f_audio_out = zeros(size(f_audio)); + + for iSample = 2:nSample + runningMS = ... + runningMS * (1-FT) +... + mono_audio(iSample)^2 * FT; + runningRMSdB = 10 * log10(runningMS); + + gainDB = min([0, ... + parameter.compressorSlope * (parameter.compressorThreshold - runningRMSdB)]); + preGain = 10^(gainDB/20); + + if preGain < gain % "gain" being old gain + coeff = AT; % we're in the attack phase + else + coeff = RT; % we're in the release phase + end + + % calculate new gain as mix of current gain (preGain) and old gain + gain = (1-coeff) * gain + coeff * preGain; + + f_audio_out(iSample, :) = gain * buffer(end,:); + if delay > 1 + buffer = [f_audio(iSample, :); buffer(1:end-1,:)]; + else + buffer = f_audio(iSample, :); + end + end + end + + if parameter.normalizeOutputAudio + f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); + end + +end + +% This degradation does impose a temporal distortion +timepositions_afterDegr = timepositions_beforeDegr + parameter.delayTime; + +end + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_applyHarmonicDistortion.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,88 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyHarmonicDistortion(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_applyHarmonicDistortion +% Version: 1 +% Date: 2013-01-25 +% Programmer: Matthias Mauch +% +% Description: +% - applies quadratic distortion to the audio +% - f_audio_out is the distorted audio +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .nApplications = 3 - number of iterative applications. The higher the +% stronger +% .normalizeOutputAudio = 1 - normalize audio +% +% Output: +% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number +% of channels +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'nApplications')==0 + parameter.nApplications = 3; +end +if isfield(parameter,'normalizeOutputAudio')==0 + parameter.normalizeOutputAudio = 1; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +f_audio_out = []; +if ~isempty(f_audio) + f_audio_out = f_audio; + for ii = 1:parameter.nApplications + f_audio_out = sin(f_audio_out * pi/2); + end + + if parameter.normalizeOutputAudio + f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); + end + +end + +% This degradation does not impose a delay +timepositions_afterDegr = timepositions_beforeDegr; + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_applyHighpassFilter.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,110 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyHighpassFilter(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_applyHighpassFilter +% Date: 2013-04 +% Programmer: Matthias Mauch +% +% Description: +% - applies a highpass filter to the audio +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .stopFrequency = 200 - stop band edge frequency in Hz +% .passFrequency = - pass band edge frequency in Hz, +% default is 2 x [stop band edge frequency] +% +% Output: +% f_audio_out - audio output signal +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'stopFrequency')==0 + parameter.stopFrequency = 200; +end +if isfield(parameter,'passFrequency')==0 + parameter.passFrequency = 2 * parameter.stopFrequency; +end + +if parameter.stopFrequency > parameter.passFrequency + error('Please choose a pass frequency greater than the stop frequency.'); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +f_audio_out = []; +if ~isempty(f_audio) + + omega_stop = parameter.stopFrequency / samplingFreq * 2 * pi; % stopband omega + omega_pass = parameter.passFrequency / samplingFreq * 2 * pi; % passband omega + transition_width = abs(omega_stop-omega_pass); + + lobe_width = 3.32; + filter_order = ceil(lobe_width*pi/transition_width); % filter order via transition bandwidth (see lecture) + + + filter_length = 2*filter_order + 1; + + n = 0:(filter_length-1); + omega_cutoff = (omega_stop+omega_pass)/2; % cutoff frequency is mean of pass and stopband edges + alpha = (filter_length-1)/2; + m = n - alpha; % symmetricised indices + + hd = -omega_cutoff/pi * sinc(omega_cutoff/pi*m); + hd(alpha+1) = hd(alpha+1) + 1; + + window = hamming(filter_length)'; + h = hd .* window; + + f_audio_out = fftfilt(h, [f_audio; zeros([filter_order, size(f_audio,2)])]); + f_audio_out = f_audio_out((filter_order + 1):end, :); + + + f_audio_out(f_audio_out < -1) = -1; + f_audio_out(f_audio_out > 1) = 1; + f_audio_out = f_audio_out * 0.999; + +end + +% This degradation has no delay. +timepositions_afterDegr = timepositions_beforeDegr; + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_applyImpulseResponse.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,197 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyImpulseResponse(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_applyImpulseResponse +% Date of Revision: 2013-04 +% Programmer: Sebastian Ewert +% +% Description: +% - applies an FIR filter +% - takes care that f_audio and firfilter use same sampling frequency +% - set samplingFreqFilter = samplingFreq if you do not which to resample +% the filter +% - predefines IR: 'GreatHall1','Classroom1','Octagon1', +% 'GoogleNexusOneFrontSpeaker','GoogleNexusOneFrontMic' +% 'VinylPlayer1960' +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% samplingFreq - sampling frequency of f_audio +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .presetIR = 'GreatHall1'; - load IR from a ADT preset +% .impulseResponse = []; - IR to apply +% .impulseResponseSampFreq = 0; - sampling rate of IR +% .normalizeOutputAudio = 1 - normalize output +% .normalizeImpulseResponse = 0 - l1-normalize firfilter before +% application +% +% Output: +% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% timepositions_afterDegr - time positions corresponding to timepositions_beforeDegr +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end +if isfield(parameter,'loadInternalIR')==0 + parameter.loadInternalIR = 1; +end +if isfield(parameter,'internalIR')==0 + parameter.internalIR = 'GreatHall1'; +end +if isfield(parameter,'normalizeOutputAudio')==0 + parameter.normalizeOutputAudio = 1; +end +if isfield(parameter,'normalizeImpulseResponse')==0 + parameter.normalizeImpulseResponse = 0; +end +if isfield(parameter,'impulseResponse')==0 + parameter.impulseResponse = []; +end +if isfield(parameter,'impulseResponseSampFreq')==0 + parameter.impulseResponseSampFreq = 0; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +if parameter.loadInternalIR + % load IR included in toolbox + + fullFilenameMfile = mfilename('fullpath'); + [pathstr,name,ext] = fileparts(fullFilenameMfile); + dirRootIRs = fullfile(pathstr,'../degradationData'); + + names_internalIR = {'GreatHall1','Classroom1','Octagon1','GoogleNexusOneFrontSpeaker','GoogleNexusOneFrontMic','VinylPlayer1960'}; + indexIR = find(strcmpi(names_internalIR,parameter.internalIR), 1); + if isempty(indexIR) + error('Please specify a valid preset') + end + + switch indexIR + case 1 + file = fullfile(dirRootIRs,'RoomResponses/GreatHall_Omni_x06y06.wav'); + case 2 + file = fullfile(dirRootIRs,'RoomResponses/Classroom_Omni_30x20y.wav'); + case 3 + file = fullfile(dirRootIRs,'RoomResponses/Octagon_Omni_x06y06.wav'); + case 4 + file = fullfile(dirRootIRs,'PhoneResponses/IR_GoogleNexusOneFrontSpeaker.wav'); + case 5 + file = fullfile(dirRootIRs,'PhoneResponses/IR_GoogleNexusOneFrontMic.wav'); + case 6 + file = fullfile(dirRootIRs,'VinylSim/ImpulseReponseVinylPlayer1960_smoothed.wav'); + end + [parameter.impulseResponse,parameter.impulseResponseSampFreq] = wavread(file); +end + +fs = samplingFreq; +h = parameter.impulseResponse; +fs_h = parameter.impulseResponseSampFreq; +h_org = h; + +f_audio_out = []; +if ~isempty(f_audio) + + if (size(h,2) > 1) && (size(h,1) ~= 1) + error('Multichannel impulse responses are not supported'); + end + + if fs ~= fs_h + h = resample(h,fs,fs_h); + end + + if parameter.normalizeImpulseResponse + h = h / max(abs(h)); + end + + f_audio_out = fftfilt(h,f_audio); + + if parameter.normalizeOutputAudio + f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); + end +end + +% This degradation does impose a delay +timepositions_afterDegr = []; +if ~isempty(timepositions_beforeDegr) + % approximation via group delay + + [Gd,W] = mygrpdelay(h_org,1,fs_h,2048); + %[Gd,W] = grpdelay(h_org,1,1024); % Matlab's own group delay function. Failt for some filters considerably. + + %figure; + %plot(W,Gd/samplingFreqFilter) + + averageOfGroupDelays = mean(Gd); + timeOffset_sec = averageOfGroupDelays / fs_h; + + timepositions_afterDegr = timepositions_beforeDegr + timeOffset_sec; +end + +end + +function [gd,w] = mygrpdelay(b,a,Fs,nfft) +% see also https://ccrma.stanford.edu/~jos/fp/Group_Delay_Computation_grpdelay_m.html + +b = b(:); +a = a(:); + +w=Fs*[0:nfft-1]/nfft; +oa = length(a)-1; % order of a(z) +oc = oa + length(b)-1; % order of c(z) +c = conv(b,fliplr(a)); % c(z) = b(z)*a(1/z)*z^(-oa) +cr = c.*[0:oc]'; % derivative of c wrt 1/z +num = fft(cr,nfft); +den = fft(c,nfft); +minmag = 10*eps; +polebins = find(abs(den)<minmag); +num(polebins) = 0; +den(polebins) = 1; +gd = real(num ./ den) - oa; + +ns = nfft/2; % Matlab convention - should be nfft/2 + 1 +gd = gd(1:ns); +w = w(1:ns); + +w = w(:); % Matlab returns column vectors +gd = gd(:); + +end + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_applyMp3Compression.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,197 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyMp3Compression(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_applyMp3Compression +% Date: 2013-01-22 +% Programmer: Sebastian Ewert +% +% Description: +% - encodes audio using mp3 +% - f_audio_out is the decoded version of that mp3 +% - uses lame for mp3 handling +% - some binaries for lame are provided. Under linux it additionally tries +% to find a binary installed on the system. +% - if no suitable lame can be found please install one and point +% parameter.LocationLameBinary to it +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% samplingFreq - sampling frequency of f_audio +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .LocationLameBinary - not set. Use to specify path to lame +% .LameOptions = '--preset cbr 128' - lame encoding options +% .deleteIntermediateFiles = 1 - delete temporary files +% +% Output: +% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number +% of channels +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'LocationLameBinary')==0 + fullFilenameMfile = mfilename('fullpath'); + [pathstr,name,ext] = fileparts(fullFilenameMfile); + if ispc + parameter.LocationLameBinary = fullfile(pathstr, '..\degradationData\Compressors\lame.exe'); + elseif isunix + if ismac + parameter.LocationLameBinary = fullfile(pathstr,'../degradationData/Compressors/lame.mac'); + else + % linux/unix + [status,result] = system('which lame'); + if status == 0 + parameter.LocationLameBinary = result; + else + parameter.LocationLameBinary = fullfile(pathstr, '../degradationData/Compressors/lame.linux'); + + [status,result] = system(parameter.LocationLameBinary); + if status > 1 + error(['Cannot find a valid lame binary. Possible solutions:',... + '1.) Install lame on your system using the package system. ',... + '2.) Compile a lame binary yourself and point parameter.LocationLameBinary ',... + 'to it. See also http://lame.sourceforge.net/']) + end + end + end + end + +else +end +if isfield(parameter,'compressionLevel')==0 + parameter.compressionLevel = 'strong'; % {'maximum','strong','medium','light','verylight'}; +end +if isfield(parameter,'LameOptions')==0 + parameter.LameOptions = []; % usually set via parameter.compressionLevel +end +if isfield(parameter,'deleteIntermediateFiles')==0 + parameter.deleteIntermediateFiles = 1; +end +if isfield(parameter,'normalizeOutputAudio')==0 + parameter.normalizeOutputAudio = 1; +end + +if ~exist(parameter.LocationLameBinary,'file') + error('audio_to_mp3: could not find Lame under %s .\n',parameter.LocationLameBinary); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +f_audio_out = []; +if ~isempty(f_audio) + + if isempty(parameter.LameOptions) + compressionLevels = {'maximum','strong','medium','light','verylight'}; + indexLevel = find(strcmpi(compressionLevels,parameter.compressionLevel), 1); + if isempty(indexLevel) + error('Please specify a valid preset') + end + + switch indexLevel + case 1 + parameter.LameOptions = '--preset cbr 32'; + case 2 + parameter.LameOptions = '--preset cbr 64'; + case 3 + parameter.LameOptions = '--preset cbr 128'; + case 4 + parameter.LameOptions = '--preset cbr 192'; + case 5 + parameter.LameOptions = '--preset cbr 256'; + end + end + + wavFilenameAndPath = [tempname,'.wav']; + [tempdir,wavFilename,wavExt] = fileparts(wavFilenameAndPath); + wavwrite(f_audio,samplingFreq,24,wavFilenameAndPath); + + mp3FilenameAndPath = [tempdir,'/',wavFilename,'.mp3']; + [status,result] = system(sprintf('"%s" %s "%s" "%s"',parameter.LocationLameBinary,parameter.LameOptions,... + wavFilenameAndPath, mp3FilenameAndPath)); + if status ~= 0 + warning(sprintf('There has been an error during the creation of %s. Error message:\n%s\n',mp3FilenameAndPath,result)); + end + if parameter.deleteIntermediateFiles + delete(wavFilenameAndPath); + end + + [status,result] = system(sprintf('"%s" --decode "%s" "%s"',parameter.LocationLameBinary,... + mp3FilenameAndPath,wavFilenameAndPath )); + if status ~= 0 + warning(sprintf('There has been an error during the creation of %s. Error message:\n%s\n',wavFilenameAndPath,result)); + end + if parameter.deleteIntermediateFiles + delete(mp3FilenameAndPath); + end + + try + [f_audio_out, fs,nbits] = wavread(wavFilenameAndPath); + catch % fix incorrect chunk size, see http://www.mathworks.com/support/solutions/en/data/1-1BZMF/index.html + warning('lame returned an ill-formed audio file. Trying to correct the file header...') + d = dir(wavFilenameAndPath); + fileSize = d.bytes; + fid=fopen(wavFilenameAndPath,'r+','l'); + fseek(fid,4,-1); + fwrite(fid,fileSize-8,'uint32'); + fseek(fid,40,-1); + fwrite(fid,fileSize-44,'uint32'); + fclose(fid); + [f_audio_out, fs,nbits] = wavread(wavFilenameAndPath); + end + + if parameter.deleteIntermediateFiles + delete(wavFilenameAndPath); + end + + if fs ~= samplingFreq + f_audio_out = resample(f_audio_out,samplingFreq,fs); + end + + if parameter.normalizeOutputAudio + f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); + end + +end + +% This degradation does not impose a delay. +% Note: Remark that MP3 does impose a delay on the encoder as well as on +% the decoder side. In case of lame, the decoder delay is the negative to +% the encoder delay so both cancel each other out. +timepositions_afterDegr = timepositions_beforeDegr; + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_applySpeedup.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,97 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_applySpeedup(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_applySpeedup +% Version: 1 +% Date: 2013-01-23 +% Programmer: Sebastian Ewert +% +% Description: +% - changes the playback speed of f_audio via resampling +% - change is specified in percent: +% total length of f_audio after the degradation is +% (100 - parameter.changeInPercent)/100 * originalLength +% - positive values lead to a speed-up, while negative values lead to a +% slow-down +% - Note: Frequencies are shifted to 100/(100 - parameter.changeInPercent), +% i.e. the default of parameter.changeInPercent = +3 shifts all +% frequencies by about half a semitone +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .changeInPercent = +3 - see description +% .normalizeOutputAudio = 1 - normalize output +% +% Output: +% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number +% of channels +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'changeInPercent')==0 + parameter.changeInPercent = +3; +end +if isfield(parameter,'normalizeOutputAudio')==0 + parameter.normalizeOutputAudio = 1; +end +if isfield(parameter,'maxProblemComplexity')==0 + % lower this if you run into 'reduce problem complexity' problems + parameter.maxProblemComplexity = 2^27; % limit defined in resample: 2^31, however, that is still too large +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +f_audio_out = []; +if ~isempty(f_audio) + Q = round(sqrt(parameter.maxProblemComplexity * 100 / (100 - parameter.changeInPercent))); + P = round(parameter.maxProblemComplexity / Q); + + f_audio_out = resample(f_audio,P,Q); + + if parameter.normalizeOutputAudio + f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); + end +end + +% This degradation does impose a temporal distortion +timepositions_afterDegr = (100 - parameter.changeInPercent)/100 * timepositions_beforeDegr; + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradationUnits/degradationUnit_applyWowResampling.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,176 @@ +function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyWowResampling(f_audio, samplingFreq, timepositions_beforeDegr, parameter) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: degradation_applyWowResampling +% Date of Revision: 2013-03 +% Programmer: Sebastian Ewert +% +% Description: +% - This is useful for wow and flutter simulations. +% - a playback speed of 1 is modulated by a cos signal via +% f(x) = a_m * cos(2*pi*f_m*x)+1 +% - the function mapping a position in the original recording +% to a position in the generated recording: +% F(x) = x + a_m * sin(2*pi*f_m*x) / (2*pi*f_m) +% - an optimal solution now would employ a sinc reconstruction of f_audio, +% sinc_fa, and sampling sinc_fa(F^-1(y)) equidistantly. +% - This implementation employs only an approximation by first upsampling +% f_audio and then sampling that using nearest neighbors +% +% Input: +% f_audio - audio signal \in [-1,1]^{NxC} with C being the number of +% channels +% samplingFreq - sampling frequency of f_audio +% timepositions_beforeDegr - some degradations delay the input signal. If +% some points in time are given via this +% parameter, timepositions_afterDegr will +% return the corresponding positions in the +% output. Set to [] if unavailable. Set f_audio +% and samplingFreq to [] to compute only +% timepositions_afterDegr. +% +% Input (optional): parameter +% .intensityOfChange = 1.5 - a_m = parameter.intensityOfChange/100; stay below 100 +% .frequencyOfChange = 0.5 - f_m +% .upsamplingFactor = 5 - the higher the better the quality (and the more memory) +% .normalizeOutputAudio = 0 - normalize audio +% +% Output: +% f_audio_out - audio signal \in [-1,1]^{NxC} with C being the number +% of channels +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<4 + parameter=[]; +end +if nargin<3 + timepositions_beforeDegr=[]; +end +if nargin<2 + error('Please specify input data'); +end + +if isfield(parameter,'intensityOfChange')==0 + parameter.intensityOfChange = 1.5; % a_m = parameter.intensityOfChange/100; %stay below 100 +end +if isfield(parameter,'frequencyOfChange')==0 + parameter.frequencyOfChange = 0.5; % f_m +end +if isfield(parameter,'upsamplingFactor')==0 + parameter.upsamplingFactor = 5; % the higher the better the quality (and the more memory) +end +if isfield(parameter,'normalizeOutputAudio')==0 + parameter.normalizeOutputAudio = 0; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Main program +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +fs = samplingFreq; +fsOverSampled = fs * parameter.upsamplingFactor; +a_m = parameter.intensityOfChange / 100; +f_m = parameter.frequencyOfChange; + +f_audio_out = f_audio; +if ~isempty(f_audio) + numSamples = size(f_audio,1); + numChannels = size(f_audio,2); + length_sec = numSamples/fs; + numFullPeriods = floor(length_sec * f_m); + numSamplesToWarp = round(numFullPeriods *fs / f_m); + + oldSamplePositions_to_newOversampledPositions = round(timeAssignment_newToOld([1:numSamplesToWarp]/fs,a_m,f_m)*fsOverSampled); + + for ch=1:numChannels + audioUpsampled = resample(f_audio(:,ch),parameter.upsamplingFactor,1); + + f_audio_out(1:numSamplesToWarp,ch) = audioUpsampled(oldSamplePositions_to_newOversampledPositions); + + clear audioUpsampled + end + + if parameter.normalizeOutputAudio + f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq); + end + +end + +%pitchShifted_semitones = getPitchShiftAtPositionsInNewFile([0:0.1:length_sec],a_m,f_m); % not used yet but might be useful later on + +%selftest(length_sec,a_m,f_m); + +% This degradation does impose a complex temporal distortion +timepositions_afterDegr = []; +if ~isempty(timepositions_beforeDegr) + timepositions_afterDegr = timeAssignment_oldToNew(timepositions_beforeDegr,a_m,f_m); +end + +end + + +function timeAssigned = timeAssignment_oldToNew(x,a_m,f_m) +% vectorized + +timeAssigned = x + a_m * sin(2*pi*f_m*x) / (2*pi*f_m); + +end + +function timeAssigned = timeAssignment_newToOld(y,a_m,f_m) +% vectorized +% SE: non linear equation: solved numerically (we are lucky: +% As G(x) := x - (F(x)-y) is a contraction for a_m<1 we can simply employ the Banach fixpoint theorem) + +timeAssigned = y; +for k=1:40 + timeAssigned = y - a_m * sin(2*pi*f_m*timeAssigned) / (2*pi*f_m); +end + +end + +function pitchShifted_semitones = getPitchShiftAtPositionsInNewFile(y,a_m,f_m) +% vectorized + +% maps times from new to old and takes a look at the value of the derivative +% there + +timeAssigned = timeAssignment_newToOld(y,a_m,f_m); + +derivative = 1 + a_m * cos(2*pi*f_m*timeAssigned); + +pitchShifted_semitones = log2(1./derivative)*12; + +end + +function selftest(length_sec,a_m,f_m) + +x0 = rand(10000,1) * length_sec; + +timeAssigned1 = timeAssignment_oldToNew(x0,a_m,f_m); +timeAssigned2 = timeAssignment_newToOld(timeAssigned1,a_m,f_m); + +figure; +plot(x0 - timeAssigned2); + +end + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradations/ISMIR2013Degradations/liveRecording.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,43 @@ +function degradation_config = liveRecording() +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Preset: liveRecording +% Date of Revision: 2013-04 +% Programmer: Sebastian Ewert +% +% Description: +% - this degradation preset employs +% * degradation_applyFirFilter to apply a room impulse response +% * degradation_addNoise to add light noise (preset is pink noise at 45db SNR) +% * adthelper_normalizeAudio to normalize the output audio +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +degradation_config(1).methodname = 'degradationUnit_applyImpulseResponse'; +degradation_config(1).parameter.loadInternalIR = 1; +degradation_config(1).parameter.internalIR = 'GreatHall1'; + +degradation_config(2).methodname = 'degradationUnit_addNoise'; +degradation_config(2).parameter.snrRatio = 40; % in dB +degradation_config(2).parameter.noiseColor = 'pink'; + +degradation_config(3).methodname = 'adthelper_normalizeAudio'; + +end + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradations/ISMIR2013Degradations/pubEnvironment.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,40 @@ +function degradation_config = pubEnvironment() +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Preset: pubEnvironment +% Date of Revision: 2013-04 +% Programmer: Sebastian Ewert +% +% Description: +% - this degradation preset employs +% * degradation_addSound to add some sounds originating from a real +% pub environment +% * adthelper_normalizeAudio to normalize the output audio +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +degradation_config(1).methodname = 'degradationUnit_addSound'; +degradation_config(1).parameter.loadInternalSound = 1; +degradation_config(1).parameter.internalSound = 'PubEnvironment1'; +degradation_config(1).parameter.snrRatio = 15; % in dB + +degradation_config(2).methodname = 'adthelper_normalizeAudio'; + +end + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradations/ISMIR2013Degradations/radioBroadcast.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,44 @@ +function degradation_config = radioBroadcast() +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Preset: radioBroadcast +% Date of Revision: 2013-04 +% Programmer: Sebastian Ewert +% +% Description: +% - this degradation preset employs +% * degradation_applyDynamicRangeCompression +% * degradation_applySpeedup to simulate the increased playback speed +% radio station often use +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +degradation_config(1).methodname = 'degradationUnit_applyDynamicRangeCompression'; +degradation_config(1).parameter.forgettingTime = 0.3; % seconds +degradation_config(1).parameter.compressorThreshold = -40; % dB +degradation_config(1).parameter.compressorSlope = 0.6; +degradation_config(1).parameter.attackTime = 0.2; % seconds +degradation_config(1).parameter.releaseTime = 0.2; % seconds +degradation_config(1).parameter.delayTime = 0.2; % seconds + +degradation_config(2).methodname = 'degradationUnit_applySpeedup'; +degradation_config(2).parameter.changeInPercent = +2; + +degradation_config(3).methodname = 'adthelper_normalizeAudio'; + +end + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradations/ISMIR2013Degradations/smartPhonePlayback.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,46 @@ +function degradation_config = smartPhonePlayback() +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Preset: smartPhonePlayback +% Date of Revision: 2013-04 +% Programmer: Sebastian Ewert +% +% Description: +% - simulating a user playing a song on this mobile phone +% - this degradation preset employs +% * degradation_applyImpulseResponse to apply an impulse response taken from +% the speaker of a typical smart phone +% * degradation_addNoise to add noise (preset is light pink noise at 40db SNR) +% - note that due to the size of speakers in a phone the speaker often +% cannot play bass sounds. This cut-off can be as high as 400-600 Hz. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +degradation_config(1).methodname = 'degradationUnit_applyImpulseResponse'; +degradation_config(1).parameter.loadInternalIR = 1; +degradation_config(1).parameter.internalIR = 'GoogleNexusOneFrontSpeaker'; + +degradation_config(2).methodname = 'degradationUnit_addNoise'; +degradation_config(2).parameter.snrRatio = 40; % in dB +degradation_config(2).parameter.noiseColor = 'pink'; + +degradation_config(3).methodname = 'adthelper_normalizeAudio'; + +end + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradations/ISMIR2013Degradations/smartPhoneRecording.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,66 @@ +function degradation_config = smartPhoneRecording() +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Preset: radioBroadcast +% Date of Revision: 2013-04 +% Programmer: Sebastian Ewert +% +% Description: +% - simulating a user holding a phone in front of a speaker +% - this degradation preset employs +% * degradation_applyFirFilter to apply an impulse response taken from +% the mic of a typical smart phone (Google Nexus One) +% * degradation_applyDynamicRangeCompression to simulate the phone's auto-gain +% * degradation_applyClippingAlternative to apply some clipping +% * degradation_addNoise to add noise (preset is light pink noise) +% - note that the impulse responses for the phones were not recorded in a +% perfect unechoic chamber but in a normal studio environment. Therefore, +% the studio's room response is mixed in (acceptable considering the goal +% of this simulation) +% - note that many (early) UMTS/3G phones employ DSPs cutting of +% frequencies above 8kHz even for normal recordings (i.e. without +% transmitting the signal over the network). +% GSM/2G phones usually even cut at 4kHz. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +degradation_config(1).methodname = 'degradationUnit_applyImpulseResponse'; +degradation_config(1).parameter.loadInternalIR = 1; +degradation_config(1).parameter.internalIR = 'GoogleNexusOneFrontMic'; + +degradation_config(2).methodname = 'degradationUnit_applyDynamicRangeCompression'; +degradation_config(2).parameter.forgettingTime = 0.2; % seconds +degradation_config(2).parameter.compressorThreshold = -35; % dB +degradation_config(2).parameter.compressorSlope = 0.5; +degradation_config(2).parameter.attackTime = 0.01; % seconds +degradation_config(2).parameter.releaseTime = 0.01; % seconds +degradation_config(2).parameter.delayTime = 0.01; % seconds + +degradation_config(3).methodname = 'degradationUnit_applyClippingAlternative'; +degradation_config(3).parameter.percentOfSamplesClipped = 0.3; + +degradation_config(4).methodname = 'degradationUnit_addNoise'; +degradation_config(4).parameter.snrRatio = 35; % in dB +degradation_config(4).parameter.noiseColor = 'pink'; + +degradation_config(5).methodname = 'adthelper_normalizeAudio'; + + +end + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradations/ISMIR2013Degradations/strongMp3Compression.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,33 @@ +function degradation_config = strongMp3Compression() +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Preset: strongMp3Compression +% Date of Revision: 2013-04 +% Programmer: Sebastian Ewert +% +% Description: +% - this degradation preset employs +% * degradation_applyMp3Compression with a strong compression level +% * adthelper_normalizeAudio to normalize the output audio +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +degradation_config(1).methodname = 'degradationUnit_applyMp3Compression'; +degradation_config(1).parameter.compressionLevel = 'strong'; + +degradation_config(2).methodname = 'adthelper_normalizeAudio'; + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradations/ISMIR2013Degradations/vinylRecording.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,60 @@ +function degradation_config = vinylRecording() +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Preset: vinylRecording +% Date of Revision: 2013-04 +% Programmer: Sebastian Ewert +% +% Description: +% - this degradation preset employs +% * degradation_applyFirFilter to apply an impulse response taken from a +% vinyl player +% * degradation_addSound to add some sounds originating from the player +% mechanics +% * degradation_applyWowResampling to simulate wow-and-flutter +% * degradation_addNoise to add noise (preset is light pink noise at 40db SNR) +% * adthelper_normalizeAudio to normalize the output audio +% - First, applies an impulse response taken from a vinyl player +% - Then, a recording of cranking sounds (dust, mechanical noise,...) is +% added +% - then some light pink noise is added +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +degradation_config(1).methodname = 'degradationUnit_applyImpulseResponse'; +degradation_config(1).parameter.loadInternalIR = 1; +degradation_config(1).parameter.internalIR = 'VinylPlayer1960'; + +degradation_config(2).methodname = 'degradationUnit_addSound'; +degradation_config(2).parameter.loadInternalSound = 1; +degradation_config(2).parameter.internalSound = 'OldDustyRecording'; +degradation_config(2).parameter.snrRatio = 40; % in dB + +degradation_config(3).methodname = 'degradationUnit_applyWowResampling'; +degradation_config(3).parameter.intensityOfChange = 1.3; +degradation_config(3).parameter.frequencyOfChange = 33/60; % vinyl at 33 rpm + +degradation_config(4).methodname = 'degradationUnit_addNoise'; +degradation_config(4).parameter.snrRatio = 40; % in dB +degradation_config(4).parameter.noiseColor = 'pink'; + +degradation_config(5).methodname = 'adthelper_normalizeAudio'; + +end + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AudioDegradationToolbox/degradations/StrongUnitDegradations/unit_addSound.m Thu Oct 24 20:26:35 2013 +0100 @@ -0,0 +1,33 @@ +function degradation_config = addSound() +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Preset: addSound +% Programmer: Matthias Mauch +% +% Description: +% Parametrisation of the Degradation Unit of the same name +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +degradation_config(1).methodname = 'degradationUnit_addSound'; +degradation_config(1).parameter.snrRatio = 10; % in dB +degradation_config(1).parameter.loadInternalSound = 1; +degradation_config(1).parameter.internalSound = 'PubEnvironment1'; + +degradation_config(2).methodname = 'adthelper_normalizeAudio'; + + +end \ No newline at end of file
--- a/AudioDegradationToolbox/degradations/liveRecording.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -function degradation_config = liveRecording() -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Preset: liveRecording -% Date of Revision: 2013-04 -% Programmer: Sebastian Ewert -% -% Description: -% - this degradation preset employs -% * degradation_applyFirFilter to apply a room impulse response -% * degradation_addNoise to add light noise (preset is pink noise at 45db SNR) -% * adthelper_normalizeAudio to normalize the output audio -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -degradation_config(1).methodname = 'degradationUnit_applyImpulseResponse'; -degradation_config(1).parameter.loadInternalIR = 1; -degradation_config(1).parameter.internalIR = 'GreatHall1'; - -degradation_config(2).methodname = 'degradationUnit_addNoise'; -degradation_config(2).parameter.snrRatio = 40; % in dB -degradation_config(2).parameter.noiseColor = 'pink'; - -degradation_config(3).methodname = 'adthelper_normalizeAudio'; - -end - - - -
--- a/AudioDegradationToolbox/degradations/pubEnvironment.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -function degradation_config = pubEnvironment() -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Preset: pubEnvironment -% Date of Revision: 2013-04 -% Programmer: Sebastian Ewert -% -% Description: -% - this degradation preset employs -% * degradation_addSound to add some sounds originating from a real -% pub environment -% * adthelper_normalizeAudio to normalize the output audio -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -degradation_config(1).methodname = 'degradationUnit_addSound'; -degradation_config(1).parameter.loadInternalSound = 1; -degradation_config(1).parameter.internalSound = 'PubEnvironment1'; -degradation_config(1).parameter.snrRatio = 15; % in dB - -degradation_config(2).methodname = 'adthelper_normalizeAudio'; - -end - - - -
--- a/AudioDegradationToolbox/degradations/radioBroadcast.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -function degradation_config = radioBroadcast() -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Preset: radioBroadcast -% Date of Revision: 2013-04 -% Programmer: Sebastian Ewert -% -% Description: -% - this degradation preset employs -% * degradation_applyDynamicRangeCompression -% * degradation_applySpeedup to simulate the increased playback speed -% radio station often use -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -degradation_config(1).methodname = 'degradationUnit_applyDynamicRangeCompression'; -degradation_config(1).parameter.forgettingTime = 0.3; % seconds -degradation_config(1).parameter.compressorThreshold = -40; % dB -degradation_config(1).parameter.compressorSlope = 0.6; -degradation_config(1).parameter.attackTime = 0.2; % seconds -degradation_config(1).parameter.releaseTime = 0.2; % seconds -degradation_config(1).parameter.delayTime = 0.2; % seconds - -degradation_config(2).methodname = 'degradationUnit_applySpeedup'; -degradation_config(2).parameter.changeInPercent = +2; - -degradation_config(3).methodname = 'adthelper_normalizeAudio'; - -end - -
--- a/AudioDegradationToolbox/degradations/smartPhonePlayback.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -function degradation_config = smartPhonePlayback() -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Preset: smartPhonePlayback -% Date of Revision: 2013-04 -% Programmer: Sebastian Ewert -% -% Description: -% - simulating a user playing a song on this mobile phone -% - this degradation preset employs -% * degradation_applyImpulseResponse to apply an impulse response taken from -% the speaker of a typical smart phone -% * degradation_addNoise to add noise (preset is light pink noise at 40db SNR) -% - note that due to the size of speakers in a phone the speaker often -% cannot play bass sounds. This cut-off can be as high as 400-600 Hz. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -degradation_config(1).methodname = 'degradationUnit_applyImpulseResponse'; -degradation_config(1).parameter.loadInternalIR = 1; -degradation_config(1).parameter.internalIR = 'GoogleNexusOneFrontSpeaker'; - -degradation_config(2).methodname = 'degradationUnit_addNoise'; -degradation_config(2).parameter.snrRatio = 40; % in dB -degradation_config(2).parameter.noiseColor = 'pink'; - -degradation_config(3).methodname = 'adthelper_normalizeAudio'; - -end - - - -
--- a/AudioDegradationToolbox/degradations/smartPhoneRecording.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -function degradation_config = smartPhoneRecording() -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Preset: radioBroadcast -% Date of Revision: 2013-04 -% Programmer: Sebastian Ewert -% -% Description: -% - simulating a user holding a phone in front of a speaker -% - this degradation preset employs -% * degradation_applyFirFilter to apply an impulse response taken from -% the mic of a typical smart phone (Google Nexus One) -% * degradation_applyDynamicRangeCompression to simulate the phone's auto-gain -% * degradation_applyClippingAlternative to apply some clipping -% * degradation_addNoise to add noise (preset is light pink noise) -% - note that the impulse responses for the phones were not recorded in a -% perfect unechoic chamber but in a normal studio environment. Therefore, -% the studio's room response is mixed in (acceptable considering the goal -% of this simulation) -% - note that many (early) UMTS/3G phones employ DSPs cutting of -% frequencies above 8kHz even for normal recordings (i.e. without -% transmitting the signal over the network). -% GSM/2G phones usually even cut at 4kHz. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -degradation_config(1).methodname = 'degradationUnit_applyImpulseResponse'; -degradation_config(1).parameter.loadInternalIR = 1; -degradation_config(1).parameter.internalIR = 'GoogleNexusOneFrontMic'; - -degradation_config(2).methodname = 'degradationUnit_applyDynamicRangeCompression'; -degradation_config(2).parameter.forgettingTime = 0.2; % seconds -degradation_config(2).parameter.compressorThreshold = -35; % dB -degradation_config(2).parameter.compressorSlope = 0.5; -degradation_config(2).parameter.attackTime = 0.01; % seconds -degradation_config(2).parameter.releaseTime = 0.01; % seconds -degradation_config(2).parameter.delayTime = 0.01; % seconds - -degradation_config(3).methodname = 'degradationUnit_applyClippingAlternative'; -degradation_config(3).parameter.percentOfSamplesClipped = 0.3; - -degradation_config(4).methodname = 'degradationUnit_addNoise'; -degradation_config(4).parameter.snrRatio = 35; % in dB -degradation_config(4).parameter.noiseColor = 'pink'; - -degradation_config(5).methodname = 'adthelper_normalizeAudio'; - - -end - - - -
--- a/AudioDegradationToolbox/degradations/strongMp3Compression.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -function degradation_config = strongMp3Compression() -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Preset: strongMp3Compression -% Date of Revision: 2013-04 -% Programmer: Sebastian Ewert -% -% Description: -% - this degradation preset employs -% * degradation_applyMp3Compression with a strong compression level -% * adthelper_normalizeAudio to normalize the output audio -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -degradation_config(1).methodname = 'degradationUnit_applyMp3Compression'; -degradation_config(1).parameter.compressionLevel = 'strong'; - -degradation_config(2).methodname = 'adthelper_normalizeAudio'; - -end
--- a/AudioDegradationToolbox/degradations/vinylRecording.m Wed Aug 21 19:18:46 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -function degradation_config = vinylRecording() -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Preset: vinylRecording -% Date of Revision: 2013-04 -% Programmer: Sebastian Ewert -% -% Description: -% - this degradation preset employs -% * degradation_applyFirFilter to apply an impulse response taken from a -% vinyl player -% * degradation_addSound to add some sounds originating from the player -% mechanics -% * degradation_applyWowResampling to simulate wow-and-flutter -% * degradation_addNoise to add noise (preset is light pink noise at 40db SNR) -% * adthelper_normalizeAudio to normalize the output audio -% - First, applies an impulse response taken from a vinyl player -% - Then, a recording of cranking sounds (dust, mechanical noise,...) is -% added -% - then some light pink noise is added -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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. -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -degradation_config(1).methodname = 'degradationUnit_applyImpulseResponse'; -degradation_config(1).parameter.loadInternalIR = 1; -degradation_config(1).parameter.internalIR = 'VinylPlayer1960'; - -degradation_config(2).methodname = 'degradationUnit_addSound'; -degradation_config(2).parameter.loadInternalSound = 1; -degradation_config(2).parameter.internalSound = 'OldDustyRecording'; -degradation_config(2).parameter.snrRatio = 40; % in dB - -degradation_config(3).methodname = 'degradationUnit_applyWowResampling'; -degradation_config(3).parameter.intensityOfChange = 1.3; -degradation_config(3).parameter.frequencyOfChange = 33/60; % vinyl at 33 rpm - -degradation_config(4).methodname = 'degradationUnit_addNoise'; -degradation_config(4).parameter.snrRatio = 40; % in dB -degradation_config(4).parameter.noiseColor = 'pink'; - -degradation_config(5).methodname = 'adthelper_normalizeAudio'; - -end - - - -
--- a/demo_batchProcessing.m Wed Aug 21 19:18:46 2013 +0100 +++ b/demo_batchProcessing.m Thu Oct 24 20:26:35 2013 +0100 @@ -18,7 +18,7 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -addpath(fullfile(pwd,'AudioDegradationToolbox')); +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 @@ -39,6 +39,17 @@ % destination directory outputDirectory = 'demoOutput/'; +% desired degradations +degradationnames = {'liveRecording', ... + 'pubEnvironment', ... + 'radioBroadcast', ... + 'smartPhonePlayback', ... + 'smartPhoneRecording', ... + 'strongMp3Compression', ... + 'vinylRecording', ... + 'unit_addSound', ... + 'unit_addNoise'}; +nDegradation = length(degradationnames); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -106,85 +117,21 @@ remainingColumns = data{2}; end - % Start the degradation process + % apply degradations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - degradationname = 'liveRecording'; - 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)); + 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 - if ~isempty(csvfilename) - writeCsvFile(fullfile(PathToOutput,csvfilename),timepositions_afterDegr,remainingColumns); - end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - degradationname = 'strongMp3Compression'; - 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 - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - degradationname = 'vinylRecording'; - 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 - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - degradationname = 'radioBroadcast'; - 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 - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - degradationname = 'smartPhoneRecording'; - 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 - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - degradationname = 'smartPhonePlayback'; - 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
--- a/listOfFiles.txt Wed Aug 21 19:18:46 2013 +0100 +++ b/listOfFiles.txt Thu Oct 24 20:26:35 2013 +0100 @@ -1,5 +1,7 @@ -testdata/472TNA3M_snippet.wav -testdata/clarinet.wav -testdata/p009m_drum.wav -testdata/RWC-C08.wav ; testdata/RWC-C08.csv -testdata/p009m_drum.csv \ No newline at end of file +testdata/RWC_G39.wav +testdata/RWC_G72.wav +testdata/RWC_G84.wav +testdata/RWC_P009m_drum.wav +testdata/RWC-C08.wav +testdata/session5-faure_elegie2c-001-0.wav +testdata/175234__kenders2000__nonsense-sentence.wav \ No newline at end of file