dsp.js icon indicating copy to clipboard operation
dsp.js copied to clipboard

Bitwise "^ operator" in BiquadFilter?

Open ghost opened this issue 8 years ago • 2 comments

There are two instance of the "^ operator" in the recalculateCoefficients() function. I think they are being used on floating point values. It's more common to use bitwise operations on Integers. Maybe the "^" were meant to be "Math.pow" instead?

ghost avatar Apr 19 '18 06:04 ghost

i am sure that this is the XOR operator, for an operator that is like Math.pow, there is **. Example: 3 ** 2 === 9

Taureon avatar Jan 29 '22 17:01 Taureon

@Taureon it is indeed the bitwas XOR operator in JavaScript, but that's what the bug report seems to be about.

Most comments in that code use ^ as the exponent operator (it's a relatively common notation, since ^ as used as the power/exponent operator in some programming languages, and in LaTeX, for example). It's likely that this code was written with the intention to use power/exponent where ^ is used.

In those lines of code, A^2 should probably be replaced with A*A:

      case DSP.LOW_SHELF:   // H(s) = A * (s^2 + (sqrt(A)/Q)*s + A)/(A*s^2 + (sqrt(A)/Q)*s + 1)
        coeff = sinw0 * Math.sqrt( (A^2 + 1)*(1/this.S - 1) + 2*A );
// ...
      case DSP.HIGH_SHELF:   // H(s) = A * (A*s^2 + (sqrt(A)/Q)*s + 1)/(s^2 + (sqrt(A)/Q)*s + A)
        coeff = sinw0 * Math.sqrt( (A^2 + 1)*(1/this.S - 1) + 2*A );

harbulot avatar Jan 31 '22 16:01 harbulot