matthiasm@0: matthiasm@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matthiasm@0: % Audio Degradation Toolbox matthiasm@0: % matthiasm@0: % Centre for Digital Music, Queen Mary University of London. matthiasm@0: % This file copyright 2013 Sebastian Ewert, Matthias Mauch and QMUL. 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 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: f_audio_out = applyDegradation('liveRecording', f_audio, samplingFreq); SebastianEwert@4: SebastianEwert@4: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Degr_01_liveRecording_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('Degr_01_liveRecording_file%d.png',k))) 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: f_audio_out = applyDegradation('strongMp3Compression', f_audio, samplingFreq); SebastianEwert@4: SebastianEwert@4: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Degr_02_strongMp3Compression_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('Degr_02_strongMp3Compression_file%d.png',k))) 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: f_audio_out = applyDegradation('vinylRecording', f_audio, samplingFreq); SebastianEwert@4: SebastianEwert@4: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Degr_03_vinylRecording_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('Degr_03_vinylRecording_file%d.png',k))) 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: f_audio_out = applyDegradation('radioBroadcast', f_audio, samplingFreq); SebastianEwert@4: SebastianEwert@4: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Degr_04_radioBroadcast_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('Degr_04_radioBroadcast_file%d.png',k))) SebastianEwert@4: end SebastianEwert@4: end matthiasm@0: SebastianEwert@4: %% SebastianEwert@4: for k=1:length(filenames) SebastianEwert@4: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@4: SebastianEwert@4: f_audio_out = applyDegradation('smartPhoneRecording', f_audio, samplingFreq); SebastianEwert@4: SebastianEwert@4: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Degr_05_smartPhoneRecording_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('Degr_05_smartPhoneRecording_file%d.png',k))) SebastianEwert@4: end SebastianEwert@4: end matthiasm@0: SebastianEwert@4: %% SebastianEwert@4: for k=1:length(filenames) SebastianEwert@4: [f_audio,samplingFreq]=wavread(filenames{k}); SebastianEwert@4: SebastianEwert@4: f_audio_out = applyDegradation('smartPhonePlayback', f_audio, samplingFreq); SebastianEwert@4: SebastianEwert@4: wavwrite(f_audio_out,samplingFreq,16,fullfile(pathOutputDemo,sprintf('Degr_06_smartPhonePlayback_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('Degr_06_smartPhonePlayback_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 matthiasm@0: % in timepositions_afterDegr. In this case, there is no need for f_audio matthiasm@0: % and samplingFreq as above but they could be specified too. matthiasm@0: timepositions_beforeDegr = [5, 60]; matthiasm@0: [~,timepositions_afterDegr] = applyDegradation('radioBroadcast', [], [], timepositions_beforeDegr); matthiasm@0: fprintf('radioBroadcast: corresponding positions:\n'); matthiasm@0: for k=1:length(timepositions_beforeDegr) fprintf('%g -> %g\n',timepositions_beforeDegr(k),timepositions_afterDegr(k)); end matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: matthiasm@0: