Skip to content

Commit

Permalink
feat: add analog magnitude functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Dec 14, 2023
1 parent 2b404aa commit bf0e4ee
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
</p>

# ZLEqualizer
![pluginval](<https://github.com/ZL-Audio/ZLSplit/actions/workflows/cmake_full_test.yml/badge.svg?branch=main>)
![pluginval](<https://github.com/ZL-Audio/ZLEqualizer/actions/workflows/cmake_full_test.yml/badge.svg?branch=main>)

ZLEqualizer is an equalizer plugin.

<!-- <img src="Docs/screenshot.png" width=94%> -->

## Usage

See the wiki for details.
Expand Down
49 changes: 49 additions & 0 deletions source/dsp/iir_filter/analog_func.cpp
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);
}
}
38 changes: 38 additions & 0 deletions source/dsp/iir_filter/analog_func.h
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
10 changes: 10 additions & 0 deletions source/dsp/iir_filter/martin_coeff.cpp
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"
20 changes: 20 additions & 0 deletions source/dsp/iir_filter/martin_coeff.h
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

0 comments on commit bf0e4ee

Please sign in to comment.