Add a method to apply an HF scale without band-splitting

This commit is contained in:
Chris Robinson
2019-03-10 10:30:33 -07:00
parent 6a95189ef6
commit 12721f94a7
4 changed files with 52 additions and 25 deletions
+7 -16
View File
@@ -424,32 +424,23 @@ struct ReverbState final : public EffectState {
for(ALsizei c{0};c < NUM_LINES;c++)
{
/* Apply scaling to the B-Format's HF response to "upsample" it to
* higher-order output. Use the early buffer to store the split
* signal since it's not needed anymore.
* higher-order output.
*/
const ALfloat hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]};
ALfloat (&hfbuf)[BUFFERSIZE] = mEarlyBuffer[0];
ALfloat (&lfbuf)[BUFFERSIZE] = mEarlyBuffer[1];
mAmbiSplitter[0][c].applyHfScale(mTempSamples[c], hfscale, todo);
mAmbiSplitter[0][c].process(hfbuf, lfbuf, mTempSamples[c], todo);
MixRowSamples(lfbuf, &hfscale, &hfbuf, 1, 0, todo);
MixSamples(lfbuf, numOutput, samplesOut, mEarly.CurrentGain[c], mEarly.PanGain[c],
todo, 0, todo);
MixSamples(mTempSamples[c], numOutput, samplesOut, mEarly.CurrentGain[c],
mEarly.PanGain[c], todo, 0, todo);
}
ConvertA2B(mTempSamples, mLateBuffer, todo);
for(ALsizei c{0};c < NUM_LINES;c++)
{
const ALfloat hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]};
ALfloat (&hfbuf)[BUFFERSIZE] = mLateBuffer[0];
ALfloat (&lfbuf)[BUFFERSIZE] = mLateBuffer[1];
mAmbiSplitter[1][c].applyHfScale(mTempSamples[c], hfscale, todo);
mAmbiSplitter[1][c].process(hfbuf, lfbuf, mTempSamples[c], todo);
MixRowSamples(lfbuf, &hfscale, &hfbuf, 1, 0, todo);
MixSamples(lfbuf, numOutput, samplesOut, mLate.CurrentGain[c], mLate.PanGain[c], todo,
0, todo);
MixSamples(mTempSamples[c], numOutput, samplesOut, mLate.CurrentGain[c],
mLate.PanGain[c], todo, 0, todo);
}
}
+35 -1
View File
@@ -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>;
+2 -1
View File
@@ -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>;
+8 -7
View File
@@ -612,13 +612,14 @@ void MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context, const
* be desirable.
*/
const ALfloat hfscale{(chan==0) ? voice->AmbiScales[0] : voice->AmbiScales[1]};
ALfloat (&hfbuf)[BUFFERSIZE] = Device->FilteredData;
ALfloat (&lfbuf)[BUFFERSIZE] = Device->ResampledData;
voice->AmbiSplitter[chan].process(hfbuf, lfbuf, ResampledData, DstBufferSize);
MixRowSamples(lfbuf, &hfscale, &hfbuf, 1, 0, DstBufferSize);
ResampledData = lfbuf;
/* Beware the evil const_cast. It's safe since it's pointing to
* either SrcData or Device->ResampledData (both non-const),
* but the resample method takes its input as const float* and
* may return it without copying to output, making it currently
* unavoidable.
*/
voice->AmbiSplitter[chan].applyHfScale(const_cast<ALfloat*>(ResampledData),
hfscale, DstBufferSize);
}
/* Now filter and mix to the appropriate outputs. */