Skip to content

Commit

Permalink
custom DSP, button GUI, audio tracks
Browse files Browse the repository at this point in the history
-Custom compressor DSP module following Eric Tarr Hack Audio
-started working on button with .cpp file and a method to make visibile new look and feel needed
-standalone .cpp file for labels
-new audio track
  • Loading branch information
sadmemelord committed Feb 7, 2023
1 parent faec816 commit 3a85864
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 26 deletions.
Binary file removed AudioTracks/LetsAllLoveLain.mp3
Binary file not shown.
Binary file added AudioTracks/drumLoop120BPM.wav
Binary file not shown.
12 changes: 12 additions & 0 deletions QuasoCompressor.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@
displaySplashScreen="1" jucerFormatVersion="1" companyName="sadmemelord">
<MAINGROUP id="AsMcn2" name="QuasoCompressor">
<GROUP id="{D7589DD5-C5DE-D5EC-0ABB-CC849D0320A2}" name="Source">
<GROUP id="{3AA7347B-C769-588D-D2C3-E9D9D6869278}" name="DSP">
<FILE id="xldVei" name="CustomCompressor.cpp" compile="1" resource="0"
file="Source/DSP/CustomCompressor.cpp"/>
<FILE id="PdVLdv" name="CustomCompressor.h" compile="0" resource="0"
file="Source/DSP/CustomCompressor.h"/>
</GROUP>
<GROUP id="{934AFFCF-E6D9-A510-94D9-DF6065430908}" name="Parameters">
<FILE id="ej4ums" name="Parameters.cpp" compile="1" resource="0" file="Source/Parameters/Parameters.cpp"/>
<FILE id="mhnrMB" name="Parameters.h" compile="0" resource="0" file="Source/Parameters/Parameters.h"/>
</GROUP>
<GROUP id="{2FCDF22E-12E8-C833-F580-A2D5C8080127}" name="GUI">
<GROUP id="{7A552564-44BA-2D36-BAD5-A6BDE6689467}" name="Buttons">
<FILE id="t6P086" name="Buttons.cpp" compile="1" resource="0" file="Source/GUI/Buttons/Buttons.cpp"/>
</GROUP>
<GROUP id="{2933A0D2-F796-2453-8CE3-E15B4C2809B5}" name="Groups">
<FILE id="aTV8bt" name="Groups.cpp" compile="1" resource="0" file="Source/GUI/Groups/Groups.cpp"/>
</GROUP>
<GROUP id="{AECC7D59-22E4-71EC-A4C6-115669E4CDC5}" name="Labels">
<FILE id="EB3I42" name="Labels.cpp" compile="1" resource="0" file="Source/GUI/Labels/Labels.cpp"/>
</GROUP>
<GROUP id="{2F35E864-726F-E587-054A-5BD819F58A90}" name="LookAndFeel">
<FILE id="z0bHft" name="DialLAF.cpp" compile="1" resource="0" file="Source/GUI/LookAndFeel/DialLAF.cpp"/>
<FILE id="s7ERMe" name="DialLAF.h" compile="0" resource="0" file="Source/GUI/LookAndFeel/DialLAF.h"/>
Expand Down
50 changes: 50 additions & 0 deletions Source/DSP/CustomCompressor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
==============================================================================
CustomCompressor.cpp
Created: 7 Feb 2023 4:07:01pm
Author: Utente
==============================================================================
*/

#include "CustomCompressor.h"

CustomCompressor::CustomCompressor()
{

}


void CustomCompressor::prepare(juce::dsp::ProcessSpec& spec) noexcept
{
_sampleRate = spec.sampleRate;
}


void CustomCompressor::setThreshold(float newThresh)
{
_thresh = newThresh;
}


void CustomCompressor::setRatio(float newRatio)
{
_ratio = newRatio;
}


void CustomCompressor::setAttack(float newAttack)
{
_attack = newAttack / 1000.0f;
}

void CustomCompressor::setRelease(float newRelease)
{
_release = newRelease / 1000.0f;
}

void CustomCompressor::setBypass(bool newBypass)
{
_isBypassed = newBypass;
}
132 changes: 132 additions & 0 deletions Source/DSP/CustomCompressor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
==============================================================================
CustomCompressor.h
Created: 7 Feb 2023 4:07:01pm
Author: Utente
==============================================================================
*/

#pragma once
#include <JuceHeader.h>

