SebastianEwert@28
|
1 function computeMeanSpectralEnvelope(audiofile, fftLength)
|
SebastianEwert@28
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
SebastianEwert@28
|
3 % Audio Degradation Toolbox
|
SebastianEwert@28
|
4 %
|
SebastianEwert@28
|
5 % Centre for Digital Music, Queen Mary University of London.
|
SebastianEwert@28
|
6 % This file copyright 2013 Sebastian Ewert, Matthias Mauch and QMUL.
|
SebastianEwert@28
|
7 %
|
SebastianEwert@28
|
8 % This program is free software; you can redistribute it and/or
|
SebastianEwert@28
|
9 % modify it under the terms of the GNU General Public License as
|
SebastianEwert@28
|
10 % published by the Free Software Foundation; either version 2 of the
|
SebastianEwert@28
|
11 % License, or (at your option) any later version. See the file
|
SebastianEwert@28
|
12 % COPYING included with this distribution for more information.
|
SebastianEwert@28
|
13 %
|
SebastianEwert@28
|
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
SebastianEwert@28
|
15
|
SebastianEwert@28
|
16 [f_audio,samplingFreq]=wavread(audiofile);
|
SebastianEwert@28
|
17
|
SebastianEwert@28
|
18 % compute mean spectral vector for f_audio
|
SebastianEwert@28
|
19 [destMagFreqResp, destMagFreqResp_freqs] = internal_computeMeanSpectralVector(f_audio,samplingFreq,fftLength);
|
SebastianEwert@28
|
20 destMagFreqResp = internal_standardizeMagFreqResp(destMagFreqResp);
|
SebastianEwert@28
|
21
|
SebastianEwert@28
|
22 outputFilename = [audiofile(1:end-4),'_specEnv'];
|
SebastianEwert@28
|
23 save(outputFilename,'destMagFreqResp','destMagFreqResp_freqs')
|
SebastianEwert@28
|
24
|
SebastianEwert@28
|
25 end
|
SebastianEwert@28
|
26
|
SebastianEwert@28
|
27
|
SebastianEwert@28
|
28 function [f_meanmagspec_db,freqs] = internal_computeMeanSpectralVector(f_audio,fs,fftLength)
|
SebastianEwert@28
|
29
|
SebastianEwert@28
|
30 f_audio = mean(f_audio,2);
|
SebastianEwert@28
|
31
|
SebastianEwert@28
|
32 [f_spec,freqs,time] = spectrogram(f_audio,hanning(fftLength),fftLength/2,fftLength,fs);
|
SebastianEwert@28
|
33
|
SebastianEwert@28
|
34 f_magspec_db = 20 * log10(abs(f_spec));
|
SebastianEwert@28
|
35
|
SebastianEwert@28
|
36 f_magspec_db(:,isinf(sum(abs(f_magspec_db),1))) = []; % ignore rows with -inf/inf entries
|
SebastianEwert@28
|
37
|
SebastianEwert@28
|
38 f_meanmagspec_db = mean(f_magspec_db,2);
|
SebastianEwert@28
|
39
|
SebastianEwert@28
|
40 end
|
SebastianEwert@28
|
41
|
SebastianEwert@28
|
42 function magFreqResp = internal_standardizeMagFreqResp(magFreqResp)
|
SebastianEwert@28
|
43
|
SebastianEwert@28
|
44 maxRobust = max(magFreqResp(~isinf(magFreqResp)));
|
SebastianEwert@28
|
45
|
SebastianEwert@28
|
46 magFreqResp = magFreqResp - maxRobust;
|
SebastianEwert@28
|
47
|
SebastianEwert@28
|
48 magFreqResp(magFreqResp > 0) = 0; % remaining positive inf
|
SebastianEwert@28
|
49 magFreqResp(magFreqResp < -80) = -80; % remaining positive inf
|
SebastianEwert@28
|
50
|
SebastianEwert@28
|
51 end
|
SebastianEwert@28
|
52
|