-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComputeBeatHisto.m
executable file
·50 lines (44 loc) · 1.64 KB
/
ComputeBeatHisto.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
% ======================================================================
%> @brief computes a simple beat histogram
%>
%> supported novelty measures are:
%> 'Flux',
%> 'Laroche',
%> 'Hainsworth'
%>
%> @param afAudioData: 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 iPeaks indices of picked onset times
% ======================================================================
function [T, Bpm] = ComputeBeatHisto (afAudioData, f_s, afWindow, iBlockLength, iHopLength)
% set default parameters if necessary
if (nargin < 6)
iHopLength = 8;
end
if (nargin < 5)
iBlockLength = 1024;
end
if (nargin < 4 || isempty(afWindow))
afWindow = hann(iBlockLength,'periodic');
end
% compute FFT window function
if (length(afWindow) ~= iBlockLength)
error('window length mismatch');
end
% novelty function
[d,t,peaks] = ComputeNoveltyFunction ('Flux', afAudioData, f_s, afWindow, iBlockLength, iHopLength);
% tmp = zeros(size(d));
% tmp(peaks) = d(peaks);
% d = tmp;
% compute autocorrelation
afCorr = xcorr(d,'coeff');
afCorr = afCorr((ceil((length(afCorr)/2))+1):end);
Bpm = fliplr(60./t(2:end));
T = fliplr (afCorr);
end