bundle depth sliders into the envelopes

This commit is contained in:
2025-12-28 17:59:37 -06:00
parent 7284cfc1ab
commit c045337fba
8 changed files with 126 additions and 201 deletions

View File

@@ -9,9 +9,10 @@ void ParameterStore::set(ParamId id, float value) {
values_[static_cast<size_t>(id)].store(value, std::memory_order_relaxed);
}
void ParameterStore::set(EnvelopeId id, float a, float d, float s, float r) {
void ParameterStore::set(EnvelopeId id, float depth, float a, float d, float s, float r) {
EnvelopeParam params = ENV_PARAMS[static_cast<size_t>(id)];
set(params.depth, depth);
set(params.a, a);
set(params.d, d);
set(params.s, s);

View File

@@ -9,17 +9,17 @@ enum class ParamId : uint16_t {
Osc1Frequency,
Osc1WaveSelector1,
Osc1WaveSelector2,
Osc1Volume,
Osc1VolumeDepth,
Osc1VolumeEnvA,
Osc1VolumeEnvD,
Osc1VolumeEnvS,
Osc1VolumeEnvR,
FilterCutoff,
FilterCutoffDepth,
FilterCutoffEnvA,
FilterCutoffEnvD,
FilterCutoffEnvS,
FilterCutoffEnvR,
FilterResonance,
FilterResonanceDepth,
FilterResonanceEnvA,
FilterResonanceEnvD,
FilterResonanceEnvS,
@@ -39,6 +39,7 @@ enum class EnvelopeId : uint16_t {
};
struct EnvelopeParam {
ParamId depth;
ParamId a;
ParamId d;
ParamId s;
@@ -46,11 +47,11 @@ struct EnvelopeParam {
};
constexpr std::array<EnvelopeParam, static_cast<size_t>(EnvelopeId::Count)> ENV_PARAMS {{
{ ParamId::Osc1VolumeEnvA, ParamId::Osc1VolumeEnvD, ParamId::Osc1VolumeEnvS, ParamId::Osc1VolumeEnvR }, // Osc1Volume
{ ParamId::Osc1VolumeEnvA, ParamId::Osc1VolumeEnvD, ParamId::Osc1VolumeEnvS, ParamId::Osc1VolumeEnvR }, // Osc2Volume (not implemented)
{ ParamId::Osc1VolumeEnvA, ParamId::Osc1VolumeEnvD, ParamId::Osc1VolumeEnvS, ParamId::Osc1VolumeEnvR }, // Osc3Volume (not implemented)
{ ParamId::FilterCutoffEnvA, ParamId::FilterCutoffEnvD, ParamId::FilterCutoffEnvS, ParamId::FilterCutoffEnvR }, // FilterCutoff
{ ParamId::FilterResonanceEnvA, ParamId::FilterResonanceEnvD, ParamId::FilterResonanceEnvS, ParamId::FilterResonanceEnvR }, // FilterResonance
{ ParamId::Osc1VolumeDepth, ParamId::Osc1VolumeEnvA, ParamId::Osc1VolumeEnvD, ParamId::Osc1VolumeEnvS, ParamId::Osc1VolumeEnvR }, // Osc1Volume
{ ParamId::Osc1VolumeDepth, ParamId::Osc1VolumeEnvA, ParamId::Osc1VolumeEnvD, ParamId::Osc1VolumeEnvS, ParamId::Osc1VolumeEnvR }, // Osc2Volume (not implemented)
{ ParamId::Osc1VolumeDepth, ParamId::Osc1VolumeEnvA, ParamId::Osc1VolumeEnvD, ParamId::Osc1VolumeEnvS, ParamId::Osc1VolumeEnvR }, // Osc3Volume (not implemented)
{ ParamId::FilterCutoffDepth, ParamId::FilterCutoffEnvA, ParamId::FilterCutoffEnvD, ParamId::FilterCutoffEnvS, ParamId::FilterCutoffEnvR }, // FilterCutoff
{ ParamId::FilterResonanceDepth, ParamId::FilterResonanceEnvA, ParamId::FilterResonanceEnvD, ParamId::FilterResonanceEnvS, ParamId::FilterResonanceEnvR }, // FilterResonance
}};
struct ParamDefault {
@@ -65,17 +66,17 @@ constexpr std::array<ParamDefault, static_cast<size_t>(ParamId::Count)> PARAM_DE
{ 100.0f, 20.0f, 600.0f}, // Osc1Freq
{ 0.0f, 0.0f, 0.0f}, // Osc1WaveSelector1
{ 1.0f, 0.0f, 0.0f}, // Osc1WaveSelector2
{ 1.0f, 0.0f, 2.0f}, // Osc1Volume
{ 1.0f, 0.0f, 2.0f}, // Osc1VolumeDepth
{ 0.05f, 0.0f, 2.0f}, // Osc1VolumeEnvA
{ 0.2f, 0.0f, 2.0f}, // Osc1VolumeEnvD
{ 0.7f, 0.0f, 1.0f}, // Osc1VolumeEnvS
{ 0.2f, 0.0f, 2.0f}, // Osc1VolumeEnvR
{ 1.0f, 0.0f, 8.0f}, // FilterCutoff
{ 1.0f, 0.0f, 8.0f}, // FilterCutoffDepth
{ 0.05f, 0.0f, 2.0f}, // FilterCutoffEnvA
{ 0.05f, 0.0f, 2.0f}, // FilterCutoffEnvD
{ 2.0f, 0.0f, 1.0f}, // FilterCutoffEnvS
{ 0.05f, 0.0f, 2.0f}, // FilterCutoffEnvR
{ 1.414f, 0.0f, 8.0f}, // FilterResonance
{ 1.414f, 0.0f, 8.0f}, // FilterResonanceDepth
{ 0.05f, 0.0f, 2.0f}, // FilterResonanceEnvA
{ 0.05f, 0.0f, 2.0f}, // FilterResonanceEnvD
{ 0.5f, 0.0f, 1.0f}, // FilterResonanceEnvS
@@ -93,7 +94,7 @@ public:
void set(ParamId id, float value);
void set(ParamId id, int32_t value) { set(id, static_cast<float>(value)); }
void set(EnvelopeId, float a, float d, float s, float r);
void set(EnvelopeId id, float depth, float a, float d, float s, float r);
float get(ParamId id) const;
int32_t getInt(ParamId id) const { return static_cast<int32_t>(get(id)); }
void resetToDefaults();

View File

@@ -107,7 +107,7 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) {
float pitchOffset = 0.5f;
float phaseInc = pitchOffset * 2.0f * M_PI * frequency_ / static_cast<float>(sampleRate);
float gain = gainEnv * getParam(ParamId::Osc1Volume);
float gain = gainEnv * getParam(ParamId::Osc1VolumeDepth);
// sample generation
// TODO: wavetables
@@ -135,8 +135,8 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) {
}
// filter sample
float cutoffFreq = cutoffEnv * pow(2.0f, getParam(ParamId::FilterCutoff)) * frequency_;
filter_.setParams(Filter::Type::BiquadLowpass, cutoffFreq, resonanceEnv * getParam(ParamId::FilterResonance));
float cutoffFreq = cutoffEnv * pow(2.0f, getParam(ParamId::FilterCutoffDepth)) * frequency_;
filter_.setParams(Filter::Type::BiquadLowpass, cutoffFreq, resonanceEnv * getParam(ParamId::FilterResonanceDepth));
sampleOut = filter_.biquadProcess(sampleOut);
// write to buffer

View File

@@ -24,16 +24,16 @@ MainWindow::MainWindow(QWidget *parent) :
// connect envelopeGenerators
connect(ui_->envelopeOsc1Volume, &EnvelopeGenerator::envelopeChanged,
this, [this](float a, float d, float s, float r) {
audio_->parameters()->set(EnvelopeId::Osc1Volume, a, d, s, r);
this, [this](float depth, float a, float d, float s, float r) {
audio_->parameters()->set(EnvelopeId::Osc1Volume, depth, a, d, s, r);
});
connect(ui_->envelopeFilterCutoff, &EnvelopeGenerator::envelopeChanged,
this, [this](float a, float d, float s, float r) {
audio_->parameters()->set(EnvelopeId::FilterCutoff, a, d, s, r);
this, [this](float depth, float a, float d, float s, float r) {
audio_->parameters()->set(EnvelopeId::FilterCutoff, depth, a, d, s, r);
});
connect(ui_->envelopeFilterResonance, &EnvelopeGenerator::envelopeChanged,
this, [this](float a, float d, float s, float r) {
audio_->parameters()->set(EnvelopeId::FilterResonance, a, d, s, r);
this, [this](float depth, float a, float d, float s, float r) {
audio_->parameters()->set(EnvelopeId::FilterResonance, depth, a, d, s, r);
});
// this should be easy enough to put into a for each envelopeGenerator loop, each ui element just needs an EnvelopeId specifiers
@@ -47,16 +47,6 @@ MainWindow::MainWindow(QWidget *parent) :
audio_->parameters()->set(ParamId::Osc1WaveSelector2, index);
});
connect(ui_->sliderOsc1Volume, &SmartSlider::valueChanged, this, [this](float v) {
audio_->parameters()->set(ParamId::Osc1Volume, v);
});
connect(ui_->sliderFilterCutoff, &SmartSlider::valueChanged, this, [this](float v) {
audio_->parameters()->set(ParamId::FilterCutoff, v);
});
connect(ui_->sliderFilterResonance, &SmartSlider::valueChanged, this, [this](float v) {
audio_->parameters()->set(ParamId::FilterResonance, v);
});
// synth business
audio_->start();
@@ -87,11 +77,4 @@ void MainWindow::onResetClicked() {
ui_->comboOsc1WaveSelector1->setCurrentIndex(static_cast<int>(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1WaveSelector1)].def));
ui_->comboOsc1WaveSelector2->setCurrentIndex(static_cast<int>(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1WaveSelector2)].def));
// misc sliders
ui_->sliderOsc1Volume->setRange(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Volume)].min, PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Volume)].max);
ui_->sliderFilterCutoff->setRange(PARAM_DEFS[static_cast<size_t>(ParamId::FilterCutoff)].min, PARAM_DEFS[static_cast<size_t>(ParamId::FilterCutoff)].max);
ui_->sliderFilterResonance->setRange(PARAM_DEFS[static_cast<size_t>(ParamId::FilterResonance)].min, PARAM_DEFS[static_cast<size_t>(ParamId::FilterResonance)].max);
ui_->sliderOsc1Volume->setValue(PARAM_DEFS[static_cast<size_t>(ParamId::Osc1Volume)].def);
ui_->sliderFilterCutoff->setValue(PARAM_DEFS[static_cast<size_t>(ParamId::FilterCutoff)].def);
ui_->sliderFilterResonance->setValue(PARAM_DEFS[static_cast<size_t>(ParamId::FilterResonance)].def);
}

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>940</width>
<height>658</height>
<width>1102</width>
<height>564</height>
</rect>
</property>
<property name="windowTitle">
@@ -39,8 +39,8 @@
<property name="geometry">
<rect>
<x>20</x>
<y>360</y>
<width>300</width>
<y>260</y>
<width>350</width>
<height>300</height>
</rect>
</property>
@@ -54,7 +54,7 @@
<widget class="Scope" name="scope" native="true">
<property name="geometry">
<rect>
<x>270</x>
<x>360</x>
<y>20</y>
<width>400</width>
<height>200</height>
@@ -67,9 +67,9 @@
<widget class="EnvelopeGenerator" name="envelopeFilterCutoff" native="true">
<property name="geometry">
<rect>
<x>320</x>
<y>360</y>
<width>300</width>
<x>380</x>
<y>260</y>
<width>350</width>
<height>300</height>
</rect>
</property>
@@ -83,9 +83,9 @@
<widget class="EnvelopeGenerator" name="envelopeFilterResonance" native="true">
<property name="geometry">
<rect>
<x>620</x>
<y>360</y>
<width>300</width>
<x>740</x>
<y>260</y>
<width>350</width>
<height>300</height>
</rect>
</property>
@@ -99,8 +99,8 @@
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>110</x>
<y>330</y>
<x>140</x>
<y>230</y>
<width>101</width>
<height>16</height>
</rect>
@@ -120,8 +120,8 @@
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>420</x>
<y>330</y>
<x>500</x>
<y>230</y>
<width>101</width>
<height>16</height>
</rect>
@@ -141,8 +141,8 @@
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>710</x>
<y>330</y>
<x>860</x>
<y>230</y>
<width>121</width>
<height>16</height>
</rect>
@@ -261,108 +261,6 @@
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
<widget class="SmartSlider" name="sliderFilterCutoff" native="true">
<property name="geometry">
<rect>
<x>770</x>
<y>30</y>
<width>65</width>
<height>280</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
</widget>
<widget class="SmartSlider" name="sliderOsc1Volume" native="true">
<property name="geometry">
<rect>
<x>700</x>
<y>30</y>
<width>65</width>
<height>280</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
</widget>
<widget class="SmartSlider" name="sliderFilterResonance" native="true">
<property name="geometry">
<rect>
<x>840</x>
<y>30</y>
<width>65</width>
<height>280</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>690</x>
<y>10</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>Volume</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>760</x>
<y>10</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>Cutoff</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>830</x>
<y>10</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>Resonance</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
</widget>
</widget>
<customwidgets>
@@ -372,12 +270,6 @@
<header>EnvelopeGenerator/EnvelopeGenerator.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>SmartSlider</class>
<extends>QWidget</extends>
<header>SmartSlider/SmartSlider.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>Scope</class>
<extends>QWidget</extends>

View File

@@ -15,6 +15,7 @@ EnvelopeGenerator::EnvelopeGenerator(QWidget* parent) : QWidget(parent), ui_(new
this, &EnvelopeGenerator::emitEnvelope);
};
connectSlider(ui_->sliderDepth);
connectSlider(ui_->sliderAttack);
connectSlider(ui_->sliderDecay);
connectSlider(ui_->sliderSustain);
@@ -26,6 +27,10 @@ EnvelopeGenerator::~EnvelopeGenerator() {
}
// getters are here to separate ui from header
float EnvelopeGenerator::depth() const {
return ui_->sliderDepth->value();
}
float EnvelopeGenerator::attack() const {
return ui_->sliderAttack->value();
}
@@ -42,6 +47,10 @@ float EnvelopeGenerator::release() const {
return ui_->sliderRelease->value();
}
void EnvelopeGenerator::setDepth(float v) {
ui_->sliderDepth->setValue(v);
}
void EnvelopeGenerator::setAttack(float v) {
ui_->sliderAttack->setValue(v);
}
@@ -60,6 +69,7 @@ void EnvelopeGenerator::setRelease(float v) {
void EnvelopeGenerator::emitEnvelope() {
emit envelopeChanged(
depth(),
attack(),
decay(),
sustain(),
@@ -71,11 +81,13 @@ void EnvelopeGenerator::init(EnvelopeId id) {
EnvelopeParam params = ENV_PARAMS[static_cast<size_t>(id)];
ui_->sliderDepth->setRange(PARAM_DEFS[static_cast<size_t>(params.depth)].min, PARAM_DEFS[static_cast<size_t>(params.depth)].max);
ui_->sliderAttack->setRange(PARAM_DEFS[static_cast<size_t>(params.a)].min, PARAM_DEFS[static_cast<size_t>(params.a)].max);
ui_->sliderDecay->setRange(PARAM_DEFS[static_cast<size_t>(params.d)].min, PARAM_DEFS[static_cast<size_t>(params.d)].max);
ui_->sliderSustain->setRange(PARAM_DEFS[static_cast<size_t>(params.s)].min, PARAM_DEFS[static_cast<size_t>(params.s)].max);
ui_->sliderRelease->setRange(PARAM_DEFS[static_cast<size_t>(params.r)].min, PARAM_DEFS[static_cast<size_t>(params.r)].max);
setDepth(PARAM_DEFS[static_cast<size_t>(params.depth)].def);
setAttack(PARAM_DEFS[static_cast<size_t>(params.a)].def);
setDecay(PARAM_DEFS[static_cast<size_t>(params.d)].def);
setSustain(PARAM_DEFS[static_cast<size_t>(params.s)].def);

View File

@@ -20,19 +20,21 @@ public:
void init(EnvelopeId id);
// setters
void setDepth(float v);
void setAttack(float v);
void setDecay(float v);
void setSustain(float v);
void setRelease(float v);
// getters
float depth() const;
float attack() const;
float decay() const;
float sustain() const;
float release() const;
signals:
void envelopeChanged(double a, double d, double s, double r);
void envelopeChanged(double depth, double a, double d, double s, double r);
private:

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>300</height>
<width>347</width>
<height>302</height>
</rect>
</property>
<property name="sizePolicy">
@@ -22,7 +22,7 @@
<widget class="SmartSlider" name="sliderDecay" native="true">
<property name="geometry">
<rect>
<x>80</x>
<x>140</x>
<y>20</y>
<width>65</width>
<height>280</height>
@@ -35,7 +35,7 @@
<widget class="SmartSlider" name="sliderRelease" native="true">
<property name="geometry">
<rect>
<x>220</x>
<x>280</x>
<y>20</y>
<width>65</width>
<height>280</height>
@@ -48,7 +48,7 @@
<widget class="SmartSlider" name="sliderSustain" native="true">
<property name="geometry">
<rect>
<x>150</x>
<x>210</x>
<y>20</y>
<width>65</width>
<height>280</height>
@@ -61,7 +61,7 @@
<widget class="SmartSlider" name="sliderAttack" native="true">
<property name="geometry">
<rect>
<x>10</x>
<x>70</x>
<y>20</y>
<width>65</width>
<height>280</height>
@@ -71,36 +71,10 @@
<bool>true</bool>
</property>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>0</x>
<y>290</y>
<width>291</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
<widget class="Line" name="line_2">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>291</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>30</x>
<x>90</x>
<y>-10</y>
<width>21</width>
<height>31</height>
@@ -121,7 +95,7 @@
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>100</x>
<x>160</x>
<y>-10</y>
<width>21</width>
<height>31</height>
@@ -142,7 +116,7 @@
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>170</x>
<x>230</x>
<y>-10</y>
<width>20</width>
<height>31</height>
@@ -163,7 +137,7 @@
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>240</x>
<x>300</x>
<y>-10</y>
<width>20</width>
<height>31</height>
@@ -181,6 +155,66 @@
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
<widget class="SmartSlider" name="sliderDepth" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>65</width>
<height>280</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
</widget>
<widget class="Line" name="line_2">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>346</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>0</x>
<y>290</y>
<width>346</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>0</x>
<y>-10</y>
<width>71</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Depth</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>