Skip to content

Commit

Permalink
feat: complete knee computer
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Dec 25, 2023
1 parent ed24bf7 commit 974192f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ target_link_libraries(SharedCode
juce_gui_extra
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags)
juce::juce_recommended_warning_flags
Boost::boost)

# Link the JUCE plugin targets our SharedCode target
target_link_libraries("${PROJECT_NAME}" PRIVATE SharedCode)
Expand Down
19 changes: 12 additions & 7 deletions source/dsp/compressor/computer/knee_computer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@
#ifndef ZLECOMP_COMPUTER_H
#define ZLECOMP_COMPUTER_H

#include <juce_audio_processors/juce_audio_processors.h>

#include <boost/circular_buffer.hpp>
#include <boost/math/interpolators/cubic_hermite.hpp>

#include "virtual_computer.h"

namespace zlCompressor {

template<typename FloatType>
class KneeComputer {
class KneeComputer : VirtualComputer<FloatType> {
public:
KneeComputer() { interpolate(); }

KneeComputer(const KneeComputer<FloatType> &c);

FloatType eval(FloatType x);

FloatType process(FloatType x);
FloatType process(FloatType x) override;

inline void setThreshold(FloatType v) {
threshold.store(v);
Expand All @@ -39,40 +43,41 @@ namespace zlCompressor {
interpolate();
}

inline FloatType getRatio() const { return ratio.load();}
inline FloatType getRatio() const { return ratio.load(); }

inline void setKneeW(FloatType v) {
kneeW.store(v);
interpolate();
}

inline FloatType getKneeW() const {return kneeW.load();}
inline FloatType getKneeW() const { return kneeW.load(); }

inline void setKneeD(FloatType v) {
kneeD.store(v);
interpolate();
}

inline FloatType getKneeD() const {return kneeD.load();}
inline FloatType getKneeD() const { return kneeD.load(); }

inline void setKneeS(FloatType v) {
kneeS.store(v);
interpolate();
}

inline FloatType getKneeS() const {return kneeS.load();}
inline FloatType getKneeS() const { return kneeS.load(); }

inline void setBound(FloatType v) {
bound.store(v);
}

inline FloatType getBound() const {return bound.load();}
inline FloatType getBound() const { return bound.load(); }

private:
std::atomic<FloatType> threshold = FloatType(0), ratio = FloatType(1);
std::atomic<FloatType> kneeW = FloatType(0.0625), kneeD = FloatType(0.5), kneeS = FloatType(0.5);
std::atomic<FloatType> bound = FloatType(0);
std::unique_ptr<boost::math::interpolators::cubic_hermite<std::array<FloatType, 3>>> cubic;

void interpolate();
};

Expand Down
6 changes: 3 additions & 3 deletions source/dsp/compressor/computer/virtual_computer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

namespace zlCompressor {
template<typename FloatType>
class sComputer {
class VirtualComputer {
public:
sComputer() = default;
VirtualComputer() = default;

virtual ~sComputer() = 0;
virtual ~VirtualComputer() = 0;

virtual FloatType process(FloatType x) = 0;
};
Expand Down

0 comments on commit 974192f

Please sign in to comment.