Skip to content

Commit

Permalink
finished most features
Browse files Browse the repository at this point in the history
  • Loading branch information
HyperLan-git committed Aug 4, 2024
1 parent 741bce1 commit 5d6ab76
Show file tree
Hide file tree
Showing 16 changed files with 322 additions and 53 deletions.
12 changes: 12 additions & 0 deletions Fased/Builds/LinuxMakefile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ OBJECTS_STANDALONE_PLUGIN := \
$(JUCE_OBJDIR)/include_juce_audio_plugin_client_Standalone_1a871192.o \

OBJECTS_SHARED_CODE := \
$(JUCE_OBJDIR)/FreqResponseComponent_b9068b85.o \
$(JUCE_OBJDIR)/SelectorComponent_72293e3f.o \
$(JUCE_OBJDIR)/BiquadFilter_a6b254af.o \
$(JUCE_OBJDIR)/PluginProcessor_a059e380.o \
$(JUCE_OBJDIR)/KnobComponent_fed34708.o \
Expand Down Expand Up @@ -202,6 +204,16 @@ $(JUCE_OBJDIR)/include_juce_audio_plugin_client_Standalone_1a871192.o: ../../Juc
@echo "Compiling include_juce_audio_plugin_client_Standalone.cpp"
$(V_AT)$(CXX) $(JUCE_CXXFLAGS) $(JUCE_CPPFLAGS_STANDALONE_PLUGIN) $(JUCE_CFLAGS_STANDALONE_PLUGIN) -o "$@" -c "$<"

$(JUCE_OBJDIR)/FreqResponseComponent_b9068b85.o: ../../Source/FreqResponseComponent.cpp
-$(V_AT)mkdir -p $(@D)
@echo "Compiling FreqResponseComponent.cpp"
$(V_AT)$(CXX) $(JUCE_CXXFLAGS) $(JUCE_CPPFLAGS_SHARED_CODE) $(JUCE_CFLAGS_SHARED_CODE) -o "$@" -c "$<"

$(JUCE_OBJDIR)/SelectorComponent_72293e3f.o: ../../Source/SelectorComponent.cpp
-$(V_AT)mkdir -p $(@D)
@echo "Compiling SelectorComponent.cpp"
$(V_AT)$(CXX) $(JUCE_CXXFLAGS) $(JUCE_CPPFLAGS_SHARED_CODE) $(JUCE_CFLAGS_SHARED_CODE) -o "$@" -c "$<"

