generated from ZL-Audio/ZLTemplate
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add analog magnitude functions
- Loading branch information
Showing
5 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) 2023 - zsliu98 | ||
// This file is part of ZLEqualizer | ||
// | ||
// ZLEqualizer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
// | ||
// ZLEqualizer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#include "analog_func.h" | ||
|
||
namespace zl_iir { | ||
double AnalogFunc::getMagnitude2(std::array<double, 6> coeff, double w) { | ||
auto w_2 = w * w; | ||
auto denominator = std::pow(coeff[1], 2) * w_2 + std::pow(coeff[2] - coeff[0] * w_2, 2); | ||
auto numerator = std::pow(coeff[4], 2) * w_2 + std::pow(coeff[5] - coeff[3] * w_2, 2); | ||
return numerator / denominator; | ||
} | ||
|
||
double AnalogFunc::getLowPassMagnitude2(double w0, double q, double w) { | ||
return getMagnitude2({1, w0 / q, w0 * w0, 0, 0, w0 * w0}, w); | ||
} | ||
|
||
double AnalogFunc::getHighPassMagnitude2(double w0, double q, double w) { | ||
return getMagnitude2({1, w0 / q, w0 * w0, 1, 0, 0}, w); | ||
} | ||
|
||
double AnalogFunc::getBandPassMagnitude2(double w0, double q, double w) { | ||
return getMagnitude2({1, w0 / q, w0 * w0, 0, w0 / q, 0}, w); | ||
} | ||
|
||
double AnalogFunc::getNotchMagnitude2(double w0, double q, double w) { | ||
return getMagnitude2({1, w0 / q, w0 * w0, 1, 0, w0 * w0}, w); | ||
} | ||
|
||
double AnalogFunc::getPeakMagnitude2(double w0, double g, double q, double w) { | ||
return getMagnitude2({1, w0 / std::sqrt(g) / q, w0 * w0, 1, w0 * std::sqrt(g) / q, w0 * w0}, w); | ||
} | ||
|
||
double AnalogFunc::getLowShelfMagnitude2(double w0, double g, double q, double w) { | ||
auto A = std::sqrt(g); | ||
return getMagnitude2({A, std::sqrt(A) * w0 / q, w0 * w0, A, A * std::sqrt(A) * w0 / q, A * w0 * w0}, w); | ||
} | ||
|
||
double AnalogFunc::getHighShelfMagnitude2(double w0, double g, double q, double w) { | ||
auto A = std::sqrt(g); | ||
return getMagnitude2({1, std::sqrt(A) * w0 / q, w0 * w0, A * A, A * std::sqrt(A) * w0 / q, A * w0 * w0}, w); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (C) 2023 - zsliu98 | ||
// This file is part of ZLEqualizer | ||
// | ||
// ZLEqualizer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
// | ||
// ZLEqualizer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#ifndef ZLEQUALIZER_ANALOG_FUNC_H | ||
#define ZLEQUALIZER_ANALOG_FUNC_H | ||
|
||
#include <cmath> | ||
#include <array> | ||
|
||
namespace zl_iir { | ||
class AnalogFunc { | ||
public: | ||
static double getLowPassMagnitude2(double w0, double q, double w); | ||
|
||
static double getHighPassMagnitude2(double w0, double q, double w); | ||
|
||
static double getBandPassMagnitude2(double w0, double q, double w); | ||
|
||
static double getNotchMagnitude2(double w0, double q, double w); | ||
|
||
static double getPeakMagnitude2(double w0, double g, double q, double w); | ||
|
||
static double getLowShelfMagnitude2(double w0, double g, double q, double w); | ||
|
||
static double getHighShelfMagnitude2(double w0, double g, double q, double w); | ||
|
||
private: | ||
static double getMagnitude2(std::array<double, 6> coeff, double w); | ||
}; | ||
} | ||
|
||
#endif //ZLEQUALIZER_ANALOG_FUNC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (C) 2023 - zsliu98 | ||
// This file is part of ZLEqualizer | ||
// | ||
// ZLEqualizer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
// | ||
// ZLEqualizer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#include "martin_coeff.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (C) 2023 - zsliu98 | ||
// This file is part of ZLEqualizer | ||
// | ||
// ZLEqualizer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
// | ||
// ZLEqualizer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#ifndef ZLEQUALIZER_MARTIN_COEFFS_H | ||
#define ZLEQUALIZER_MARTIN_COEFFS_H | ||
|
||
#include "martin_coeff.h" | ||
|
||
class MartinCoeff { | ||
|
||
}; | ||
|
||
|
||
#endif //ZLEQUALIZER_MARTIN_COEFFS_H |