gpt4 book ai didi

javascript - Pizzicato JS - 无频率数据

转载 作者:行者123 更新时间:2023-11-30 20:56:18 25 4
gpt4 key购买 nike

我想使用 Pizzicato JS 和 Three 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();
}

CLICK HERE FOR SCREENSHOT!

谢谢

最佳答案

所以我想通了,我期望频率数据在执行 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);

关于javascript - Pizzicato JS - 无频率数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47626854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com