computes the novelty function for onset detection > > supported novelty measures are: > 'Flux', > 'Laroche', > 'Hainsworth' > > @param cNoveltyName: name of the novelty measure > @param x: time domain sample data, dimension channels X samples > @param f_s: sample rate of audio data > @param afWindow: FFT window of length iBlockLength (default: hann), can be [] empty > @param iBlockLength: internal block length (default: 4096 samples) > @param iHopLength: internal hop length (default: 512 samples) > > @retval f frequency > @retval t time stamp for the frequency value > @retval G_T threshold function > @retval iPeaks indices of picked onset times ======================================================================
0001 %computes the novelty function for onset detection 0002 %> 0003 %> supported novelty measures are: 0004 %> 'Flux', 0005 %> 'Laroche', 0006 %> 'Hainsworth' 0007 %> 0008 %> @param cNoveltyName: name of the novelty measure 0009 %> @param x: time domain sample data, dimension channels X samples 0010 %> @param f_s: sample rate of audio data 0011 %> @param afWindow: FFT window of length iBlockLength (default: hann), can be [] empty 0012 %> @param iBlockLength: internal block length (default: 4096 samples) 0013 %> @param iHopLength: internal hop length (default: 512 samples) 0014 %> 0015 %> @retval f frequency 0016 %> @retval t time stamp for the frequency value 0017 %> @retval G_T threshold function 0018 %> @retval iPeaks indices of picked onset times 0019 % ====================================================================== 0020 function [d, t, G_T, iPeaks] = ComputeNoveltyFunction (cNoveltyName, x, f_s, afWindow, iBlockLength, iHopLength) 0021 0022 % set function handle 0023 hNoveltyFunc = str2func (['Novelty' cNoveltyName]); 0024 0025 % set default parameters if necessary 0026 if (nargin < 6) 0027 iHopLength = 512; 0028 end 0029 if (nargin < 5) 0030 iBlockLength = 4096; 0031 end 0032 if (nargin < 4 || isempty(afWindow)) 0033 afWindow = hann(iBlockLength, 'periodic'); 0034 end 0035 0036 % compute FFT window function 0037 if (length(afWindow) ~= iBlockLength) 0038 error('window length mismatch'); 0039 end 0040 0041 % parametrization of smoothing filters 0042 fSmoothLpLenInS = 0.07; 0043 fThreshLpLenInS = 0.14; 0044 iSmoothLpLen = max(2, ceil(fSmoothLpLenInS * f_s / iHopLength)); 0045 iThreshLpLen = max(2, ceil(fThreshLpLenInS * f_s / iHopLength)); 0046 0047 % pre-processing: down-mixing 0048 x = ToolDownmix(x); 0049 0050 % pre-processing: normalization (not necessary for many features) 0051 x = ToolNormalizeAudio(x); 0052 0053 % in the real world, we would do this block by block... 0054 [X, f, t] = ComputeSpectrogram(x, ... 0055 f_s, ... 0056 afWindow, ... 0057 iBlockLength, ... 0058 iHopLength); 0059 0060 % novelty function 0061 d = hNoveltyFunc(X, f_s); 0062 0063 % smooth novelty function 0064 b = ones(iSmoothLpLen,1)/iSmoothLpLen; 0065 d = filtfilt (b, 1, d); 0066 d(d<0) = 0; 0067 0068 % compute threshold 0069 iLen = min(iThreshLpLen, floor(length(d) / 3)); 0070 b = ones(iLen, 1) / iLen; 0071 G_T = .4*mean(d(2:end)) + filtfilt (b, 1, d); 0072 0073 [fPeaks, iPeaks] = findpeaks(max(0, d - G_T)); 0074 end 0075