Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitwise "^ operator" in BiquadFilter? #36

Open
ghost opened this issue Apr 19, 2018 · 2 comments
Open

Bitwise "^ operator" in BiquadFilter? #36

ghost opened this issue Apr 19, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Apr 19, 2018

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?

@Taureon
Copy link

Taureon commented Jan 29, 2022

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

@harbulot
Copy link

@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 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants