Skip to content

Commit

Permalink
New dephase option (#76)
Browse files Browse the repository at this point in the history
* wip

* wip actual dephasing

* fixed bad stereo

* make new phase optional

* better dephase rate

* odd

* better default
  • Loading branch information
isivisi committed Feb 8, 2024
1 parent a459c48 commit 01dab78
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 38 deletions.
8 changes: 6 additions & 2 deletions presets/quatosc/4leafclover.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 7.7397608757019043,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":1.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
]
}
}
6 changes: 5 additions & 1 deletion presets/quatosc/Banana.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 5.6385593414306641,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":1.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
]
}
6 changes: 5 additions & 1 deletion presets/quatosc/BlinkingEye.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 6.2843341827392578,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":4.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
],
"data": {
Expand Down
6 changes: 5 additions & 1 deletion presets/quatosc/Carousel.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 0.019277108833193779,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":1.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
]
}
6 changes: 5 additions & 1 deletion presets/quatosc/Cats.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 5.9855294227600098,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":1.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
]
}
6 changes: 5 additions & 1 deletion presets/quatosc/Dancing Waves.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 5.869870662689209,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":1.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
]
}
6 changes: 5 additions & 1 deletion presets/quatosc/Heartbeat.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 0.5012052059173584,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":1.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
]
}
6 changes: 5 additions & 1 deletion presets/quatosc/Planets.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 8.0,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":1.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
]
}
6 changes: 5 additions & 1 deletion presets/quatosc/Spinning Messenger.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 0.0,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":1.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
]
}
6 changes: 5 additions & 1 deletion presets/quatosc/WoggleBass.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 0.0,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":1.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
]
}
6 changes: 5 additions & 1 deletion presets/quatosc/stereobass.vcvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugin": "questionablemodules",
"model": "quatosc",
"version": "2.1.8",
"version": "2.1.14",
"params": [
{
"value": 5.6385593414306641,
Expand Down Expand Up @@ -58,6 +58,10 @@
{
"value":1.0,
"id": 13
},
{
"value": 0.0,
"id": 14
}
]
}
70 changes: 44 additions & 26 deletions src/quatosc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct QuatOSC : QuestionableModule {
Z_POS_I_PARAM,
STEREO,
SPREAD,
DEPHASE,
PARAMS_LEN
};
enum InputId {
Expand Down Expand Up @@ -172,9 +173,10 @@ struct QuatOSC : QuestionableModule {
configParam(Z_POS_I_PARAM, 0.f, 1.f, 1.f, "Z Position Influence");
configSwitch(VOCT1_OCT, -1.f, 8.f, 0.f, "VOct 1 Octave", {"Off", "1", "2", "3", "4", "5", "6", "7", "8"});
configSwitch(VOCT2_OCT, -1.f, 8.f, 6.f, "VOct 2 Octave", {"Off", "1", "2", "3", "4", "5", "6", "7", "8"});
configSwitch(VOCT3_OCT, -1.f, 8.f, 0.f, "VOct 3 Octave", {"Off", "1", "2", "3", "4", "5", "6", "7", "8"});
configSwitch(STEREO, 0.f, 2.f, 0.f, "Stereo", {"Mono", "Full Stereo", "Sides"});
configSwitch(VOCT3_OCT, -1.f, 8.f, -1.f, "VOct 3 Octave", {"Off", "1", "2", "3", "4", "5", "6", "7", "8"});
configSwitch(STEREO, 0.f, 2.f, 1.f, "Stereo", {"Mono", "Full Stereo", "Sides"});
configSwitch(SPREAD, 1.f, 16.f, 1.f, "Spread", {"Off", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"});
configSwitch(DEPHASE, 0.f, 1.f, 0.f, "Dephase Algorithm", {"Old", "New"});
configInput(VOCT, "VOct");
configInput(VOCT2, "VOct 2");
configInput(VOCT3, "VOct 3");
Expand Down Expand Up @@ -226,15 +228,24 @@ struct QuatOSC : QuestionableModule {

inline float calcVOctFreq(int input) {
float voctOffset = quantizedVOCT[input] ? std::round(getValue(input)) : getValue(input);
if (voctOffset < 0.f) return 1.f;
if (voctOffset < 0.f) return params[DEPHASE].getValue() == 0.f ? 1.f : 0.f;
return HALF_SEMITONE * (clockFreq / 2.f) * dsp::approxExp2_taylor5((inputs[input].getVoltage() + voctOffset) + 30.f) / std::pow(2.f, 30.f);
}

inline float processLFO(float &phase, float frequency, float deltaTime, int voct = -1) {
float syncClockOffset = 0.f;

inline float processLFO(float &phase, float frequency, const ProcessArgs& args, int voct = -1) {
float voctFreq = calcVOctFreq(voct);

phase += ((frequency) + (voct != -1 ? voctFreq : 0.f)) * deltaTime;
if (params[DEPHASE].getValue() == 1.f) { // new dephase
double time = ((args.frame/args.sampleRate) - syncClockOffset);
double perfectPhase = (voctFreq * time) + frequency;
perfectPhase -= trunc(perfectPhase);
double phaseErr = perfectPhase - phase;
phase += phaseErr * args.sampleTime * 25;
}

phase += ((frequency) + (voct != -1 ? voctFreq : 0.f)) * args.sampleTime;
phase -= trunc(phase);

return sin(2.f * M_PI * phase);
Expand Down Expand Up @@ -284,19 +295,7 @@ struct QuatOSC : QuestionableModule {
}

void processUndersampled(const ProcessArgs& args) override {

if (oct1Connected != inputs[VOCT].isConnected()) {
oct1Connected = inputs[VOCT].isConnected();
resetPhase(true);
}
if (oct2Connected != inputs[VOCT2].isConnected()) {
oct2Connected = inputs[VOCT2].isConnected();
resetPhase(true);
}
if (oct3Connected != inputs[VOCT3].isConnected()) {
oct3Connected = inputs[VOCT3].isConnected();
resetPhase(true);
}
gmtl::Quatf rotOffset;

// clock stuff from lfo
if (inputs[CLOCK_INPUT].isConnected()) {
Expand All @@ -313,11 +312,19 @@ struct QuatOSC : QuestionableModule {
} else clockFreq = 2.f;

// quat rotation from lfos
gmtl::Quatf rotOffset = gmtl::makePure(gmtl::Vec3f(
getValue(X_FLO_I_PARAM, true) * ((processLFO(lfo1Phase, 0.f, args.sampleTime, VOCT))),
getValue(Y_FLO_I_PARAM, true) * ((processLFO(lfo2Phase, 0.f, args.sampleTime, VOCT2))),
getValue(Z_FLO_I_PARAM, true) * ((processLFO(lfo3Phase, 0.f, args.sampleTime, VOCT3)))
));
if (params[DEPHASE].getValue() == 0.f) {
rotOffset = gmtl::makePure(gmtl::Vec3f(
getValue(X_FLO_I_PARAM, true) * ((processLFO(lfo1Phase, 0, args, VOCT))),
getValue(Y_FLO_I_PARAM, true) * ((processLFO(lfo2Phase, 0, args, VOCT2))),
getValue(Z_FLO_I_PARAM, true) * ((processLFO(lfo3Phase, 0, args, VOCT3)))
));
} else {
rotOffset = gmtl::makePure(gmtl::Vec3f(
getValue(X_FLO_I_PARAM, true) * ((processLFO(lfo1Phase, 0.8364f, args, VOCT))),
getValue(Y_FLO_I_PARAM, true) * ((processLFO(lfo2Phase, 0.435f, args, VOCT2))),
(getValue(VOCT3) < 0) ? 0.95 : getValue(Z_FLO_I_PARAM, true) * ((processLFO(lfo3Phase, 0.3234f, args, VOCT3)))
));
}
gmtl::normalize(rotOffset);

// quat constant rotation addition
Expand All @@ -335,9 +342,11 @@ struct QuatOSC : QuestionableModule {
gmtl::normalize(sphereQuat);

//dephase
lfo1Phase = smoothDephase(0, lfo1Phase, args.sampleTime);
lfo2Phase = smoothDephase(0, lfo2Phase, args.sampleTime);
lfo3Phase = smoothDephase(0, lfo3Phase, args.sampleTime);
if (params[DEPHASE].getValue() == 0.f) { // old style
lfo1Phase = smoothDephase(0, lfo1Phase, args.sampleTime);
lfo2Phase = smoothDephase(0, lfo2Phase, args.sampleTime);
lfo3Phase = smoothDephase(0, lfo3Phase, args.sampleTime);
}

// spread polyphonic logic
int spread = getSpread();
Expand Down Expand Up @@ -376,8 +385,12 @@ struct QuatOSC : QuestionableModule {
outputs[OUT2].setVoltage(outputs[OUT].getVoltage(i), i);
}
}

}

float audioMinima = 0.f;
float audioMaxima = 0.f;

json_t* dataToJson() override {
json_t* nodeJ = QuestionableModule::dataToJson();
json_object_set_new(nodeJ, "projection", json_string(projection.c_str()));
Expand Down Expand Up @@ -768,6 +781,11 @@ struct QuatOSCWidget : QuestionableWidget {
menu->addChild(createMenuItem("Z", mod->projection == "Z" ? "" : "", [=]() { mod->projection = "Z"; }));
}));
menu->addChild(createMenuItem(mod->normalizeSpreadVolume ? "Disable Spread Volume Normalization" : "Enable Spread Volume Normalization", "",[=]() { mod->normalizeSpreadVolume = !mod->normalizeSpreadVolume; }));

menu->addChild(rack::createSubmenuItem("Dephase Algorithm", "", [=](ui::Menu* menu) {
menu->addChild(createMenuItem("Old", mod->params[QuatOSC::DEPHASE].getValue() == 0.f ? "" : "",[=]() { mod->params[QuatOSC::DEPHASE].setValue(0.f); }));
menu->addChild(createMenuItem("New", mod->params[QuatOSC::DEPHASE].getValue() == 1.f ? "" : "", [=]() { mod->params[QuatOSC::DEPHASE].setValue(1.f); }));
}));

QuestionableWidget::appendContextMenu(menu);
}
Expand Down

0 comments on commit 01dab78

Please sign in to comment.