Skip to content

Commit

Permalink
chore: clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Oct 10, 2024
1 parent 5148f6f commit d9c016f
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 30 deletions.
5 changes: 5 additions & 0 deletions source/dsp/container/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include <array>

namespace zlContainer {
/**
* an array which has a fixed maximum size (capacity)
* @tparam T the type of elements
* @tparam N the capacity of array
*/
template<typename T, size_t N>
class FixedMaxSizeArray {
public:
Expand Down
4 changes: 4 additions & 0 deletions source/dsp/container/circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <vector>

namespace zlContainer {
/**
* a circular buffer
* @tparam T the type of elements
*/
template<typename T>
class CircularBuffer {
public:
Expand Down
2 changes: 0 additions & 2 deletions source/dsp/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ namespace zlDSP {
void updateCorrections();

void updateSolo();

juce::FileLogger logger{juce::File("/Volumes/Ramdisk/log.txt"), ""};
};
}

Expand Down
19 changes: 0 additions & 19 deletions source/dsp/fft_analyzer/fft_helper.hpp

This file was deleted.

6 changes: 4 additions & 2 deletions source/dsp/fft_analyzer/multiple_fft_analyzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
namespace zlFFT {
/**
* a fft analyzer which make sure that multiple FFTs are synchronized in time
* @tparam FloatType
* @tparam FloatType the float type of input audio buffers
* @tparam FFTNum the number of FFTs
* @tparam PointNum the number of output points
*/
template<typename FloatType, size_t FFTNum, size_t PointNum>
class MultipleFFTAnalyzer final {
Expand Down Expand Up @@ -225,7 +227,7 @@ namespace zlFFT {
const auto y = interplotDBs[i][idx].load() / minDB * height + boundY;
path.get().lineTo(x, y);
}
for (size_t idx = PointNum - cubicNum; idx < PointNum; idx += 3) {
for (size_t idx = PointNum - cubicNum; idx < PointNum - 2; idx += 3) {
const auto x1 = static_cast<float>(idx) / static_cast<float>(PointNum - 1) * width;
const auto y1 = interplotDBs[i][idx].load() / minDB * height + boundY;\
const auto x2 = static_cast<float>(idx + 1) / static_cast<float>(PointNum - 1) * width;
Expand Down
4 changes: 4 additions & 0 deletions source/dsp/fft_analyzer/pre_post_fft_analyzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "../delay/delay.hpp"

namespace zlFFT {
/**
* a fft analyzer which process pre, post and side audio buffers
* @tparam FloatType the float type of input audio buffers
*/
template<typename FloatType>
class PrePostFFTAnalyzer final : private juce::Thread, juce::AsyncUpdater {
public:
Expand Down
7 changes: 7 additions & 0 deletions source/dsp/filter/fir_correction/fir_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
#include "../../container/array.hpp"

namespace zlFilter {
/**
* an FIR which has the magnitude responses of prototype filters and zero phase responses
* @tparam FloatType the float type of input audio buffer
* @tparam FilterNum the number of filters
* @tparam FilterSize the size of each filter
* @tparam defaultFFTOrder the default FFT order for 44100/48000 Hz input
*/
template<typename FloatType, size_t FilterNum, size_t FilterSize, size_t defaultFFTOrder = 13>
class FIR {
public:
Expand Down
7 changes: 7 additions & 0 deletions source/dsp/filter/fir_correction/mixed_correction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
#include "../../container/array.hpp"

namespace zlFilter {
/**
* an FIR which corrects the magnitude responses of IIR filters to prototype filters
* and minimizes phase responses at high-end
* @tparam FloatType the float type of input audio buffer
* @tparam FilterNum the number of filters
* @tparam FilterSize the size of each filter
*/
template<typename FloatType, size_t FilterNum, size_t FilterSize>
class MixedCorrection {
public:
Expand Down
6 changes: 6 additions & 0 deletions source/dsp/filter/fir_correction/prototype_correction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
#include "../../container/array.hpp"

namespace zlFilter {
/**
* an FIR which corrects the responses of IIR filters to prototype filters
* @tparam FloatType the float type of input audio buffer
* @tparam FilterNum the number of filters
* @tparam FilterSize the size of each filter
*/
template<typename FloatType, size_t FilterNum, size_t FilterSize>
class PrototypeCorrection {
public:
Expand Down
4 changes: 4 additions & 0 deletions source/dsp/filter/ideal_filter/empty_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include <atomic>

namespace zlFilter {
/**
* an empty filter which holds filter parameters
* @tparam FloatType the float type of input audio buffer
*/
template<typename FloatType>
class Empty {
public:
Expand Down
5 changes: 5 additions & 0 deletions source/dsp/filter/ideal_filter/single_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include "../filter_design/filter_design.hpp"

namespace zlFilter {
/**
* an ideal prototype filter which holds coeffs for calculating responses
* @tparam FloatType the float type of input audio buffer
* @tparam FilterSize the number of cascading filters
*/
template<typename FloatType, size_t FilterSize>
class Ideal {
public:
Expand Down
12 changes: 11 additions & 1 deletion source/dsp/filter/iir_filter/single_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace zlFilter {
/**
* an IIR filter which processes audio on the real-time thread
* the maximum modulation rate of parameters is once per block
* @tparam FloatType
* @tparam FloatType the float type of input audio buffer
* @tparam FilterSize the number of cascading filters
*/
template<typename FloatType, size_t FilterSize>
class IIR {
Expand Down Expand Up @@ -198,6 +199,10 @@ namespace zlFilter {

FloatType getGain() const { return static_cast<FloatType>(gain.load()); }

/**
* set gain and update coeffs immediately
* @param x gain
*/
void setGainNow(FloatType x) {
gain.store(static_cast<double>(x));
switch (currentFilterStructure) {
Expand Down Expand Up @@ -228,6 +233,11 @@ namespace zlFilter {

inline FloatType getQ() const { return static_cast<FloatType>(q.load()); }

/**
* set gain & Q and update coeffs immediately
* @param g1 gain
* @param q1 Q value
*/
void setGainAndQNow(FloatType g1, FloatType q1) {
gain.store(static_cast<double>(g1));
q.store(static_cast<double>(q1));
Expand Down
5 changes: 5 additions & 0 deletions source/dsp/filter/iir_filter/single_idle_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include "svf_base.hpp"

namespace zlFilter {
/**
* an idle IIR filter which holds coeffs for calculating responses
* @tparam FloatType the float type of input audio buffer
* @tparam FilterSize the number of cascading filters
*/
template<typename FloatType, size_t FilterSize>
class IIRIdle {
public:
Expand Down
21 changes: 21 additions & 0 deletions source/dsp/interpolation/seq_makima.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@
#include <vector>

namespace zlInterpolation {
/**
* modified Akima spline interpolation with increasing input/output X
* @tparam FloatType the float type of input/output
*/
template<typename FloatType>
class SeqMakima {
public:
/**
*
* @param x input X pointer
* @param y input Y pointer
* @param pointNum number of input points
* @param leftDerivative left derivative
* @param rightDerivative right derivative
*/
explicit SeqMakima(FloatType *x, FloatType *y, size_t pointNum,
FloatType leftDerivative, FloatType rightDerivative)
: xs(x), ys(y), inputSize(pointNum),
Expand All @@ -24,6 +36,9 @@ namespace zlInterpolation {
deltas.resize(pointNum - 1);
}

/**
* call this to update derivatives if input has been updated
*/
void prepare() {
for (size_t i = 0; i < deltas.size(); ++i) {
deltas[i] = (ys[i + 1] - ys[i]) / (xs[i + 1] - xs[i]);
Expand All @@ -43,6 +58,12 @@ namespace zlInterpolation {
derivatives.end()[-2] = calculateD(deltas.end()[-3], deltas.end()[-2], deltas.end()[-1], rightDelta);
}

/**
* evaluate the spline at output X
* @param x output X pointer
* @param y output Y pointer
* @param pointNum number of output points
*/
void eval(FloatType *x, FloatType *y, const size_t pointNum) {
size_t currentPos = 0;
size_t startIdx = 0, endIdx = pointNum - 1;
Expand Down
6 changes: 3 additions & 3 deletions source/dsp/phase/phase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//
// You should have received a copy of the GNU General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>.

#ifndef ZLPHASE_PHASE_HPP
#define ZLPHASE_PHASE_HPP
#ifndef ZL_PHASE_PHASE_HPP
#define ZL_PHASE_PHASE_HPP

#include "phase_flip.hpp"

#endif //ZLPHASE_PHASE_HPP
#endif //ZL_PHASE_PHASE_HPP
10 changes: 7 additions & 3 deletions source/dsp/phase/phase_flip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
//
// You should have received a copy of the GNU General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>.

#ifndef ZLPHASE_PHASE_FLIP_HPP
#define ZLPHASE_PHASE_FLIP_HPP
#ifndef ZL_PHASE_PHASE_FLIP_HPP
#define ZL_PHASE_PHASE_FLIP_HPP

#include <juce_dsp/juce_dsp.h>

namespace zlPhase {
/**
* phase-flip the input audio buffer
* @tparam FloatType the float type of input audio buffer
*/
template<typename FloatType>
class PhaseFlip {
public:
Expand All @@ -27,4 +31,4 @@ namespace zlPhase {
};
} // zlPhase

#endif //PHASE_FLIP_HPP
#endif //ZL_PHASE_PHASE_FLIP_HPP

0 comments on commit d9c016f

Please sign in to comment.