This is the code that i have been using to get frequency data of current time period of song. However its outputting same frequency again and again.
var audio = new Audio();
audio.src = 'anaconda.mp3';
var ctx = new webkitAudioContext(),
source;
source = ctx.createMediaElementSource(audio);
var analyser = ctx.createAnalyser();
source.connect(analyser);
analyser.connect(ctx.destination);
draw();
function draw() {
for (var i = 0; i <= audio.duration; i++) {
audio.currentTime = i;
getFrequency();
}
}
function getFrequency() {
analyser.fftSize = 32;
var bufferLength = analyser.fftSize;
var freqData = new Uint8Array(bufferLength);
analyser.getByteTimeDomainData(freqData);
console.log(freqData);
}
This is the output that i am getting in a loop:
[128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128]
Aucun commentaire:
Enregistrer un commentaire