Skip to content

Commit

Permalink
Remove snake oil "quality" mode
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Nov 13, 2021
1 parent 6b8c64d commit 4802727
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 1,628 deletions.
108 changes: 3 additions & 105 deletions src/capacitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ See ./LICENSE.md for all licenses

#include "plugin.hpp"

// quality options
#define ECO 0
#define HIGH 1

struct Capacitor : Module {
enum ParamIds {
LOWPASS_PARAM,
Expand All @@ -43,7 +39,6 @@ struct Capacitor : Module {
// module variables
const double gainCut = 0.03125;
const double gainBoost = 32.0;
int quality;

// control parameters
float lowpassParam;
Expand All @@ -69,7 +64,7 @@ struct Capacitor : Module {
double lastLowpass[16];
double lastHighpass[16];
int count[16];
long double fpNShape[16];
double fpNShape[16];

// other
double overallscale;
Expand All @@ -80,7 +75,6 @@ struct Capacitor : Module {
configParam(LOWPASS_PARAM, 0.f, 1.f, 1.f, "Lowpass");
configParam(HIGHPASS_PARAM, 0.f, 1.f, 0.f, "Highpass");

quality = loadQuality();
onReset();
}

Expand Down Expand Up @@ -121,24 +115,6 @@ struct Capacitor : Module {
overallscale *= sampleRate;
}

json_t* dataToJson() override
{
json_t* rootJ = json_object();

// quality
json_object_set_new(rootJ, "quality", json_integer(quality));

return rootJ;
}

void dataFromJson(json_t* rootJ) override
{
// quality
json_t* qualityJ = json_object_get(rootJ, "quality");
if (qualityJ)
quality = json_integer_value(qualityJ);
}

void process(const ProcessArgs& args) override
{
if (outputs[OUT_OUTPUT].isConnected()) {
Expand All @@ -155,7 +131,7 @@ struct Capacitor : Module {
double highpassSpeed;
double invLowpass;
double invHighpass;
long double inputSample;
double inputSample;

// for each poly channel
for (int i = 0, numChannels = std::max(1, inputs[IN_INPUT].getChannels()); i < numChannels; ++i) {
Expand All @@ -175,33 +151,6 @@ struct Capacitor : Module {
// pad gain
inputSample *= gainCut;

if (quality == HIGH) {
if (inputSample < 1.2e-38 && -inputSample < 1.2e-38) {
static int noisesource = 0;
//this declares a variable before anything else is compiled. It won't keep assigning
//it to 0 for every sample, it's as if the declaration doesn't exist in this context,
//but it lets me add this denormalization fix in a single place rather than updating
//it in three different locations. The variable isn't thread-safe but this is only
//a random seed and we can share it with whatever.
noisesource = noisesource % 1700021;
noisesource++;
int residue = noisesource * noisesource;
residue = residue % 170003;
residue *= residue;
residue = residue % 17011;
residue *= residue;
residue = residue % 1709;
residue *= residue;
residue = residue % 173;
residue *= residue;
residue = residue % 17;
double applyresidue = residue;
applyresidue *= 0.00000001;
applyresidue *= 0.00000001;
inputSample = applyresidue;
}
}

lowpassAmount[i] = (((lowpassAmount[i] * lowpassSpeed) + lowpassChase[i]) / (lowpassSpeed + 1.0));
invLowpass = 1.0 - lowpassAmount[i];
highpassAmount[i] = (((highpassAmount[i] * highpassSpeed) + highpassChase[i]) / (highpassSpeed + 1.0));
Expand Down Expand Up @@ -299,16 +248,6 @@ struct Capacitor : Module {
break;
}

//stereo 32 bit dither, made small and tidy.
if (quality == HIGH) {
int expon;
frexpf((float)inputSample, &expon);
long double dither = (rand() / (RAND_MAX * 7.737125245533627e+25)) * pow(2, expon + 62);
inputSample += (dither - fpNShape[i]);
fpNShape[i] = dither;
//end 32 bit dither
}

// bring gain back up
inputSample *= gainBoost;

Expand All @@ -321,47 +260,6 @@ struct Capacitor : Module {
};

struct CapacitorWidget : ModuleWidget {

// quality item
struct QualityItem : MenuItem {
Capacitor* module;
int quality;

void onAction(const event::Action& e) override
{
module->quality = quality;
}

void step() override
{
rightText = (module->quality == quality) ? "" : "";
}
};

void appendContextMenu(Menu* menu) override
{
Capacitor* module = dynamic_cast<Capacitor*>(this->module);
assert(module);

menu->addChild(new MenuSeparator()); // separator

MenuLabel* qualityLabel = new MenuLabel(); // menu label
qualityLabel->text = "Quality";
menu->addChild(qualityLabel);

QualityItem* low = new QualityItem(); // low quality
low->text = "Eco";
low->module = module;
low->quality = 0;
menu->addChild(low);

QualityItem* high = new QualityItem(); // high quality
high->text = "High";
high->module = module;
high->quality = 1;
menu->addChild(high);
}

CapacitorWidget(Capacitor* module)
{
setModule(module);
Expand All @@ -385,4 +283,4 @@ struct CapacitorWidget : ModuleWidget {
}
};

Model* modelCapacitor = createModel<Capacitor, CapacitorWidget>("capacitor");
Model* modelCapacitor = createModel<Capacitor, CapacitorWidget>("capacitor");
110 changes: 4 additions & 106 deletions src/capacitor_stereo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ See ./LICENSE.md for all licenses

#include "plugin.hpp"

// quality options
#define ECO 0
#define HIGH 1

struct Capacitor_stereo : Module {
enum ParamIds {
LOWPASS_L_PARAM,
Expand Down Expand Up @@ -54,7 +50,6 @@ struct Capacitor_stereo : Module {
const double gainCut = 0.03125;
const double gainBoost = 32.0;
bool isLinked;
bool quality;
float lastLowpassParam;
float lastHighpassParam;

Expand Down Expand Up @@ -87,7 +82,7 @@ struct Capacitor_stereo : Module {
double lastHighpass;
double lastWet;
int count;
long double fpNShape;
double fpNShape;
} stateL[16], stateR[16];

// other
Expand All @@ -104,7 +99,6 @@ struct Capacitor_stereo : Module {
configParam(LINK_PARAM, 0.f, 1.f, 1.f, "Link");

isLinked = true;
quality = loadQuality();
onReset();
}

Expand Down Expand Up @@ -150,24 +144,6 @@ struct Capacitor_stereo : Module {
}
}

json_t* dataToJson() override
{
json_t* rootJ = json_object();

// quality
json_object_set_new(rootJ, "quality", json_integer(quality));

return rootJ;
}

void dataFromJson(json_t* rootJ) override
{
// quality
json_t* qualityJ = json_object_get(rootJ, "quality");
if (qualityJ)
quality = json_integer_value(qualityJ);
}

void processChannel(stateVars v[], Param& lowpass, Param& highpass, Param& drywet, Input& lowpassCv, Input& highpassCv, Input& drywetCv, Input& input, Output& output)
{
// params
Expand All @@ -190,8 +166,8 @@ struct Capacitor_stereo : Module {
double invHighpass;
double dry;

long double inputSample;
long double drySample;
double inputSample;
double drySample;

// for each poly channel
for (int i = 0, numChannels = std::max(1, input.getChannels()); i < numChannels; ++i) {
Expand All @@ -214,33 +190,6 @@ struct Capacitor_stereo : Module {
// pad gain
inputSample *= gainCut;

if (quality == HIGH) {
if (inputSample < 1.2e-38 && -inputSample < 1.2e-38) {
static int noisesource = 0;
//this declares a variable before anything else is compiled. It won't keep assigning
//it to 0 for every sample, it's as if the declaration doesn't exist in this context,
//but it lets me add this denormalization fix in a single place rather than updating
//it in three different locations. The variable isn't thread-safe but this is only
//a random seed and we can share it with whatever.
noisesource = noisesource % 1700021;
noisesource++;
int residue = noisesource * noisesource;
residue = residue % 170003;
residue *= residue;
residue = residue % 17011;
residue *= residue;
residue = residue % 1709;
residue *= residue;
residue = residue % 173;
residue *= residue;
residue = residue % 17;
double applyresidue = residue;
applyresidue *= 0.00000001;
applyresidue *= 0.00000001;
inputSample = applyresidue;
}
}

drySample = inputSample;

v[i].lowpassAmount = (((v[i].lowpassAmount * lowpassSpeed) + v[i].lowpassChase) / (lowpassSpeed + 1.0));
Expand Down Expand Up @@ -344,16 +293,6 @@ struct Capacitor_stereo : Module {

inputSample = (drySample * dry) + (inputSample * v[i].wet);

if (quality == HIGH) {
//stereo 32 bit dither, made small and tidy.
int expon;
frexpf((float)inputSample, &expon);
long double dither = (rand() / (RAND_MAX * 7.737125245533627e+25)) * pow(2, expon + 62);
inputSample += (dither - v[i].fpNShape);
v[i].fpNShape = dither;
//end 32 bit dither
}

// bring gain back up
inputSample *= gainBoost;

Expand Down Expand Up @@ -397,47 +336,6 @@ struct Capacitor_stereo : Module {
};

struct Capacitor_stereoWidget : ModuleWidget {

// quality item
struct QualityItem : MenuItem {
Capacitor_stereo* module;
int quality;

void onAction(const event::Action& e) override
{
module->quality = quality;
}

void step() override
{
rightText = (module->quality == quality) ? "" : "";
}
};

void appendContextMenu(Menu* menu) override
{
Capacitor_stereo* module = dynamic_cast<Capacitor_stereo*>(this->module);
assert(module);

menu->addChild(new MenuSeparator()); // separator

MenuLabel* qualityLabel = new MenuLabel(); // menu label
qualityLabel->text = "Quality";
menu->addChild(qualityLabel);

QualityItem* low = new QualityItem(); // low quality
low->text = "Eco";
low->module = module;
low->quality = 0;
menu->addChild(low);

QualityItem* high = new QualityItem(); // high quality
high->text = "High";
high->module = module;
high->quality = 1;
menu->addChild(high);
}

Capacitor_stereoWidget(Capacitor_stereo* module)
{
setModule(module);
Expand Down Expand Up @@ -477,4 +375,4 @@ struct Capacitor_stereoWidget : ModuleWidget {
}
};

Model* modelCapacitor_stereo = createModel<Capacitor_stereo, Capacitor_stereoWidget>("capacitor_stereo");
Model* modelCapacitor_stereo = createModel<Capacitor_stereo, Capacitor_stereoWidget>("capacitor_stereo");
Loading

0 comments on commit 4802727

Please sign in to comment.