Skip to content

Commit

Permalink
Use GroupState properly. Other notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ywwg committed Jan 5, 2014
1 parent 3d40c46 commit a142872
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 51 deletions.
74 changes: 38 additions & 36 deletions src/effects/native/reverbeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "mathstuff.h"
#include "sampleutil.h"

const unsigned int kOutBufSize = 32;
#define RUN_WG(n, junct_a, junct_b) waveguide_nl_process_lin(group_state.waveguide[n], junct_a - group_state.out[n*2+1], junct_b - group_state.out[n*2], group_state.out+n*2, group_state.out+n*2+1)

// static
QString ReverbEffect::getId() {
Expand All @@ -25,29 +25,29 @@ EffectManifest ReverbEffect::getManifest() {
EffectManifestParameter* time = manifest.addParameter();
time->setId("time");
time->setName(QObject::tr("time"));
time->setDescription("Controls the RT60 time of the reverb. Actually "
"controls the size of the plate. The mapping between "
"plate size and RT60 time is just a heuristic, so "
"it's not very accurate.");
time->setDescription(QObject::tr("Controls the RT60 time of the reverb. "
"Actually controls the size of the plate. The mapping "
"between plate size and RT60 time is just a "
"heuristic, so it's not very accurate."));
time->setControlHint(EffectManifestParameter::CONTROL_KNOB_LINEAR);
time->setValueHint(EffectManifestParameter::VALUE_FLOAT);
time->setSemanticHint(EffectManifestParameter::SEMANTIC_UNKNOWN);
time->setUnitsHint(EffectManifestParameter::UNITS_UNKNOWN);
time->setDefault(0.1);
time->setMinimum(1.0);
time->setMinimum(0.1);
time->setDefault(1.0);
time->setMaximum(8.5);

EffectManifestParameter* damping = manifest.addParameter();
damping->setId("damping");
damping->setName(QObject::tr("damping"));
damping->setDescription("Controls the degree that the surface of the plate "
"is damped.");
damping->setDescription(QObject::tr("Controls the degree that the surface "
"of the plate is damped."));
damping->setControlHint(EffectManifestParameter::CONTROL_KNOB_LINEAR);
damping->setValueHint(EffectManifestParameter::VALUE_FLOAT);
damping->setSemanticHint(EffectManifestParameter::SEMANTIC_UNKNOWN);
damping->setUnitsHint(EffectManifestParameter::UNITS_UNKNOWN);
damping->setDefault(0.5);
damping->setMinimum(0.0);
damping->setDefault(0.5);
damping->setMaximum(1.0);

return manifest;
Expand All @@ -57,32 +57,30 @@ ReverbEffect::ReverbEffect(EngineEffect* pEffect,
const EffectManifest& manifest)
: m_pTimeParameter(pEffect->getParameterById("time")),
m_pDampingParameter(pEffect->getParameterById("damping")) {

m_pWaveguide = (waveguide_nl**)malloc(8 * sizeof(waveguide_nl *));
m_pWaveguide[0] = waveguide_nl_new(2389, LP_INNER, 0.04f, 0.0f);
m_pWaveguide[1] = waveguide_nl_new(4742, LP_INNER, 0.17f, 0.0f);
m_pWaveguide[2] = waveguide_nl_new(4623, LP_INNER, 0.52f, 0.0f);
m_pWaveguide[3] = waveguide_nl_new(2142, LP_INNER, 0.48f, 0.0f);
m_pWaveguide[4] = waveguide_nl_new(5597, LP_OUTER, 0.32f, 0.0f);
m_pWaveguide[5] = waveguide_nl_new(3692, LP_OUTER, 0.89f, 0.0f);
m_pWaveguide[6] = waveguide_nl_new(5611, LP_OUTER, 0.28f, 0.0f);
m_pWaveguide[7] = waveguide_nl_new(3703, LP_OUTER, 0.29f, 0.0f);

m_pOut = SampleUtil::alloc(kOutBufSize);
}

ReverbEffect::~ReverbEffect() {
for (int i = 0; i < 8; i++) {
waveguide_nl_reset(m_pWaveguide[i]);
for (QMap<QString, GroupState*>::iterator it = m_groupState.begin();
it != m_groupState.end();) {
for (int i = 0; i < 8; i++) {
waveguide_nl_reset((*it)->waveguide[i]);
}
SampleUtil::free((*it)->out);
delete it.value();
it = m_groupState.erase(it);
}
SampleUtil::free(m_pOut);
qDebug() << debugString() << "destroyed";
}

void ReverbEffect::process(const QString& group,
const CSAMPLE* pInput, CSAMPLE* pOutput,
const unsigned int numSamples) {
GroupState& group_state = m_groupState[group];
GroupState* pGroupState = m_groupState.value(group, NULL);
if (pGroupState == NULL) {
pGroupState = new GroupState();
m_groupState[group] = pGroupState;
}
GroupState& group_state = *pGroupState;

CSAMPLE time = m_pTimeParameter ?
m_pTimeParameter->value().toDouble() : 1.0f;
Expand All @@ -96,28 +94,32 @@ void ReverbEffect::process(const QString& group,
const float lpscale = 1.0f - damping * 0.93;

for (pos=0; pos<8; pos++) {
waveguide_nl_set_delay(m_pWaveguide[pos],
m_pWaveguide[pos]->size * scale);
waveguide_nl_set_delay(group_state.waveguide[pos],
group_state.waveguide[pos]->size * scale);
}
for (pos=0; pos<4; pos++) {
waveguide_nl_set_fc(m_pWaveguide[pos], LP_INNER * lpscale);
waveguide_nl_set_fc(group_state.waveguide[pos], LP_INNER * lpscale);
}
for (; pos<8; pos++) {
waveguide_nl_set_fc(m_pWaveguide[pos], LP_OUTER * lpscale);
waveguide_nl_set_fc(group_state.waveguide[pos], LP_OUTER * lpscale);
}

for (pos = 0; pos < numSamples - 1; pos+=2) {
const float alpha =
(m_pOut[0] + m_pOut[2] + m_pOut[4] + m_pOut[6]) * 0.5f
+ pInput[pos];
(group_state.out[0] + group_state.out[2] +
group_state.out[4] + group_state.out[6]) * 0.5f + pInput[pos];
const float beta =
(m_pOut[1] + m_pOut[9] + m_pOut[14]) * 0.666666666f;
(group_state.out[1] + group_state.out[9] + group_state.out[14])
* 0.666666666f;
const float gamma =
(m_pOut[3] + m_pOut[8] + m_pOut[11]) * 0.666666666f;
(group_state.out[3] + group_state.out[8] + group_state.out[11])
* 0.666666666f;
const float delta =
(m_pOut[5] + m_pOut[10] + m_pOut[13]) * 0.666666666f;
(group_state.out[5] + group_state.out[10] + group_state.out[13])
* 0.666666666f;
const float epsilon =
(m_pOut[7] + m_pOut[12] + m_pOut[15]) * 0.666666666f;
(group_state.out[7] + group_state.out[12] + group_state.out[15])
* 0.666666666f;

RUN_WG(0, beta, alpha);
RUN_WG(1, gamma, alpha);
Expand Down
34 changes: 19 additions & 15 deletions src/effects/native/reverbeffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
#include "effects/native/waveguide_nl.h"
#include "sampleutil.h"

class ReverbEffect : public EffectProcessor {
private:
#define LP_INNER 0.96f
#define LP_OUTER 0.983f
#define RUN_WG(n, junct_a, junct_b) waveguide_nl_process_lin(m_pWaveguide[n], junct_a - m_pOut[n*2+1], junct_b - m_pOut[n*2], m_pOut+n*2, m_pOut+n*2+1)
#define LP_INNER 0.96f
#define LP_OUTER 0.983f
const unsigned int kOutBufSize = 32;

class ReverbEffect : public EffectProcessor {
public:
ReverbEffect(EngineEffect* pEffect, const EffectManifest& manifest);
virtual ~ReverbEffect();
Expand All @@ -39,20 +38,25 @@ class ReverbEffect : public EffectProcessor {

EngineEffectParameter* m_pTimeParameter;
EngineEffectParameter* m_pDampingParameter;
waveguide_nl** m_pWaveguide;
CSAMPLE* m_pOut;

struct GroupState {
GroupState()
: delayPos(0),
time(0) {
SampleUtil::applyGain(delayBuffer, 0, MAX_BUFFER_LEN);
GroupState() {
waveguide = (waveguide_nl**)malloc(8 * sizeof(waveguide_nl *));
waveguide[0] = waveguide_nl_new(2389, LP_INNER, 0.04f, 0.0f);
waveguide[1] = waveguide_nl_new(4742, LP_INNER, 0.17f, 0.0f);
waveguide[2] = waveguide_nl_new(4623, LP_INNER, 0.52f, 0.0f);
waveguide[3] = waveguide_nl_new(2142, LP_INNER, 0.48f, 0.0f);
waveguide[4] = waveguide_nl_new(5597, LP_OUTER, 0.32f, 0.0f);
waveguide[5] = waveguide_nl_new(3692, LP_OUTER, 0.89f, 0.0f);
waveguide[6] = waveguide_nl_new(5611, LP_OUTER, 0.28f, 0.0f);
waveguide[7] = waveguide_nl_new(3703, LP_OUTER, 0.29f, 0.0f);

out = SampleUtil::alloc(kOutBufSize);
}
CSAMPLE delayBuffer[MAX_BUFFER_LEN];
unsigned int delayPos;
unsigned int time;
waveguide_nl** waveguide;
CSAMPLE* out;
};
QMap<QString, GroupState> m_groupState;
QMap<QString, GroupState*> m_groupState;

DISALLOW_COPY_AND_ASSIGN(ReverbEffect);
};
Expand Down

0 comments on commit a142872

Please sign in to comment.