class CustomCompressor
{

public:
CustomCompressor();

void prepare(juce::dsp::ProcessSpec& spec) noexcept;

void process(juce::AudioBuffer<float>& buffer) noexcept
{
//the process method is defined in the header file
//because it is passed through the translation unit
//and has a better chance of being optimized
//bypassing the dsp

if (_isBypassed == true)
return;

auto data = buffer.getArrayOfWritePointers();

//sample/channel loop
for(int sample = 0; sample < buffer.getNumSamples(); ++sample)
{

for (int ch = 0; ch < buffer.getNumChannels(); ++ch)
{
data[ch][sample] = processSample(data[ch][sample]);
}
}
}

float processSample(float inputValue)
{
//attack and release variable from Eric Tarr Hack Audio
auto alphaAttack = std::exp((std::log(9) * -1.0) / (_sampleRate * _attack));
auto alphaRelease = std::exp((std::log(9) * -1.0) / (_sampleRate * _release));

const auto input = inputValue;

//input dividedin unipolar (absolute value) and dB values
auto input_uni = std::abs(input); //maybe remove std
auto input_dB = juce::Decibels::gainToDecibels(input_uni / 1.0);

//checking that no value in dB are negative infinity
if (input_dB < -96)
{
input_dB = -96;
}

if (input_dB > _thresh)
{
_gainSC = _thresh + (input_dB - _thresh) / _ratio;
}

else
{
_gainSC = input_dB;
}

_gainChange_dB = _gainSC - input_dB;

if (_gainChange_dB < _gainSmoothPrevious)
{
_gainSmooth = ((1.0 - alphaAttack) * _gainChange_dB) + (alphaAttack * _gainSmoothPrevious);
_currentSignal = _gainSmooth;
}

else
{
_gainSmooth = ((1.0 - alphaRelease) * _gainChange_dB) + (alphaRelease * _gainSmoothPrevious);
_currentSignal = _gainSmooth;

}

auto output = input * juce::Decibels::decibelsToGain(_gainSmooth);
_gainSmoothPrevious = _gainSmooth;

//output signal
return output;

}

void setThreshold(float newThresh);
void setRatio(float newRatio);
void setAttack(float newAttack);
void setRelease(float newRelease);
void setBypass(bool newBypass);


private:

//compressor parameters
float _thresh = 0.0f;
float _ratio = 1.0f;
float _attack = 50.0f / 1000.0f ;
float _release = 160.0f / 1000.0f;
bool _isBypassed = false;

//sample rate
float _sampleRate = 44100.0f;

//gain sidechain
float _gainSC = 0.0f;

//gain smooth
float _gainSmooth = 0.0f;

//gain smooth previous
float _gainSmoothPrevious = 0.0f;

//current signal
float _currentSignal = 0.0f;

//gain change in decibels
float _gainChange_dB = 0.0f;



};
16 changes: 16 additions & 0 deletions Source/GUI/Buttons/Buttons.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
==============================================================================
Buttons.cpp
Created: 7 Feb 2023 8:21:22pm
Author: Utente
==============================================================================
*/

#include "../../PluginEditor.h"

void QuasoCompressorAudioProcessorEditor::setButtonProps(juce::ToggleButton& button)
{
addAndMakeVisible(button);
}
19 changes: 19 additions & 0 deletions Source/GUI/Labels/Labels.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
==============================================================================
Labels.cpp
Created: 7 Feb 2023 8:23:29pm
Author: Utente
==============================================================================
*/

#include "../../PluginEditor.h"

void QuasoCompressorAudioProcessorEditor::setCommonLabelProps(juce::Label& label)
{
//setting properties common to every slider
addAndMakeVisible(label);
label.setFont(juce::Font("Helvetica", 16.0f, juce::Font::FontStyleFlags::bold));
label.setJustificationType(juce::Justification::centred);
}
9 changes: 0 additions & 9 deletions Source/GUI/Sliders/SliderProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,3 @@ void QuasoCompressorAudioProcessorEditor::attachSliders()
outputAttach = std::make_unique<SliderAttachment>(audioProcessor.apvts, outputID, outputDial);

}

void QuasoCompressorAudioProcessorEditor::setCommonLabelProps(juce::Label& label)
{
//setting properties common to every slider
addAndMakeVisible(label);
label.setFont(juce::Font("Helvetica", 16.0f, juce::Font::FontStyleFlags::bold));
label.setJustificationType(juce::Justification::centred);
}

