【发布时间】:2011-12-12 00:36:18
【问题描述】:
如何在网络音频 api 中使用 waveshapernode?特别是曲线 Float32Array 属性?
【问题讨论】:
标签: api audio webkit web-audio-api
如何在网络音频 api 中使用 waveshapernode?特别是曲线 Float32Array 属性?
【问题讨论】:
标签: api audio webkit web-audio-api
请随意查看示例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));
}
}
然后将其“加载”到像这样的波形整形器节点中:
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 使失真听起来更好,值是通过直觉发现的)。 你可以找到我用来创建波形曲线的算法here
【讨论】: