我想使用Pizzicato JS,与三个JS创建一个声音可视化。但由于某种原因,在我获得频率数据后,它为每个频段返回的频率为0。为了获得这些频率,我是否遗漏了什么,这样我就可以用三个JS来操纵我的网格,请告诉我?我已经附加了我的控制台窗口的屏幕截图,并粘贴了下面的代码以供参考。
var context = Pizzicato.context;
var analyser = context.createAnalyser();
var ambient = new Pizzicato.Sound('./mp3/ambient.mp3', playAmbient);
ambient.loop = true;
ambient.volume = 1;
ambient.connect(analyser);
var frequencyData = new Uint8Array(analyser.frequencyBinCount);
console.log("Frequency Data: " , frequencyData);
console.log("Frequency Data Length: " , frequencyData.length);`
function playAmbient(e)
{
console.log("playAmbient();");
ambient.play();
}

谢谢
发布于 2017-12-05 10:20:15
所以我弄清楚了,我希望频率数据在执行console.log()时返回每个频带的频率数组。实际上,我必须使用getByteFrequencyData方法接收我的频率数据。我粘贴了我的新代码集来引用未定义数据的问题。
context = Pizzicato.context;
analyser = context.createAnalyser();
sound = new Pizzicato.Sound(params, playAmbient);
sound.volume = 1;
sound.connect(analyser);
function playAmbient(e)
{
console.log("playAmbient();");
ambient.play();
}
setInterval(function () {
try{
var bufferLength = analyser.frequencyBinCount;
frequencyData = new Uint8Array(bufferLength);
// The statement below was missing, and in return it will then
// update my frequencies for each band given from my
// frequencyData.
analyser.getByteFrequencyData(frequencyData);
// Now I'm seeing the frequencies update in my console.log window
// when each interval is fired.
console.log(frequencyData);
}catch(error){
console.log(error);
}
}, 500);https://stackoverflow.com/questions/47626854
复制相似问题