BPM detection using Gamedev algorithm

4 visualizaciones (últimos 30 días)
Sagi Shtainman
Sagi Shtainman el 21 de Jul. de 2019
Comentada: Federico Dentesano el 22 de Nov. de 2020
Hello everyone, I tried writing to use Gamedev algorithm in matlab to extract the BPM of a metronome but something isnt working.
I don't get the right BPM for the metronome used.
Hopefully someone can inspect my code and find whats the problem.
% CIRCULAR BUFFERING
filename='120 BPM 4_4 Wood Metronome HD.mp3';
format long;
[y,Fs] = audioread(filename);
yLeft=y(:,1);
yRight=y(:,2);
count=0;
len=length(yLeft);
numOfWin=len/(43*1024); % the length of window in samples (43*1024)
numOfWin=floor(numOfWin) ; %numOfWin- the num. of complete windows withn the song
newNumSamp=numOfWin*(43*1024);
yLeft=y(1:newNumSamp,1);
yRight=y(1:newNumSamp,2);
%CREATE LEFT & RIGHT MATRIX
LReshapeData=reshape(yLeft,[1024,numOfWin*43]);
RReshapeData=reshape(yRight,[1024,numOfWin*43]);
EWin=zeros(1,43);
% %create the energ buffer for the first window:
for segmentInd=43:-1:1
Eseg=sum((LReshapeData(:,segmentInd).^2)+(RReshapeData(:,segmentInd).^2) );
EWin((43-segmentInd)+1)=Eseg;
end
for segmentInd=44:numOfWin*43
Eseg=sum((LReshapeData(:,segmentInd).^2)+(RReshapeData(:,segmentInd).^2) );
avgE=sum(EWin)/43;
VarE=(1/43)*sum( (EWin-avgE).^2);
C=(-0.0025714*VarE)+1.5142857;
if EWin(1)> abs(C)*avgE
count=count+1;
end
EWin(1:end)=[Eseg,EWin(1:42)];%shift right the buffer in 1 segment
end
tsec=newNumSamp/Fs; % t=n*Ts- the total length in seconds
tmin=tsec/60;
numBPM=count/tmin;
  1 comentario
Federico Dentesano
Federico Dentesano el 22 de Nov. de 2020
Hi have you finished the code? I am trying to understand how BPM tracking works and this code was helpful, I would like to see it complete if you have it..

Iniciar sesión para comentar.

Respuestas (1)

Dinesh Yadav
Dinesh Yadav el 5 de Ag. de 2019
The missing points in the above implementation are as follows:-
  • The first sample points you have used for comparing average energy to "C" is 1:1024, but the second sample you have used for comparing is of 44th column i.e. 44032:43056 samples. Therefore, you are missing to compare energies of 2nd to 43rd column. Change your update "EWin" command code as shown below:
EWin(1: end)=[Ewin(2:43),Eseg];
  • The second one is related to flooring of sample points. Even after flooring you should store those extra sample points and compute and compare energies of those also. Here the sample points after flooring have been discarded so even if there is a beat at the ending the above algorithm won't detect that.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by