加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

Web Audio API WaveShaperNode

发布时间:2020-12-14 18:40:01 所属栏目:资源 来源:网络整理
导读:你如何在网络音频api中使用waveshapernode?特别是曲线Float32Array属性? 解决方法 请随意查看示例 here. 详细地说,我用这个函数创建了一个wavehaper曲线: WAAMorningStar.prototype.createWSCurve = function (amount,n_samples) {if ((amount = 0) (amou
你如何在网络音频api中使用waveshapernode?特别是曲线Float32Array属性?

解决方法

请随意查看示例 here.

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

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));
    }

}

然后在wavehaper节点中“加载”它,如下所示:

this.createWSCurve(ND.dist,this.nSamples);
this.sigmaDistortNode = this.context.createWaveShaper();
this.sigmaDistortNode.curve = this.wsCurve;

每当我需要更改失真参数时,我会重新创建wavehaper曲线:

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来使失真听起来更好,从价值上看是值得的).
您可以找到我用来创建wavehaper曲线here的算法

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读