gpt4 book ai didi

api - 网络音频 API WaveShaperNode

转载 作者:行者123 更新时间:2023-12-04 12:12:26 38 4
gpt4 key购买 nike

web音频api中的waveshapernode是怎么使用的?特别是曲线 Float32Array 属性?

最佳答案

随意看一个例子 here .

详细地说,我用这个函数创建了一个波形曲线:

WAAMorningStar.prototype.createWSCurve = function (amount, n_samples) {

if ((amount >= 0) && (amount < 1)) {

ND.dist = amount;

var k = 2 * ND.dist / (1 - ND.dist);

for (var i = 0; i < n_samples; i+=1) {
// LINEAR INTERPOLATION: x := (c - a) * (z - y) / (b - a) + y
// a = 0, b = 2048, z = 1, y = -1, c = i
var x = (i - 0) * (1 - (-1)) / (n_samples - 0) + (-1);
this.wsCurve[i] = (1 + k) * x / (1+ k * Math.abs(x));
}

}

然后将它“加载”到一个waveshaper节点中,如下所示:
this.createWSCurve(ND.dist, this.nSamples);
this.sigmaDistortNode = this.context.createWaveShaper();
this.sigmaDistortNode.curve = this.wsCurve;

每次我需要更改失真参数时,我都会重新创建波形曲线:
WAAMorningStar.prototype.setDistortion = function (distValue) {
var distCorrect = distValue;
if (distValue < -1) {
distCorrect = -1;
}
if (distValue >= 1) {
distCorrect = 0.985;
}
this.createWSCurve (distCorrect, this.nSamples);
}

(我使用 distCorrect 使失真听起来更好,值在 euristically 中找到)。
您可以找到我用来创建波形曲线的算法 here

关于api - 网络音频 API WaveShaperNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7840347/

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