7

WebオーディオAPIでwaveshapernodeをどのように使用しますか?特に曲線のFloat32Array属性?

4

1 に答える 1

6

こちらの例をご覧ください。

詳細には、この関数を使用してウェーブシェイパーカーブを作成します。

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を使用して、歪みの音をより良くします。値は自然に見つかります)。ウェーブシェイパーカーブを作成するために使用するアルゴリズムは、ここにあります。

于 2011-11-15T21:03:13.953 に答える