matthiasm@8: function [timesig,three_energy,four_energy] = findmeter_mm(acf,period,thresh); matthiasm@8: matthiasm@8: % a simple enegy test with current period value, where energy is evaluated matthiasm@8: % at small regions at double and four times the period, to be compared with matthiasm@8: % energy at 3 and 6 times the beat period, to decide if the time signature matthiasm@8: % of the current frame is duple or triple. matthiasm@8: matthiasm@8: if nargin<3 matthiasm@8: thresh = 0; matthiasm@8: %default state matthiasm@8: end matthiasm@8: matthiasm@8: matthiasm@8: acf = acf/sum(acf); matthiasm@8: matthiasm@8: period = round(period); matthiasm@8: matthiasm@8: sw= 2; matthiasm@8: matthiasm@8: matthiasm@8: % % new approach - LESS GOOD than the old approach matthiasm@8: % matthiasm@8: % numperiods = floor(length(acf)/period); matthiasm@8: % num4multiples = floor(numperiods/4); matthiasm@8: % % % just check we haven't gone over the end of the acf matthiasm@8: % num4multiples = num4multiples- double((period*num4multiples*4+sw) > length(acf)); matthiasm@8: % matthiasm@8: % % initialize; matthiasm@8: % three_energy = 0; matthiasm@8: % four_energy = 0; matthiasm@8: % matthiasm@8: % for i=1:length(num4multiples) matthiasm@8: % matthiasm@8: % three_energy = three_energy + sum(acf(3*i*period-sw:1:3*i*period+sw)); matthiasm@8: % four_energy = four_energy + sum(acf(4*i*period-sw:1:4*i*period+sw)); matthiasm@8: % matthiasm@8: % end matthiasm@8: matthiasm@8: matthiasm@8: % old approach... matthiasm@8: matthiasm@8: if(length(acf)<6*period+sw) matthiasm@8: matthiasm@8: matthiasm@8: three_energy = sum(acf(3*period-sw:1:3*period+sw)); matthiasm@8: matthiasm@8: four_energy = sum(acf(4*period-sw:1:4*period+sw)); matthiasm@8: matthiasm@8: else matthiasm@8: matthiasm@8: three_energy = sum(acf(3*period-sw:1:3*period+sw)) + sum(acf(6*period-sw:1:6*period+sw)); matthiasm@8: matthiasm@8: four_energy = sum(acf(4*period-sw:1:4*period+sw)) + sum(acf(2*period-sw:1:2*period+sw)); matthiasm@8: matthiasm@8: end matthiasm@8: matthiasm@8: matthiasm@8: if ( (four_energy - three_energy) >= thresh ) matthiasm@8: timesig = 4; matthiasm@8: else matthiasm@8: timesig = 3; matthiasm@8: end