Skip to content

Commit

Permalink
- made dynamics.envelope_follower support polyphony
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Hart committed Sep 15, 2024
1 parent f17ab75 commit 37a13ea
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 40 deletions.
2 changes: 1 addition & 1 deletion hi_backend/backend/BackendVisualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ void MainTopBar::ClickablePeakMeter::PopupComponent::EnvInfo::calculate(const Au

span<float, 2> frame;

dynamics::envelope_follower follower[2];
dynamics::envelope_follower<1> follower[2];

follower[0].setAttack(0.0);
follower[0].setRelease(12.0);
Expand Down
4 changes: 2 additions & 2 deletions hi_dsp_library/dsp_basics/AllpassDelay.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EnvelopeFollower
*
* You have to call setSampleRate before you can use it.
*/
AttackRelease(float attackTime, float releaseTime);;
AttackRelease(float attackTime=20.0, float releaseTime=50.0);;

/** Returns the envelope value. */
float calculateValue(float input);;
Expand Down Expand Up @@ -240,4 +240,4 @@ template <int NumChannels> struct InterpolatingDelay
hmath Math;
};

}
}
28 changes: 2 additions & 26 deletions hi_dsp_library/dsp_nodes/DynamicsNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,7 @@ namespace dynamics {
using namespace hise;
using namespace juce;

void envelope_follower::createParameters(ParameterDataList& data)
{
{
DEFINE_PARAMETERDATA(envelope_follower, Attack);
p.setRange({ 0.0, 1000.0, 0.1 });
p.setSkewForCentre(50.0);
p.setDefaultValue(20.0);

data.add(std::move(p));
}

{
DEFINE_PARAMETERDATA(envelope_follower, Release);
p.setRange({ 0.0, 1000.0, 0.1 });
p.setSkewForCentre(50.0);
p.setDefaultValue(20.0);

data.add(std::move(p));
}

{
DEFINE_PARAMETERDATA(envelope_follower, ProcessSignal);
data.add(std::move(p));
}
}


void updown_comp::RMSDetector::prepare(PrepareSpecs ps)
{
Expand Down Expand Up @@ -302,4 +278,4 @@ void updown_comp::calculateGraph(block values)
}
}
} // dynamics
} // scriptnode
} // scriptnode
49 changes: 39 additions & 10 deletions hi_dsp_library/dsp_nodes/DynamicsNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ using comp = dynamics_wrapper<chunkware_simple::SimpleComp>;
using limiter = dynamics_wrapper<chunkware_simple::SimpleLimit>;


class envelope_follower: public data::display_buffer_base<true>
template <int NV> class envelope_follower: public data::display_buffer_base<true>,
public polyphonic_base
{
public:

Expand All @@ -316,8 +317,8 @@ class envelope_follower: public data::display_buffer_base<true>
SN_NODE_ID("envelope_follower");
SN_GET_SELF_AS_OBJECT(envelope_follower);

envelope_follower() :
envelope(20.0, 50.0)
envelope_follower():
polyphonic_base(getStaticId(), false)
{

}
Expand All @@ -337,12 +338,14 @@ class envelope_follower: public data::display_buffer_base<true>
{
display_buffer_base<true>::prepare(ps);

envelope.setSampleRate(ps.sampleRate);
for(auto& envelope: envelopes)
envelope.setSampleRate(ps.sampleRate);
}

void reset() noexcept
{
envelope.reset();
for(auto& envelope: envelopes)
envelope.reset();
}

template <typename ProcessDataType> void process(ProcessDataType& data)
Expand All @@ -362,7 +365,7 @@ class envelope_follower: public data::display_buffer_base<true>
for (auto& s: data)
input = Math.max(Math.abs(s), input);

auto output = envelope.calculateValue(input);
auto output = envelopes.get().calculateValue(input);

if (processSignal)
{
Expand All @@ -376,22 +379,48 @@ class envelope_follower: public data::display_buffer_base<true>

void setAttack(double v)
{
envelope.setAttackDouble(v);
for(auto& envelope: envelopes)
envelope.setAttackDouble(v);
}

void setRelease(double v)
{
envelope.setReleaseDouble(v);
for(auto& envelope: envelopes)
envelope.setReleaseDouble(v);
}

void setProcessSignal(double v)
{
processSignal = v > 0.5;
}

void createParameters(ParameterDataList& data);
void createParameters(ParameterDataList& data)
{
{
DEFINE_PARAMETERDATA(envelope_follower, Attack);
p.setRange({ 0.0, 1000.0, 0.1 });
p.setSkewForCentre(50.0);
p.setDefaultValue(20.0);

data.add(std::move(p));
}

{
DEFINE_PARAMETERDATA(envelope_follower, Release);
p.setRange({ 0.0, 1000.0, 0.1 });
p.setSkewForCentre(50.0);
p.setDefaultValue(20.0);

data.add(std::move(p));
}

{
DEFINE_PARAMETERDATA(envelope_follower, ProcessSignal);
data.add(std::move(p));
}
}

EnvelopeFollower::AttackRelease envelope;
PolyData<EnvelopeFollower::AttackRelease, NV> envelopes;

ModValue modValue;
int lastNumSamples = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ Factory::Factory(DspNetwork* network) :
registerPolyModNode<dp<comp>, dp<wrap::illegal_poly<comp>>, data::ui::displaybuffer_editor>();
registerPolyModNode<dp<limiter>, dp<wrap::illegal_poly<limiter>>, data::ui::displaybuffer_editor>();
registerPolyModNode<dp<updown_comp>, dp<wrap::illegal_poly<updown_comp>>, updown_editor>();
registerModNode<dp<envelope_follower>, data::ui::displaybuffer_editor >();
registerPolyModNode<dp<envelope_follower<1>>, dp<envelope_follower<NUM_POLYPHONIC_VOICES>>, data::ui::displaybuffer_editor >();
}

}
Expand Down

0 comments on commit 37a13ea

Please sign in to comment.