aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/filters
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-03-10 10:30:33 -0700
committerChris Robinson <[email protected]>2019-03-10 10:30:33 -0700
commit12721f94a72b94c9eab0fc861ad021d915fc0228 (patch)
tree971778d9143ba4233cc5654e834c0bb3f4ebf3e1 /Alc/filters
parent6a95189ef66bee5dc600f33c5518a60de042a225 (diff)
Add a method to apply an HF scale without band-splitting
Diffstat (limited to 'Alc/filters')
-rw-r--r--Alc/filters/splitter.cpp36
-rw-r--r--Alc/filters/splitter.h3
2 files changed, 37 insertions, 2 deletions
diff --git a/Alc/filters/splitter.cpp b/Alc/filters/splitter.cpp
index 004f8215..58a5029b 100644
--- a/Alc/filters/splitter.cpp
+++ b/Alc/filters/splitter.cpp
@@ -25,7 +25,7 @@ void BandSplitterR<Real>::init(Real f0norm)
}
template<typename Real>
-void BandSplitterR<Real>::process(Real *hpout, Real *lpout, const Real *input, int count)
+void BandSplitterR<Real>::process(Real *hpout, Real *lpout, const Real *input, const int count)
{
ASSUME(count > 0);
@@ -60,6 +60,40 @@ void BandSplitterR<Real>::process(Real *hpout, Real *lpout, const Real *input, i
this->ap_z1 = ap_z1;
}
+template<typename Real>
+void BandSplitterR<Real>::applyHfScale(Real *RESTRICT samples, const Real hfscale, const int count)
+{
+ ASSUME(count > 0);
+
+ const Real ap_coeff{this->coeff};
+ const Real lp_coeff{this->coeff*0.5f + 0.5f};
+ Real lp_z1{this->lp_z1};
+ Real lp_z2{this->lp_z2};
+ Real ap_z1{this->ap_z1};
+ auto proc_sample = [hfscale,ap_coeff,lp_coeff,&lp_z1,&lp_z2,&ap_z1](const Real in) noexcept -> Real
+ {
+ /* Low-pass sample processing. */
+ Real d{(in - lp_z1) * lp_coeff};
+ Real lp_y{lp_z1 + d};
+ lp_z1 = lp_y + d;
+
+ d = (lp_y - lp_z2) * lp_coeff;
+ lp_y = lp_z2 + d;
+ lp_z2 = lp_y + d;
+
+ /* All-pass sample processing. */
+ Real ap_y{in*ap_coeff + ap_z1};
+ ap_z1 = in - ap_y*ap_coeff;
+
+ /* High-pass generated from removing low-passed output. */
+ return (ap_y-lp_y)*hfscale + lp_y;
+ };
+ std::transform(samples, samples+count, samples, proc_sample);
+ this->lp_z1 = lp_z1;
+ this->lp_z2 = lp_z2;
+ this->ap_z1 = ap_z1;
+}
+
template class BandSplitterR<float>;
template class BandSplitterR<double>;
diff --git a/Alc/filters/splitter.h b/Alc/filters/splitter.h
index f7ea608b..83281366 100644
--- a/Alc/filters/splitter.h
+++ b/Alc/filters/splitter.h
@@ -16,7 +16,8 @@ class BandSplitterR {
public:
void init(Real f0norm);
void clear() noexcept { lp_z1 = lp_z2 = ap_z1 = 0.0f; }
- void process(Real *hpout, Real *lpout, const Real *input, int count);
+ void process(Real *hpout, Real *lpout, const Real *input, const int count);
+ void applyHfScale(Real *RESTRICT samples, const Real hfscale, const int count);
};
using BandSplitter = BandSplitterR<float>;