$(JUCE_OBJDIR)/BiquadFilter_a6b254af.o: ../../Source/BiquadFilter.cpp
-$(V_AT)mkdir -p $(@D)
@echo "Compiling BiquadFilter.cpp"
Expand Down
4 changes: 4 additions & 0 deletions Fased/Builds/VisualStudio2022/Fased_SharedCode.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
</Bscmake>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\Source\FreqResponseComponent.cpp"/>
<ClCompile Include="..\..\Source\SelectorComponent.cpp"/>
<ClCompile Include="..\..\Source\BiquadFilter.cpp"/>
<ClCompile Include="..\..\Source\PluginProcessor.cpp"/>
<ClCompile Include="..\..\Source\KnobComponent.cpp"/>
Expand Down Expand Up @@ -2825,6 +2827,8 @@
<ClCompile Include="..\..\JuceLibraryCode\include_juce_gui_extra.cpp"/>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\Source\FreqResponseComponent.hpp"/>
<ClInclude Include="..\..\Source\SelectorComponent.hpp"/>
<ClInclude Include="..\..\Source\BiquadFilter.hpp"/>
<ClInclude Include="..\..\Source\PluginProcessor.h"/>
<ClInclude Include="..\..\Source\KnobComponent.hpp"/>
Expand Down
12 changes: 12 additions & 0 deletions Fased/Builds/VisualStudio2022/Fased_SharedCode.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,12 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\Source\FreqResponseComponent.cpp">
<Filter>Fased\Source</Filter>
</ClCompile>
<ClCompile Include="..\..\Source\SelectorComponent.cpp">
<Filter>Fased\Source</Filter>
</ClCompile>
<ClCompile Include="..\..\Source\BiquadFilter.cpp">
<Filter>Fased\Source</Filter>
</ClCompile>
Expand Down Expand Up @@ -3564,6 +3570,12 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\Source\FreqResponseComponent.hpp">
<Filter>Fased\Source</Filter>
</ClInclude>
<ClInclude Include="..\..\Source\SelectorComponent.hpp">
<Filter>Fased\Source</Filter>
</ClInclude>
<ClInclude Include="..\..\Source\BiquadFilter.hpp">
<Filter>Fased\Source</Filter>
</ClInclude>
Expand Down
8 changes: 8 additions & 0 deletions Fased/Fased.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
addUsingNamespaceToJuceHeader="0" jucerFormatVersion="1">
<MAINGROUP id="IRbPzB" name="Fased">
<GROUP id="{44BCDEC5-5FB9-EE5A-5196-CD4D90010E59}" name="Source">
<FILE id="nkbU73" name="FreqResponseComponent.cpp" compile="1" resource="0"
file="Source/FreqResponseComponent.cpp"/>
<FILE id="pshHSn" name="FreqResponseComponent.hpp" compile="0" resource="0"
file="Source/FreqResponseComponent.hpp"/>
<FILE id="GuhDNY" name="SelectorComponent.cpp" compile="1" resource="0"
file="Source/SelectorComponent.cpp"/>
<FILE id="wumvJf" name="SelectorComponent.hpp" compile="0" resource="0"
file="Source/SelectorComponent.hpp"/>
<FILE id="m1IS3x" name="BiquadFilter.cpp" compile="1" resource="0"
file="Source/BiquadFilter.cpp"/>
<FILE id="zWNOzP" name="BiquadFilter.hpp" compile="0" resource="0"
Expand Down
8 changes: 3 additions & 5 deletions Fased/Source/BiquadFilter.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "BiquadFilter.hpp"

#define PI 3.141592653589793f

BiquadFilter::BiquadFilter(int sampleRate) : sampleRate(sampleRate) {}

