matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: % Audio Degradation Toolbox matthiasm@0: % matthiasm@0: % Centre for Digital Music, Queen Mary University of London. matthiasm@0: % This file copyright 2013 Sebastian Ewert, Matthias Mauch and QMUL. SebastianEwert@4: % matthiasm@0: % This program is free software; you can redistribute it and/or matthiasm@0: % modify it under the terms of the GNU General Public License as matthiasm@0: % published by the Free Software Foundation; either version 2 of the matthiasm@0: % License, or (at your option) any later version. See the file matthiasm@0: % COPYING included with this distribution for more information. matthiasm@0: % matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: matthiasm@0: % Note: Some degradations impose a delay/temporal distortion on the input matthiasm@0: % data. The last example shows, given time positions before the matthiasm@0: % degradation, how the corresponding time positions after the degradation matthiasm@0: % can be retrieved matthiasm@0: matthiasm@0: %% matthiasm@0: matthiasm@0: clear SebastianEwert@4: close all matthiasm@0: matthiasm@23: addpath(genpath(fullfile(pwd,'AudioDegradationToolbox'))); matthiasm@0: matthiasm@0: pathOutputDemo = 'demoOutput/'; matthiasm@0: if ~exist(pathOutputDemo,'dir'), mkdir(pathOutputDemo); end matthiasm@0: SebastianEwert@4: filenames = { SebastianEwert@4: 'testdata/RWC_G39.wav'; SebastianEwert@4: 'testdata/RWC_G72.wav'; SebastianEwert@4: 'testdata/RWC_G84.wav'; SebastianEwert@4: 'testdata/RWC_P009m_drum.wav'; SebastianEwert@4: 'testdata/RWC-C08.wav'; matthiasm@7: 'testdata/session5-faure_elegie2c-001-0.wav'; matthiasm@7: 'testdata/175234__kenders2000__nonsense-sentence.wav'; SebastianEwert@4: }; matthiasm@0: matthiasm@9: createSpectrograms = 0; matthiasm@0: matthiasm@0: %% SebastianEwert@4: % just copying original files to the demo folder SebastianEwert@5: maxValueRangeVis = zeros(length(filenames)); SebastianEwert@4: for k=1:length(filenames) SebastianEwert@4: copyfile(filenames{k}, fullfile(pathOutputDemo,sprintf('00_Original_file%d.wav',k))) SebastianEwert@4: if createSpectrograms SebastianEwert@4: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@4: [s,f,t] = spectrogram(f_audio,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@4: figure; imagesc(t,f,log10(abs(s)+1)); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('00_Original_file%d.png',k))) SebastianEwert@5: maxValueRangeVis(k) = max(max(log10(abs(s)+1))); SebastianEwert@4: end SebastianEwert@4: end matthiasm@0: matthiasm@0: %% SebastianEwert@4: for k=1:length(filenames) SebastianEwert@4: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@4: SebastianEwert@4: % with default settings: SebastianEwert@4: %f_audio_out = degradationUnit_addNoise(f_audio, samplingFreq); SebastianEwert@4: SebastianEwert@4: % adjusting some parameters: SebastianEwert@4: parameter.snrRatio = 10; % in dB SebastianEwert@4: parameter.noiseColor = 'pink'; % convenient access to several noise types SebastianEwert@4: f_audio_out = degradationUnit_addNoise(f_audio, samplingFreq, [], parameter); SebastianEwert@4: SebastianEwert@4: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_01_addNoise_file%d.wav',k))); SebastianEwert@4: if createSpectrograms SebastianEwert@4: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@5: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_01_addNoise_file%d.png',k))) SebastianEwert@4: end SebastianEwert@4: end matthiasm@0: matthiasm@0: %% matthiasm@0: % Some degradations delay the input signal. If some timepositions are given matthiasm@0: % via timepositions_beforeDegr, the corresponding positions will be returned SebastianEwert@4: % in timepositions_afterDegr. matthiasm@0: timepositions_beforeDegr = [2, 3]; matthiasm@0: matthiasm@0: % Processing the time positions even works without processing the audio data (f_audio_out is empty afterwards) SebastianEwert@4: parameter.loadInternalIR = 0; SebastianEwert@4: parameter.impulseResponse = [1 -1 1 -1 1 -1 ] / 6; % some impulse response SebastianEwert@4: parameter.impulseResponseSampFreq = samplingFreq; matthiasm@0: parameter.normalizeOutputAudio = 1; matthiasm@0: [f_audio_out,timepositions_afterDegr] = degradationUnit_applyImpulseResponse([], [], timepositions_beforeDegr, parameter); matthiasm@0: SebastianEwert@4: for k=1:length(filenames) SebastianEwert@4: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@4: SebastianEwert@4: % time positions and audio can also be processed at the same time: SebastianEwert@4: [f_audio_out,timepositions_afterDegr] = degradationUnit_applyImpulseResponse(f_audio, samplingFreq, timepositions_beforeDegr, parameter); SebastianEwert@4: fprintf('degradation_applyFirFilter: adjusting time positions\n'); SebastianEwert@4: for m=1:length(timepositions_afterDegr) fprintf('%g -> %g\n',timepositions_beforeDegr(m),timepositions_afterDegr(m)); end SebastianEwert@4: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_02_applyImpulseResponse_file%d.wav',k))); SebastianEwert@4: if createSpectrograms SebastianEwert@4: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_02_applyImpulseResponse_file%d.png',k))) SebastianEwert@4: end SebastianEwert@4: end; matthiasm@0: SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: parameter.snrRatio = 10; % in dB SebastianEwert@28: parameter.loadInternalSound = 1; SebastianEwert@28: parameter.internalSound = 'PubEnvironment1'; SebastianEwert@28: f_audio_out = degradationUnit_addSound(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_03_addSound_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_03_addSound_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: parameter.dsFrequency = 4000; SebastianEwert@28: f_audio_out = degradationUnit_applyAliasing(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_04_applyAliasing_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_04_applyAliasing_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: parameter.percentOfSamples = 10; % signal is scaled so that n% of samples clip SebastianEwert@28: f_audio_out = degradationUnit_applyClippingAlternative(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_05_applyClipping_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_05_applyClipping_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: parameter.compressorSlope = 0.9; SebastianEwert@28: parameter.normalizeOutputAudio = 1; SebastianEwert@28: f_audio_out = degradationUnit_applyDynamicRangeCompression(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_06_applyDynamicRangeCompression_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_06_applyDynamicRangeCompression_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: parameter.nApplications = 5; SebastianEwert@28: f_audio_out = degradationUnit_applyHarmonicDistortion(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_07_applyHarmonicDistortion_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_07_applyHarmonicDistortion_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: parameter.LameOptions = '--preset cbr 32'; SebastianEwert@28: f_audio_out = degradationUnit_applyMp3Compression(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_08_applyMp3Compression_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_08_applyMp3Compression_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: parameter.changeInPercent = +5; SebastianEwert@28: f_audio_out = degradationUnit_applySpeedup(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_09_applySpeedup_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_09_applySpeedup_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: parameter.intensityOfChange = 3; SebastianEwert@28: parameter.frequencyOfChange = 0.5; SebastianEwert@28: f_audio_out = degradationUnit_applyWowResampling(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_10_applyWowResampling_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_10_applyWowResampling_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: parameter.stopFrequency = 1000; SebastianEwert@28: f_audio_out = degradationUnit_applyHighpassFilter(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_11_applyHighpassFilter_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_11_applyHighpassFilter_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: parameter.stopFrequency = 1000; SebastianEwert@28: f_audio_out = degradationUnit_applyLowpassFilter(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_12_applyLowpassFilter_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_12_applyLowpassFilter_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: SebastianEwert@28: SebastianEwert@28: %% SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: % There are four ways to specify the destination mean spectrum: 1. by SebastianEwert@28: % loading example files provided with the toolbox, 2. by using specific SebastianEwert@28: % noise "color" profiles, 3. by providing the destination mean spectrum SebastianEwert@28: % using the parameter destMagFreqResp, 4. by providing audio data from SebastianEwert@28: % which the destination mean spectrum is computed. SebastianEwert@28: parameter.loadInternalMagFreqResp = 1; SebastianEwert@28: parameter.internalMagFreqResp = 'Beethoven_Appasionata_Rwc'; SebastianEwert@28: f_audio_out = degradationUnit_adaptiveEqualizer(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_13_adaptiveEqualizer_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_13_adaptiveEqualizer_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end; SebastianEwert@28: SebastianEwert@28: %% SebastianEwert@28: if 1 SebastianEwert@28: for k=1:length(filenames) SebastianEwert@28: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@28: SebastianEwert@28: [parameter.audioDataForDestMfcc,parameter.audioDataForDestMfcc_sf]=wavread('testdata/RWC_P009m_drum.wav'); SebastianEwert@28: SebastianEwert@28: % After this unit, the mean MFCC vector of f_audio_out is almost identical to SebastianEwert@28: % the one of RWC_P009m_drum.wav SebastianEwert@28: parameter.visualizations = createSpectrograms; SebastianEwert@28: f_audio_out = degradationUnit_applyMfccMeanAdaption(f_audio, samplingFreq, [], parameter); SebastianEwert@28: SebastianEwert@28: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Unit_14_applyMfccMeanAdaption_file%d.wav',k))); SebastianEwert@28: if createSpectrograms SebastianEwert@28: [s,f,t] = spectrogram(f_audio_out,hamming(round(samplingFreq*0.093)),round(samplingFreq*0.093/2),[],samplingFreq); SebastianEwert@28: figure; imagesc(t,f,log10(abs(s)+1),[0 maxValueRangeVis(k)]); axis xy; colormap(hot); ylim([0,8000]); colorbar; print('-dpng', fullfile(pathOutputDemo,sprintf('Unit_14_applyMfccMeanAdaption_file%d.png',k))) SebastianEwert@28: end SebastianEwert@28: end SebastianEwert@28: end SebastianEwert@28: SebastianEwert@28: SebastianEwert@28: