generated from ZL-Audio/ZLTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
476 additions
and
12 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
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
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,15 @@ | ||
// Copyright (C) 2024 - zsliu98 | ||
// This file is part of ZLCompressor | ||
// | ||
// ZLCompressor 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. | ||
// | ||
// ZLCompressor 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 ZLCompressor. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#ifndef COMPRESSOR_COMPUTER_HPP | ||
#define COMPRESSOR_COMPUTER_HPP | ||
|
||
#include "knee_computer.hpp" | ||
|
||
#endif //COMPRESSOR_COMPUTER_HPP |
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,73 @@ | ||
// Copyright (C) 2024 - zsliu98 | ||
// This file is part of ZLCompressor | ||
// | ||
// ZLCompressor 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. | ||
// | ||
// ZLCompressor 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 ZLCompressor. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#include "knee_computer.hpp" | ||
|
||
namespace zlCompressor { | ||
template<typename FloatType> | ||
KneeComputer<FloatType>::KneeComputer(const KneeComputer<FloatType> &c) { | ||
setThreshold(c.getThreshold()); | ||
setRatio(c.getRatio()); | ||
setKneeW(c.getKneeW()); | ||
setCurve(c.getCurve()); | ||
setBound(c.getBound()); | ||
} | ||
|
||
template<typename FloatType> | ||
KneeComputer<FloatType>::~KneeComputer() = default; | ||
|
||
template<typename FloatType> | ||
FloatType KneeComputer<FloatType>::eval(FloatType x) { | ||
if (toInterpolate.exchange(false)) { | ||
interpolate(); | ||
} | ||
if (x <= lowThres) { | ||
return x; | ||
} else if (x >= highThres) { | ||
const auto linearV = paras[5] + x * currentSlope; | ||
const auto quadV = paras[3] * x * x + paras[4]; | ||
return juce::jlimit(x - currentBound, x + currentBound, | ||
currentOppositeCurve * linearV + currentCurve * quadV); | ||
} else { | ||
const auto xx = x + paras[1]; | ||
return juce::jlimit(x - currentBound, x + currentBound, | ||
x + paras[0] * xx * xx * paras[2]); | ||
} | ||
} | ||
|
||
template<typename FloatType> | ||
FloatType KneeComputer<FloatType>::process(FloatType x) { | ||
return eval(x) - x; | ||
} | ||
|
||
template<typename FloatType> | ||
void KneeComputer<FloatType>::interpolate() { | ||
currentThreshold = threshold.load(); | ||
const auto kneeW_ = kneeW.load(); | ||
currentRatio = ratio.load(); | ||
currentSlope = FloatType(1) / currentRatio; | ||
currentBound = bound.load(); | ||
currentCurve = curve.load(); | ||
currentOppositeCurve = FloatType(1) - currentCurve; | ||
lowThres = currentThreshold - kneeW_; | ||
highThres = currentThreshold + kneeW_; | ||
paras[0] = FloatType(1) / currentRatio - FloatType(1); | ||
paras[1] = -lowThres; | ||
paras[2] = FloatType(1) / (kneeW_ * FloatType(4)); | ||
paras[3] = 1 / std::min(currentThreshold + kneeW_, FloatType(0.0001)) / currentRatio; | ||
paras[4] = currentThreshold + (kneeW_ - currentThreshold) / FloatType(2) / currentRatio; | ||
paras[5] = currentThreshold * (1 - currentSlope); | ||
} | ||
|
||
template | ||
class KneeComputer<float>; | ||
|
||
template | ||
class KneeComputer<double>; | ||
} // KneeComputer |
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,87 @@ | ||
// Copyright (C) 2024 - zsliu98 | ||
// This file is part of ZLCompressor | ||
// | ||
// ZLCompressor 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. | ||
// | ||
// ZLCompressor 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 ZLCompressor. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#ifndef COMPRESSOR_COMPUTER_H | ||
#define COMPRESSOR_COMPUTER_H | ||
|
||
#include <juce_audio_processors/juce_audio_processors.h> | ||
|
||
namespace zlCompressor { | ||
/** | ||
* a computer that computes the current compression | ||
* @tparam FloatType | ||
*/ | ||
template<typename FloatType> | ||
class KneeComputer final { | ||
public: | ||
KneeComputer() = default; | ||
|
||
KneeComputer(const KneeComputer<FloatType> &c); | ||
|
||
~KneeComputer(); | ||
|
||
FloatType eval(FloatType x); | ||
|
||
/** | ||
* computes the current compression | ||
* @param x input level (in dB) | ||
* @return current compression (in dB) | ||
*/ | ||
FloatType process(FloatType x); | ||
|
||
inline void setThreshold(FloatType v) { | ||
threshold.store(v); | ||
toInterpolate.store(true); | ||
} | ||
|
||
inline FloatType getThreshold() const { return threshold.load(); } | ||
|
||
inline void setRatio(FloatType v) { | ||
ratio.store(v); | ||
toInterpolate.store(true); | ||
} | ||
|
||
inline FloatType getRatio() const { return ratio.load(); } | ||
|
||
inline void setKneeW(FloatType v) { | ||
kneeW.store(std::max(v, FloatType(0.01))); | ||
toInterpolate.store(true); | ||
} | ||
|
||
inline FloatType getKneeW() const { return kneeW.load(); } | ||
|
||
inline void setCurve(FloatType v) { | ||
curve.store(v); | ||
toInterpolate.store(true); | ||
} | ||
|
||
inline FloatType getCurve() const { return curve.load(); } | ||
|
||
inline void setBound(FloatType v) { | ||
bound.store(v); | ||
} | ||
|
||
inline FloatType getBound() const { return bound.load(); } | ||
|
||
private: | ||
std::atomic<FloatType> threshold{0}, ratio{1}; | ||
FloatType currentThreshold{0}, currentRatio{1}, currentSlope{1}; | ||
std::atomic<FloatType> kneeW{FloatType(0.01)}, curve{0}; | ||
FloatType lowThres{0}, highThres{0}, currentCurve{0}, currentOppositeCurve{1}; | ||
std::atomic<FloatType> bound{60}; | ||
FloatType currentBound{60}; | ||
std::array<FloatType, 6> paras; | ||
std::atomic<bool> toInterpolate{true}; | ||
|
||
void interpolate(); | ||
}; | ||
|
||
} // KneeComputer | ||
|
||
#endif //COMPRESSOR_COMPUTER_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,16 @@ | ||
// Copyright (C) 2024 - zsliu98 | ||
// This file is part of ZLCompressor | ||
// | ||
// ZLCompressor 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. | ||
// | ||
// ZLCompressor 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 ZLCompressor. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#ifndef DSP_HPP | ||
#define DSP_HPP | ||
|
||
#include "dsp_definitions.hpp" | ||
#include "computer/computer.hpp" | ||
|
||
#endif //DSP_HPP |
Oops, something went wrong.