网络音频 API WaveShaperNode

发布于 2024-12-11 02:38:13 字数 57 浏览 0 评论 0原文

如何在网络音频API中使用waveshapernode?特别是曲线 Float32Array 属性?

How do you use the waveshapernode in the web audio api? particular the curve Float32Array attribute?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

通知家属抬走 2024-12-18 02:38:13

请随意查看此处的示例。

详细地说,我使用此函数创建一条波形整形器曲线:

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

}

然后将其“加载”到波形整形器节点中,如下所示:

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 来制作失真声音更好,通过探索发现的价值观)。
您可以在此处找到我用来创建波形成形器曲线的算法

Feel free to look at an example here.

In detail, I create a waveshaper curve with this function:

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

}

Then "load" it in a waveshaper node like this:

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

Everytime I need to change the distortion parameter, I re-create the waveshaper curve:

WAAMorningStar.prototype.setDistortion = function (distValue) {
    var distCorrect = distValue;
    if (distValue < -1) {
        distCorrect = -1;
    }
    if (distValue >= 1) {
        distCorrect = 0.985;
    }
    this.createWSCurve (distCorrect, this.nSamples);
}

(I use distCorrect to make the distortion sound nicer, values found euristically).
You can find the algorithm I use to create the waveshaper curve here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文