WaveShaperNode Web Audio API

How do you use wavehapernode in web audio api? in particular, attribute Float32Array curve?

+7
source share
1 answer

Do not forget to see an example here .

In detail, I create a wavechaper 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 into the wavemaper node as follows:

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

Every time I need to change the distortion parameter, I again create a wavechaper 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 more enjoyable, values ​​found heuristically). You can find the algorithm that I use to create the wavehaper curve here

+6
source

All Articles