Skip to content

Commit

Permalink
avoid temporary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
gisogrimm committed Nov 19, 2023
1 parent 23428d9 commit 4f7df27
Showing 1 changed file with 18 additions and 33 deletions.
51 changes: 18 additions & 33 deletions plugins/src/receivermod_simplefdn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,43 +71,24 @@ class foa_sample_t : public TASCAR::posf_t {
};
};

inline foa_sample_t operator*(foa_sample_t self, float d)
{
self *= d;
return self;
};

inline foa_sample_t operator*(float d, foa_sample_t self)
{
self *= d;
return self;
};

inline foa_sample_t operator-(foa_sample_t a, const foa_sample_t& b)
{
a -= b;
return a;
}

inline foa_sample_t operator+(foa_sample_t a, const foa_sample_t& b)
{
a += b;
return a;
}

// y[n] = -g x[n] + x[n-1] + g y[n-1]
class reflectionfilter_t {
public:
reflectionfilter_t();
inline void filter(foa_sample_t& x)
{
x *= B1;
x -= A2 * sy;
sy *= A2;
x -= sy;
sy = x;
// all pass section:
foa_sample_t tmp(eta * x + sapx);
tmpx = x;
tmpx *= eta;
tmpx += sapx;
sapx = x;
x = tmp - eta * sapy;
sapy *= eta;
x = tmpx;
x -= sapy;
sapy = x;
};
void set_lp(float g, float c);
Expand All @@ -120,6 +101,7 @@ class reflectionfilter_t {
foa_sample_t sy; ///< output state buffer
foa_sample_t sapx; ///< input state variable of allpass filter
foa_sample_t sapy; ///< output state variable of allpass filter
foa_sample_t tmpx;
};

reflectionfilter_t::reflectionfilter_t()
Expand Down Expand Up @@ -209,7 +191,6 @@ class fdn_t {
gainmethod_t gainmethod = original;
// use feedback matrix:
bool feedback = true;
//

public:
// output FOA sample:
Expand All @@ -229,7 +210,6 @@ fdn_t::fdn_t(uint32_t fdnorder, uint32_t maxdelay, bool logdelays,
for(size_t k = 0; k < fdnpath.size(); ++k) {
fdnpath[k].init(maxdelay);
}
// inval.set_zero();
outval.set_zero();
}

Expand All @@ -247,15 +227,17 @@ void fdn_t::process(const std::vector<fdnpath_t>& src)
}
// put rotated+attenuated value to delayline, add input:
uint32_t tap = 0;
foa_sample_t tmpo;
for(auto& path : fdnpath) {
// first put input into delayline:
path.delayline[path.pos].set_zero();
// now add feedback signal:
uint32_t otap = 0;
for(auto& opath : fdnpath) {
foa_sample_t tmp = opath.dlout;
tmp += src[otap].dlout;
path.delayline[path.pos] += tmp * feedbackmat[fdnorder_ * tap + otap];
tmpo = opath.dlout;
tmpo += src[otap].dlout;
tmpo *= feedbackmat[fdnorder_ * tap + otap];
path.delayline[path.pos] += tmpo;
++otap;
}
// iterate delayline:
Expand All @@ -269,11 +251,14 @@ void fdn_t::process(const std::vector<fdnpath_t>& src)
// put rotated+attenuated value to delayline, add input:
{
uint32_t tap = 0;
foa_sample_t tmpo;
for(auto& path : fdnpath) {
foa_sample_t tmp;
uint32_t otap = 0;
for(auto& opath : src) {
tmp += opath.dlout * feedbackmat[fdnorder_ * tap + otap];
tmpo = opath.dlout;
tmpo *= feedbackmat[fdnorder_ * tap + otap];
tmp += tmpo;
++otap;
}
// first put input into delayline:
Expand Down

0 comments on commit 4f7df27

Please sign in to comment.