api - 网络音频 API WaveShaperNode

标签 api audio webkit web-audio-api

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/

相关文章:

iphone - 预加载图像/声音以避免延迟

c# - 在 Webkit View 中嵌入 native 小部件

html - 是否可以使浏览器的一部分透明显示网络应用程序中的底层桌面/窗口?

javascript - 循环播放音频次数有限

html - 是否可以设置 html5 音频标签的样式?

CSS3 关键帧在 safari 中中断

Javascript jQuery 调用 API 来填充表,但接收到特定对象调用的未定义信息

swift - 在标签中打印 JSON 响应时出现问题

azure - 用于 API 访问的单个或多个 B2C 应用程序?

api - 将站点和 api 连接到同一数据库