To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _beattracker / findmeter_mm.m @ 8:b5b38998ef3b
History | View | Annotate | Download (1.48 KB)
| 1 |
function [timesig,three_energy,four_energy] = findmeter_mm(acf,period,thresh); |
|---|---|
| 2 |
|
| 3 |
% a simple enegy test with current period value, where energy is evaluated |
| 4 |
% at small regions at double and four times the period, to be compared with |
| 5 |
% energy at 3 and 6 times the beat period, to decide if the time signature |
| 6 |
% of the current frame is duple or triple. |
| 7 |
|
| 8 |
if nargin<3 |
| 9 |
thresh = 0; |
| 10 |
%default state |
| 11 |
end |
| 12 |
|
| 13 |
|
| 14 |
acf = acf/sum(acf); |
| 15 |
|
| 16 |
period = round(period); |
| 17 |
|
| 18 |
sw= 2; |
| 19 |
|
| 20 |
|
| 21 |
% % new approach - LESS GOOD than the old approach |
| 22 |
% |
| 23 |
% numperiods = floor(length(acf)/period); |
| 24 |
% num4multiples = floor(numperiods/4); |
| 25 |
% % % just check we haven't gone over the end of the acf |
| 26 |
% num4multiples = num4multiples- double((period*num4multiples*4+sw) > length(acf)); |
| 27 |
% |
| 28 |
% % initialize; |
| 29 |
% three_energy = 0; |
| 30 |
% four_energy = 0; |
| 31 |
% |
| 32 |
% for i=1:length(num4multiples) |
| 33 |
% |
| 34 |
% three_energy = three_energy + sum(acf(3*i*period-sw:1:3*i*period+sw)); |
| 35 |
% four_energy = four_energy + sum(acf(4*i*period-sw:1:4*i*period+sw)); |
| 36 |
% |
| 37 |
% end |
| 38 |
|
| 39 |
|
| 40 |
% old approach... |
| 41 |
|
| 42 |
if(length(acf)<6*period+sw) |
| 43 |
|
| 44 |
|
| 45 |
three_energy = sum(acf(3*period-sw:1:3*period+sw)); |
| 46 |
|
| 47 |
four_energy = sum(acf(4*period-sw:1:4*period+sw)); |
| 48 |
|
| 49 |
else |
| 50 |
|
| 51 |
three_energy = sum(acf(3*period-sw:1:3*period+sw)) + sum(acf(6*period-sw:1:6*period+sw)); |
| 52 |
|
| 53 |
four_energy = sum(acf(4*period-sw:1:4*period+sw)) + sum(acf(2*period-sw:1:2*period+sw)); |
| 54 |
|
| 55 |
end |
| 56 |
|
| 57 |
|
| 58 |
if ( (four_energy - three_energy) >= thresh ) |
| 59 |
timesig = 4; |
| 60 |
else |
| 61 |
timesig = 3; |
| 62 |
end |