7 changes: 7 additions & 0 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ QuasoCompressorAudioProcessorEditor::QuasoCompressorAudioProcessorEditor (QuasoC
setGroupProps(*groups[i]);
}

for (int i = 0; i < buttons.size(); i++)
{
setButtonProps(*buttons[i]);
}

//some properties are different between dials like the textbox suffix
//inputDial.setColour(juce::Slider::ColourIds::thumbColourId, juce::Colours::indianred.darker(0.3));
inputDial.setTextValueSuffix(" dB");
Expand Down Expand Up @@ -138,6 +143,8 @@ void QuasoCompressorAudioProcessorEditor::resized()

limiterGroup.setBounds(limThreshDial.getX(), limThreshDial.getY() * 0.1,
limThreshDial.getWidth(), limThreshDial.getY() + limThreshDial.getHeight() * 2.4);

compBypassButton.setBounds(ratioDial.getX() , getLocalBounds().getY() / 2, 100, 100);



Expand Down
15 changes: 14 additions & 1 deletion Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,23 @@ class QuasoCompressorAudioProcessorEditor : public juce::AudioProcessorEditor
&limiterGroup
};

//method to set some properties common to every silder, label and group
//buttons
juce::ToggleButton compBypassButton;
juce::ToggleButton limBypassButton;

//buttons vector
std::vector<juce::ToggleButton*> buttons =
{
&compBypassButton,
&limBypassButton
};


//method to set some properties common to every silders, labels, groups and buttons
void setCommonSliderProps(juce::Slider& slider);
void setCommonLabelProps(juce::Label& label);
void setGroupProps(juce::GroupComponent& group);
void setButtonProps(juce::ToggleButton& button);

//setting up attachment
using Attachment = std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment>;
Expand Down
12 changes: 6 additions & 6 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ void QuasoCompressorAudioProcessor::updateParameters()
{
//the load method is needed because the raw parameters are atomic
inputModule.setGainDecibels(apvts.getRawParameterValue(inputID)->load());
compressorModule.setThreshold(apvts.getRawParameterValue(threshID)->load());
compressorModule.setRatio(apvts.getRawParameterValue(ratioID)->load());
compressorModule.setAttack(apvts.getRawParameterValue(attackID)->load());
compressorModule.setRelease(apvts.getRawParameterValue(releaseID)->load());
customCompressorModule.setThreshold(apvts.getRawParameterValue(threshID)->load());
customCompressorModule.setRatio(apvts.getRawParameterValue(ratioID)->load());
customCompressorModule.setAttack(apvts.getRawParameterValue(attackID)->load());
customCompressorModule.setRelease(apvts.getRawParameterValue(releaseID)->load());
limiterModule.setThreshold(apvts.getRawParameterValue(limThreshID)->load());
limiterModule.setRelease(apvts.getRawParameterValue(limReleaseID)->load());
outputModule.setGainDecibels(apvts.getRawParameterValue(outputID)->load());
Expand Down Expand Up @@ -192,7 +192,7 @@ void QuasoCompressorAudioProcessor::prepareToPlay (double sampleRate, int sample
outputModule.setRampDurationSeconds(0.02);
outputModule.prepare(spec);

compressorModule.prepare(spec);
customCompressorModule.prepare(spec);

limiterModule.prepare(spec);

Expand Down Expand Up @@ -241,7 +241,7 @@ void QuasoCompressorAudioProcessor::processBlock (juce::AudioBuffer<float>& buff

//process DSP modules
inputModule.process(juce::dsp::ProcessContextReplacing<float>(block));
compressorModule.process(juce::dsp::ProcessContextReplacing<float>(block));
customCompressorModule.process(buffer);
limiterModule.process(juce::dsp::ProcessContextReplacing<float>(block));
outputModule.process(juce::dsp::ProcessContextReplacing<float>(block));

Expand Down
4 changes: 4 additions & 0 deletions Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <JuceHeader.h>
#include "./Parameters/Parameters.h"
#include "./DSP/CustomCompressor.h"

//==============================================================================
/**
Expand Down Expand Up @@ -72,6 +73,9 @@ class QuasoCompressorAudioProcessor : public juce::AudioProcessor, juce::AudioP
//the dsp module also implements a compressor module
juce::dsp::Compressor<float> compressorModule;

//custom dsp compressor module based on Eric Tarr HACK AUDIO
CustomCompressor customCompressorModule;

//limiter module
juce::dsp::Limiter<float> limiterModule;

Expand Down
Loading

0 comments on commit 3a85864

Please sign in to comment.