BiquadFilter::BiquadFilter(struct BiquadFilterCoefficients coeffs,
Expand Down Expand Up @@ -35,7 +33,7 @@ void BiquadFilter::updateParameters() {

const float A = std::pow(10, this->parameters.gain / 40),
sqrtA = std::sqrt(A);
const float om = PI * 2 * this->parameters.f / this->sampleRate;
const float om = M_PI * 2 * this->parameters.f / this->sampleRate;
const float a = std::sin(om) / (2 * this->parameters.Q);
const float cs = std::cos(om), sn = std::sin(om);
switch (this->type) {
Expand Down Expand Up @@ -99,10 +97,10 @@ void BiquadFilter::updateParameters() {
case HIGHSHELF:
this->coefficients = {
.b0 = A * ((A + 1) + (A - 1) * cs + 2 * sqrtA * a),
.b1 = -2 * A * ((A - 1) - (A + 1) * cs),
.b1 = -2 * A * ((A - 1) + (A + 1) * cs),
.b2 = A * ((A + 1) + (A - 1) * cs - 2 * sqrtA * a),
.a0 = (A + 1) - (A - 1) * cs + 2 * sqrtA * a,
.a1 = 2 * ((A - 1) + (A + 1) * cs),
.a1 = 2 * ((A - 1) - (A + 1) * cs),
.a2 = (A + 1) - (A - 1) * cs - 2 * sqrtA * a};
break;
default:
Expand Down
17 changes: 10 additions & 7 deletions Fased/Source/BiquadFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <cmath>
#include <string>
#include "JuceHeader.h"

enum BiquadFilterType {
UNKOWN = 0,
Expand All @@ -16,12 +15,6 @@ enum BiquadFilterType {
HIGHSHELF = 8
};

constexpr const char* FILTER_TYPES[] = {"Allpass", "Lowpass", "Highpass",
"Bandpass", "Notch", "Peak",
"Lowshelf", "Highshelf"};

const juce::StringArray BIQUAD_TYPES = juce::StringArray(FILTER_TYPES);

struct BiquadFilterParams {
float f;
float Q;
Expand All @@ -33,6 +26,16 @@ struct SOState {
};

struct BiquadFilterCoefficients {
bool operator==(BiquadFilterCoefficients other) const {
return this->a0 == other.a0 && this->a1 == other.a1 &&
this->a2 == other.a2 && this->b0 == other.b0 &&
this->b1 == other.b1 && this->b2 == other.b2;
}

inline bool operator!=(BiquadFilterCoefficients other) const {
return !this->operator==(other);
}

float b0 = 1;
float b1 = 0;
float b2 = 0;
Expand Down
79 changes: 79 additions & 0 deletions Fased/Source/FreqResponseComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "FreqResponseComponent.hpp"

FreqResponseComponent::FreqResponseComponent(
const BiquadFilter& filter, juce::AudioParameterInt* filterParam)
: filter(filter), filterParam(filterParam) {
setSize(400, 400);
}

constexpr float a = std::log10(MAX_FREQ), b = std::log10(40);

constexpr float MAX_DB = 40;

void FreqResponseComponent::paint(juce::Graphics& g) {
using namespace std::complex_literals;

BiquadFilterCoefficients c = filter.getCoeffs();
int filters = *filterParam;
int w = this->getWidth(), h = this->getHeight();
if (w <= 1) return;
if (c != this->lastCoeffs || filters != this->lastFilters) {
for (int i = 0; i < w; i++) {
float f = std::pow(10, i * (a - b) / (w - 1) + b);
std::complex<float> z = std::__complex_exp<float>(
1if * juce::MathConstants<float>::pi * f /
MAX_FREQ),
z1 = 1.f / z, z2 = 1.f / (z * z);
values[i] =
(c.b0 + c.b1 * z1 + c.b2 * z2) / (c.a0 + c.a1 * z1 + c.a2 * z2);
if (filters > 1) values[i] = std::pow(values[i], filters);
}
this->lastFilters = filters;
this->lastCoeffs = c;
}

g.fillAll(juce::Colours::black);

juce::Path p, p2;

p.preallocateSpace(w);
p.startNewSubPath({-200, h / 2.f});

p2.preallocateSpace(w);
p2.startNewSubPath({-200, h / 2.f});
for (int x = 0; x < w; x++) {
float mag = 20 * std::log10(std::abs(values[x])),
phase = std::arg(values[x]);
int y = h / 2 - h * mag / MAX_DB / 2,
y2 = h / 2 - h * phase / juce::MathConstants<float>::pi / 2;
if (values[x].real() == 0 && values[x].imag() == 0) {
y = h + 20;
y2 = h + 20;
}
p.lineTo(x, y);
p2.lineTo(x, y2);
}
p.lineTo(w + 200, h / 2.f);
p.lineTo(w, h + 20);
p.lineTo(-200, h + 20);
p.closeSubPath();

p2.lineTo(w + 200, h / 2.f);
p2.lineTo(w, h + 20);
p2.lineTo(-200, h + 20);
p2.closeSubPath();

g.setColour(juce::Colours::orange);
g.fillPath(p);
g.setColour(juce::Colours::orange.darker());
g.strokePath(p, juce::PathStrokeType(5),
juce::AffineTransform().withAbsoluteTranslation(0, 3));

g.setColour(juce::Colours::cyan.withAlpha(.3f));
g.fillPath(p2);
g.setColour(juce::Colours::cyan.darker().withAlpha(.3f));
g.strokePath(p2, juce::PathStrokeType(5),
juce::AffineTransform().withAbsoluteTranslation(0, 3));
}

void FreqResponseComponent::resized() {}
27 changes: 27 additions & 0 deletions Fased/Source/FreqResponseComponent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <JuceHeader.h>
#include <complex>
#include <cmath>
#include "BiquadFilter.hpp"

constexpr int MAX_WIDTH = 400;
constexpr float MAX_FREQ = 22000;

class FreqResponseComponent : public juce::Component {
public:
FreqResponseComponent(const BiquadFilter& filter,
juce::AudioParameterInt* filterParam);

void paint(juce::Graphics& g) override;

void resized() override;

private:
const BiquadFilter& filter;
juce::AudioParameterInt* filterParam;

BiquadFilterCoefficients lastCoeffs = {};
int lastFilters = 0;
std::complex<float> values[MAX_WIDTH] = {};
};
8 changes: 3 additions & 5 deletions Fased/Source/KnobComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ void ParamListener::parameterGestureChanged(int parameterIndex,
}

KnobComponent::KnobComponent(juce::RangedAudioParameter* param, double step)
: paramListener(param, knob), label() {
: paramListener(param, knob),
label(param->getName(128), param->getName(128)) {
addAndMakeVisible(knob);
addAndMakeVisible(label);

Expand All @@ -59,10 +60,7 @@ KnobComponent::KnobComponent(juce::RangedAudioParameter* param, double step)
setSize(100, 100);
}

KnobComponent::~KnobComponent() {
knob.removeListener(&paramListener);
knob.setLookAndFeel(nullptr);
}
KnobComponent::~KnobComponent() { knob.setLookAndFeel(nullptr); }

void KnobComponent::paint(juce::Graphics& g) {
g.fillAll(juce::Colours::black);
Expand Down
30 changes: 11 additions & 19 deletions Fased/Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,33 @@ FasedAudioProcessorEditor::FasedAudioProcessorEditor(FasedAudioProcessor& p)
audioProcessor(p),
freq(p.getFreqParam()),
gain(p.getGainParam()),
Q(p.getQParam()) {
setSize(400, 500);
Q(p.getQParam()),
filters(p.getFiltersParam()),
filterType(p.getTypeParam()),
graph(p.getFilter(), p.getFiltersParam()) {
setSize(400, 550);

this->addAndMakeVisible(freq);
this->addAndMakeVisible(Q);
this->addAndMakeVisible(gain);
this->addAndMakeVisible(filters);
this->addAndMakeVisible(filterType);

filterType.addItemList(BIQUAD_TYPES, 1);

filterType.onChange = [this] { this->onSelectFilterType(); };
filterType.setSelectedId(p.getTypeParam()->getIndex() + 1);
// TODO p.addListener
this->addAndMakeVisible(graph);
}

FasedAudioProcessorEditor::~FasedAudioProcessorEditor() {}

void FasedAudioProcessorEditor::paint(juce::Graphics& g) {
g.fillAll(
getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));

g.setColour(juce::Colours::white);
g.setFont(juce::FontOptions(15.0f));
g.fillAll(juce::Colours::grey);
}

void FasedAudioProcessorEditor::resized() {
freq.setBounds(0, 0, 100, 100);
Q.setBounds(100, 0, 100, 100);
gain.setBounds(200, 0, 100, 100);
filters.setBounds(300, 0, 100, 100);

filterType.setBounds(300, 0, 100, 40);
}
filterType.setBounds(0, 100, 200, 40);

void FasedAudioProcessorEditor::onSelectFilterType() {
int id = this->filterType.getSelectedId();
if (id == 0) return;
this->audioProcessor.setFilterType((enum BiquadFilterType)(id - 1));
graph.setBounds(0, 150, 400, 400);
}
9 changes: 5 additions & 4 deletions Fased/Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <JuceHeader.h>
#include "PluginProcessor.h"
#include "KnobComponent.hpp"
#include "FreqResponseComponent.hpp"
#include "SelectorComponent.hpp"

class FasedAudioProcessorEditor : public juce::AudioProcessorEditor {
public:
Expand All @@ -13,13 +15,12 @@ class FasedAudioProcessorEditor : public juce::AudioProcessorEditor {
void resized() override;

private:
void onSelectFilterType();

FasedAudioProcessor& audioProcessor;

KnobComponent freq, Q, gain;
KnobComponent freq, Q, gain, filters;
SelectorComponent filterType;

juce::ComboBox filterType;
FreqResponseComponent graph;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FasedAudioProcessorEditor)
};
Loading

0 comments on commit 5d6ab76

Please sign in to comment.