mirror of
https://github.com/love2d/megasource.git
synced 2026-08-19 20:20:11 +02:00
update OpenAL-Soft to 1.24.3.
This commit is contained in:
@@ -122,7 +122,7 @@ void AutowahState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
{
|
||||
auto &props = std::get<AutowahProps>(*props_);
|
||||
const DeviceBase *device{context->mDevice};
|
||||
const auto frequency = static_cast<float>(device->Frequency);
|
||||
const auto frequency = static_cast<float>(device->mSampleRate);
|
||||
|
||||
const float ReleaseTime{std::clamp(props.ReleaseTime, 0.001f, 1.0f)};
|
||||
|
||||
@@ -214,7 +214,7 @@ void AutowahState::process(const size_t samplesToDo,
|
||||
chandata->mFilter.z2 = z2;
|
||||
|
||||
/* Now, mix the processed sound data to the output. */
|
||||
MixSamples({mBufferOut.data(), samplesToDo}, samplesOut[outidx].data(),
|
||||
MixSamples(al::span{mBufferOut}.first(samplesToDo), samplesOut[outidx],
|
||||
chandata->mCurrentGain, chandata->mTargetGain, samplesToDo);
|
||||
++chandata;
|
||||
}
|
||||
|
||||
@@ -12,21 +12,18 @@ inline float ReverbBoost{1.0f};
|
||||
|
||||
EffectStateFactory *NullStateFactory_getFactory();
|
||||
EffectStateFactory *ReverbStateFactory_getFactory();
|
||||
EffectStateFactory *StdReverbStateFactory_getFactory();
|
||||
EffectStateFactory *AutowahStateFactory_getFactory();
|
||||
EffectStateFactory *ChorusStateFactory_getFactory();
|
||||
EffectStateFactory *AutowahStateFactory_getFactory();
|
||||
EffectStateFactory *CompressorStateFactory_getFactory();
|
||||
EffectStateFactory *DistortionStateFactory_getFactory();
|
||||
EffectStateFactory *EchoStateFactory_getFactory();
|
||||
EffectStateFactory *EqualizerStateFactory_getFactory();
|
||||
EffectStateFactory *FlangerStateFactory_getFactory();
|
||||
EffectStateFactory *FshifterStateFactory_getFactory();
|
||||
EffectStateFactory *ModulatorStateFactory_getFactory();
|
||||
EffectStateFactory *PshifterStateFactory_getFactory();
|
||||
EffectStateFactory* VmorpherStateFactory_getFactory();
|
||||
|
||||
EffectStateFactory *DedicatedDialogStateFactory_getFactory();
|
||||
EffectStateFactory *DedicatedLfeStateFactory_getFactory();
|
||||
EffectStateFactory *DedicatedStateFactory_getFactory();
|
||||
|
||||
EffectStateFactory *ConvolutionStateFactory_getFactory();
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ constexpr auto lcoeffs_nrml = CalcDirectionCoeffs(std::array{-inv_sqrt2, 0.0f, i
|
||||
constexpr auto rcoeffs_nrml = CalcDirectionCoeffs(std::array{ inv_sqrt2, 0.0f, inv_sqrt2});
|
||||
|
||||
|
||||
struct ChorusState : public EffectState {
|
||||
struct ChorusState final : public EffectState {
|
||||
std::vector<float> mDelayBuffer;
|
||||
uint mOffset{0};
|
||||
|
||||
@@ -94,35 +94,18 @@ struct ChorusState : public EffectState {
|
||||
const float delay, const float depth, const float feedback, const float rate,
|
||||
int phase, const EffectTarget target);
|
||||
|
||||
void deviceUpdate(const DeviceBase *device, const BufferStorage*) override
|
||||
{ deviceUpdate(device, ChorusMaxDelay); }
|
||||
void deviceUpdate(const DeviceBase *device, const BufferStorage*) final;
|
||||
void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props_,
|
||||
const EffectTarget target) override
|
||||
{
|
||||
auto &props = std::get<ChorusProps>(*props_);
|
||||
update(context, slot, props.Waveform, props.Delay, props.Depth, props.Feedback, props.Rate,
|
||||
props.Phase, target);
|
||||
}
|
||||
const EffectTarget target) final;
|
||||
void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn,
|
||||
const al::span<FloatBufferLine> samplesOut) final;
|
||||
};
|
||||
|
||||
struct FlangerState final : public ChorusState {
|
||||
void deviceUpdate(const DeviceBase *device, const BufferStorage*) final
|
||||
{ ChorusState::deviceUpdate(device, FlangerMaxDelay); }
|
||||
void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props_,
|
||||
const EffectTarget target) final
|
||||
{
|
||||
auto &props = std::get<FlangerProps>(*props_);
|
||||
ChorusState::update(context, slot, props.Waveform, props.Delay, props.Depth,
|
||||
props.Feedback, props.Rate, props.Phase, target);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void ChorusState::deviceUpdate(const DeviceBase *Device, const float MaxDelay)
|
||||
void ChorusState::deviceUpdate(const DeviceBase *Device, const BufferStorage*)
|
||||
{
|
||||
const auto frequency = static_cast<float>(Device->Frequency);
|
||||
constexpr auto MaxDelay = std::max(ChorusMaxDelay, FlangerMaxDelay);
|
||||
const auto frequency = static_cast<float>(Device->mSampleRate);
|
||||
const size_t maxlen{NextPowerOf2(float2uint(MaxDelay*2.0f*frequency) + 1u)};
|
||||
if(maxlen != mDelayBuffer.size())
|
||||
decltype(mDelayBuffer)(maxlen).swap(mDelayBuffer);
|
||||
@@ -136,34 +119,40 @@ void ChorusState::deviceUpdate(const DeviceBase *Device, const float MaxDelay)
|
||||
}
|
||||
|
||||
void ChorusState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
const ChorusWaveform waveform, const float delay, const float depth, const float feedback,
|
||||
const float rate, int phase, const EffectTarget target)
|
||||
const EffectProps *props_, const EffectTarget target)
|
||||
{
|
||||
static constexpr int mindelay{MaxResamplerEdge << gCubicTable.sTableBits};
|
||||
auto &props = std::get<ChorusProps>(*props_);
|
||||
|
||||
/* The LFO depth is scaled to be relative to the sample delay. Clamp the
|
||||
* delay and depth to allow enough padding for resampling.
|
||||
*/
|
||||
const DeviceBase *device{context->mDevice};
|
||||
const auto frequency = static_cast<float>(device->Frequency);
|
||||
const auto frequency = static_cast<float>(device->mSampleRate);
|
||||
|
||||
mWaveform = waveform;
|
||||
mWaveform = props.Waveform;
|
||||
|
||||
mDelay = std::max(float2int(std::round(delay*frequency*gCubicTable.sTableSteps)), mindelay);
|
||||
mDepth = std::min(static_cast<float>(mDelay)*depth, static_cast<float>(mDelay-mindelay));
|
||||
const auto stepscale = float{frequency * gCubicTable.sTableSteps};
|
||||
mDelay = std::max(float2int(std::round(props.Delay * stepscale)), mindelay);
|
||||
mDepth = std::min(static_cast<float>(mDelay) * props.Depth,
|
||||
static_cast<float>(mDelay - mindelay));
|
||||
|
||||
mFeedback = feedback;
|
||||
mFeedback = props.Feedback;
|
||||
|
||||
/* Gains for left and right sides */
|
||||
const bool ispairwise{device->mRenderMode == RenderMode::Pairwise};
|
||||
const auto lcoeffs = (!ispairwise) ? al::span{lcoeffs_nrml} : al::span{lcoeffs_pw};
|
||||
const auto rcoeffs = (!ispairwise) ? al::span{rcoeffs_nrml} : al::span{rcoeffs_pw};
|
||||
|
||||
/* Attenuate the outputs by -3dB, since we duplicate a single mono input to
|
||||
* separate left/right outputs.
|
||||
*/
|
||||
const auto gain = slot->Gain * (1.0f/al::numbers::sqrt2_v<float>);
|
||||
mOutTarget = target.Main->Buffer;
|
||||
ComputePanGains(target.Main, lcoeffs, slot->Gain, mGains[0].Target);
|
||||
ComputePanGains(target.Main, rcoeffs, slot->Gain, mGains[1].Target);
|
||||
ComputePanGains(target.Main, lcoeffs, gain, mGains[0].Target);
|
||||
ComputePanGains(target.Main, rcoeffs, gain, mGains[1].Target);
|
||||
|
||||
if(!(rate > 0.0f))
|
||||
if(!(props.Rate > 0.0f))
|
||||
{
|
||||
mLfoOffset = 0;
|
||||
mLfoRange = 1;
|
||||
@@ -176,7 +165,8 @@ void ChorusState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
* max range to avoid overflow when calculating the displacement.
|
||||
*/
|
||||
static constexpr int range_limit{std::numeric_limits<int>::max()/360 - 180};
|
||||
const uint lfo_range{float2uint(std::min(std::round(frequency/rate), float{range_limit}))};
|
||||
const auto range = std::round(frequency / props.Rate);
|
||||
const uint lfo_range{float2uint(std::min(range, float{range_limit}))};
|
||||
|
||||
mLfoOffset = mLfoOffset * lfo_range / mLfoRange;
|
||||
mLfoRange = lfo_range;
|
||||
@@ -191,7 +181,8 @@ void ChorusState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
}
|
||||
|
||||
/* Calculate lfo phase displacement */
|
||||
if(phase < 0) phase = 360 + phase;
|
||||
auto phase = props.Phase;
|
||||
if(phase < 0) phase += 360;
|
||||
mLfoDisp = (mLfoRange*static_cast<uint>(phase) + 180) / 360;
|
||||
}
|
||||
}
|
||||
@@ -204,9 +195,6 @@ void ChorusState::calcTriangleDelays(const size_t todo)
|
||||
const float depth{mDepth};
|
||||
const int delay{mDelay};
|
||||
|
||||
ASSUME(lfo_range > 0);
|
||||
ASSUME(todo > 0);
|
||||
|
||||
auto gen_lfo = [lfo_scale,depth,delay](const uint offset) -> uint
|
||||
{
|
||||
const float offset_norm{static_cast<float>(offset) * lfo_scale};
|
||||
@@ -214,25 +202,24 @@ void ChorusState::calcTriangleDelays(const size_t todo)
|
||||
};
|
||||
|
||||
uint offset{mLfoOffset};
|
||||
ASSUME(lfo_range > offset);
|
||||
auto ldelays = mModDelays[0].begin();
|
||||
for(size_t i{0};i < todo;)
|
||||
{
|
||||
size_t rem{std::min(todo-i, size_t{lfo_range-offset})};
|
||||
do {
|
||||
mModDelays[0][i++] = gen_lfo(offset++);
|
||||
} while(--rem);
|
||||
if(offset == lfo_range)
|
||||
offset = 0;
|
||||
const size_t rem{std::min(todo-i, size_t{lfo_range-offset})};
|
||||
ldelays = std::generate_n(ldelays, rem, [&offset,gen_lfo] { return gen_lfo(offset++); });
|
||||
if(offset == lfo_range) offset = 0;
|
||||
i += rem;
|
||||
}
|
||||
|
||||
offset = (mLfoOffset+mLfoDisp) % lfo_range;
|
||||
auto rdelays = mModDelays[1].begin();
|
||||
for(size_t i{0};i < todo;)
|
||||
{
|
||||
size_t rem{std::min(todo-i, size_t{lfo_range-offset})};
|
||||
do {
|
||||
mModDelays[1][i++] = gen_lfo(offset++);
|
||||
} while(--rem);
|
||||
if(offset == lfo_range)
|
||||
offset = 0;
|
||||
const size_t rem{std::min(todo-i, size_t{lfo_range-offset})};
|
||||
rdelays = std::generate_n(rdelays, rem, [&offset,gen_lfo] { return gen_lfo(offset++); });
|
||||
if(offset == lfo_range) offset = 0;
|
||||
i += rem;
|
||||
}
|
||||
|
||||
mLfoOffset = static_cast<uint>(mLfoOffset+todo) % lfo_range;
|
||||
@@ -245,9 +232,6 @@ void ChorusState::calcSinusoidDelays(const size_t todo)
|
||||
const float depth{mDepth};
|
||||
const int delay{mDelay};
|
||||
|
||||
ASSUME(lfo_range > 0);
|
||||
ASSUME(todo > 0);
|
||||
|
||||
auto gen_lfo = [lfo_scale,depth,delay](const uint offset) -> uint
|
||||
{
|
||||
const float offset_norm{static_cast<float>(offset) * lfo_scale};
|
||||
@@ -255,25 +239,24 @@ void ChorusState::calcSinusoidDelays(const size_t todo)
|
||||
};
|
||||
|
||||
uint offset{mLfoOffset};
|
||||
ASSUME(lfo_range > offset);
|
||||
auto ldelays = mModDelays[0].begin();
|
||||
for(size_t i{0};i < todo;)
|
||||
{
|
||||
size_t rem{std::min(todo-i, size_t{lfo_range-offset})};
|
||||
do {
|
||||
mModDelays[0][i++] = gen_lfo(offset++);
|
||||
} while(--rem);
|
||||
if(offset == lfo_range)
|
||||
offset = 0;
|
||||
const size_t rem{std::min(todo-i, size_t{lfo_range-offset})};
|
||||
ldelays = std::generate_n(ldelays, rem, [&offset,gen_lfo] { return gen_lfo(offset++); });
|
||||
if(offset == lfo_range) offset = 0;
|
||||
i += rem;
|
||||
}
|
||||
|
||||
offset = (mLfoOffset+mLfoDisp) % lfo_range;
|
||||
auto rdelays = mModDelays[1].begin();
|
||||
for(size_t i{0};i < todo;)
|
||||
{
|
||||
size_t rem{std::min(todo-i, size_t{lfo_range-offset})};
|
||||
do {
|
||||
mModDelays[1][i++] = gen_lfo(offset++);
|
||||
} while(--rem);
|
||||
if(offset == lfo_range)
|
||||
offset = 0;
|
||||
const size_t rem{std::min(todo-i, size_t{lfo_range-offset})};
|
||||
rdelays = std::generate_n(rdelays, rem, [&offset,gen_lfo] { return gen_lfo(offset++); });
|
||||
if(offset == lfo_range) offset = 0;
|
||||
i += rem;
|
||||
}
|
||||
|
||||
mLfoOffset = static_cast<uint>(mLfoOffset+todo) % lfo_range;
|
||||
@@ -322,10 +305,10 @@ void ChorusState::process(const size_t samplesToDo, const al::span<const FloatBu
|
||||
++offset;
|
||||
}
|
||||
|
||||
MixSamples(lbuffer.first(samplesToDo), samplesOut, mGains[0].Current.data(),
|
||||
mGains[0].Target.data(), samplesToDo, 0);
|
||||
MixSamples(rbuffer.first(samplesToDo), samplesOut, mGains[1].Current.data(),
|
||||
mGains[1].Target.data(), samplesToDo, 0);
|
||||
MixSamples(lbuffer.first(samplesToDo), samplesOut, mGains[0].Current, mGains[0].Target,
|
||||
samplesToDo, 0);
|
||||
MixSamples(rbuffer.first(samplesToDo), samplesOut, mGains[1].Current, mGains[1].Target,
|
||||
samplesToDo, 0);
|
||||
|
||||
mOffset = offset;
|
||||
}
|
||||
@@ -336,15 +319,6 @@ struct ChorusStateFactory final : public EffectStateFactory {
|
||||
{ return al::intrusive_ptr<EffectState>{new ChorusState{}}; }
|
||||
};
|
||||
|
||||
|
||||
/* Flanger is basically a chorus with a really short delay. They can both use
|
||||
* the same processing functions, so piggyback flanger on the chorus functions.
|
||||
*/
|
||||
struct FlangerStateFactory final : public EffectStateFactory {
|
||||
al::intrusive_ptr<EffectState> create() override
|
||||
{ return al::intrusive_ptr<EffectState>{new FlangerState{}}; }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
EffectStateFactory *ChorusStateFactory_getFactory()
|
||||
@@ -352,9 +326,3 @@ EffectStateFactory *ChorusStateFactory_getFactory()
|
||||
static ChorusStateFactory ChorusFactory{};
|
||||
return &ChorusFactory;
|
||||
}
|
||||
|
||||
EffectStateFactory *FlangerStateFactory_getFactory()
|
||||
{
|
||||
static FlangerStateFactory FlangerFactory{};
|
||||
return &FlangerFactory;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ struct CompressorState final : public EffectState {
|
||||
float mAttackMult{1.0f};
|
||||
float mReleaseMult{1.0f};
|
||||
float mEnvFollower{1.0f};
|
||||
alignas(16) FloatBufferLine mGains{};
|
||||
|
||||
|
||||
void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override;
|
||||
@@ -88,8 +89,8 @@ void CompressorState::deviceUpdate(const DeviceBase *device, const BufferStorage
|
||||
/* Number of samples to do a full attack and release (non-integer sample
|
||||
* counts are okay).
|
||||
*/
|
||||
const float attackCount{static_cast<float>(device->Frequency) * AttackTime};
|
||||
const float releaseCount{static_cast<float>(device->Frequency) * ReleaseTime};
|
||||
const float attackCount{static_cast<float>(device->mSampleRate) * AttackTime};
|
||||
const float releaseCount{static_cast<float>(device->mSampleRate) * ReleaseTime};
|
||||
|
||||
/* Calculate per-sample multipliers to attack and release at the desired
|
||||
* rates.
|
||||
@@ -115,72 +116,62 @@ void CompressorState::update(const ContextBase*, const EffectSlot *slot,
|
||||
void CompressorState::process(const size_t samplesToDo,
|
||||
const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
|
||||
{
|
||||
for(size_t base{0u};base < samplesToDo;)
|
||||
/* Generate the per-sample gains from the signal envelope. */
|
||||
float env{mEnvFollower};
|
||||
if(mEnabled)
|
||||
{
|
||||
std::array<float,256> gains;
|
||||
const size_t td{std::min(gains.size(), samplesToDo-base)};
|
||||
|
||||
/* Generate the per-sample gains from the signal envelope. */
|
||||
float env{mEnvFollower};
|
||||
if(mEnabled)
|
||||
for(size_t i{0u};i < samplesToDo;++i)
|
||||
{
|
||||
for(size_t i{0u};i < td;++i)
|
||||
{
|
||||
/* Clamp the absolute amplitude to the defined envelope limits,
|
||||
* then attack or release the envelope to reach it.
|
||||
*/
|
||||
const float amplitude{std::clamp(std::fabs(samplesIn[0][base+i]), AmpEnvelopeMin,
|
||||
AmpEnvelopeMax)};
|
||||
if(amplitude > env)
|
||||
env = std::min(env*mAttackMult, amplitude);
|
||||
else if(amplitude < env)
|
||||
env = std::max(env*mReleaseMult, amplitude);
|
||||
|
||||
/* Apply the reciprocal of the envelope to normalize the volume
|
||||
* (compress the dynamic range).
|
||||
*/
|
||||
gains[i] = 1.0f / env;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Same as above, except the amplitude is forced to 1. This helps
|
||||
* ensure smooth gain changes when the compressor is turned on and
|
||||
* off.
|
||||
/* Clamp the absolute amplitude to the defined envelope limits,
|
||||
* then attack or release the envelope to reach it.
|
||||
*/
|
||||
for(size_t i{0u};i < td;++i)
|
||||
{
|
||||
const float amplitude{1.0f};
|
||||
if(amplitude > env)
|
||||
env = std::min(env*mAttackMult, amplitude);
|
||||
else if(amplitude < env)
|
||||
env = std::max(env*mReleaseMult, amplitude);
|
||||
const float amplitude{std::clamp(std::fabs(samplesIn[0][i]), AmpEnvelopeMin,
|
||||
AmpEnvelopeMax)};
|
||||
if(amplitude > env)
|
||||
env = std::min(env*mAttackMult, amplitude);
|
||||
else if(amplitude < env)
|
||||
env = std::max(env*mReleaseMult, amplitude);
|
||||
|
||||
gains[i] = 1.0f / env;
|
||||
}
|
||||
/* Apply the reciprocal of the envelope to normalize the volume
|
||||
* (compress the dynamic range).
|
||||
*/
|
||||
mGains[i] = 1.0f / env;
|
||||
}
|
||||
mEnvFollower = env;
|
||||
|
||||
/* Now compress the signal amplitude to output. */
|
||||
auto chan = mChans.cbegin();
|
||||
for(const auto &input : samplesIn)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Same as above, except the amplitude is forced to 1. This helps
|
||||
* ensure smooth gain changes when the compressor is turned on and off.
|
||||
*/
|
||||
for(size_t i{0u};i < samplesToDo;++i)
|
||||
{
|
||||
const size_t outidx{chan->mTarget};
|
||||
if(outidx != InvalidChannelIndex)
|
||||
{
|
||||
const auto src = al::span{input}.subspan(base);
|
||||
float *RESTRICT dst{samplesOut[outidx].data() + base};
|
||||
const float gain{chan->mGain};
|
||||
if(!(std::fabs(gain) > GainSilenceThreshold))
|
||||
{
|
||||
for(size_t i{0u};i < td;i++)
|
||||
dst[i] += src[i] * gains[i] * gain;
|
||||
}
|
||||
}
|
||||
++chan;
|
||||
}
|
||||
const float amplitude{1.0f};
|
||||
if(amplitude > env)
|
||||
env = std::min(env*mAttackMult, amplitude);
|
||||
else if(amplitude < env)
|
||||
env = std::max(env*mReleaseMult, amplitude);
|
||||
|
||||
base += td;
|
||||
mGains[i] = 1.0f / env;
|
||||
}
|
||||
}
|
||||
mEnvFollower = env;
|
||||
|
||||
/* Now compress the signal amplitude to output. */
|
||||
auto chan = mChans.cbegin();
|
||||
for(const auto &input : samplesIn)
|
||||
{
|
||||
const size_t outidx{chan->mTarget};
|
||||
if(outidx != InvalidChannelIndex)
|
||||
{
|
||||
const auto dst = al::span{samplesOut[outidx]};
|
||||
const float gain{chan->mGain};
|
||||
if(!(std::fabs(gain) > GainSilenceThreshold))
|
||||
{
|
||||
for(size_t i{0u};i < samplesToDo;++i)
|
||||
dst[i] += input[i] * mGains[i] * gain;
|
||||
}
|
||||
}
|
||||
++chan;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "config_simd.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -11,11 +12,10 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
|
||||
#ifdef HAVE_SSE_INTRINSICS
|
||||
#if HAVE_SSE_INTRINSICS
|
||||
#include <xmmintrin.h>
|
||||
#elif defined(HAVE_NEON)
|
||||
#elif HAVE_NEON
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
@@ -171,7 +171,7 @@ constexpr size_t ConvolveUpdateSamples{ConvolveUpdateSize / 2};
|
||||
void apply_fir(al::span<float> dst, const al::span<const float> input, const al::span<const float,ConvolveUpdateSamples> filter)
|
||||
{
|
||||
auto src = input.begin();
|
||||
#ifdef HAVE_SSE_INTRINSICS
|
||||
#if HAVE_SSE_INTRINSICS
|
||||
std::generate(dst.begin(), dst.end(), [&src,filter]
|
||||
{
|
||||
__m128 r4{_mm_setzero_ps()};
|
||||
@@ -189,7 +189,7 @@ void apply_fir(al::span<float> dst, const al::span<const float> input, const al:
|
||||
return _mm_cvtss_f32(r4);
|
||||
});
|
||||
|
||||
#elif defined(HAVE_NEON)
|
||||
#elif HAVE_NEON
|
||||
|
||||
std::generate(dst.begin(), dst.end(), [&src,filter]
|
||||
{
|
||||
@@ -227,7 +227,7 @@ struct ConvolutionState final : public EffectState {
|
||||
al::vector<std::array<float,ConvolveUpdateSamples>,16> mFilter;
|
||||
al::vector<std::array<float,ConvolveUpdateSamples*2>,16> mOutput;
|
||||
|
||||
PFFFTSetup mFft{};
|
||||
PFFFTSetup mFft;
|
||||
alignas(16) std::array<float,ConvolveUpdateSize> mFftBuffer{};
|
||||
alignas(16) std::array<float,ConvolveUpdateSize> mFftWorkBuffer{};
|
||||
|
||||
@@ -237,7 +237,7 @@ struct ConvolutionState final : public EffectState {
|
||||
struct ChannelData {
|
||||
alignas(16) FloatBufferLine mBuffer{};
|
||||
float mHfScale{}, mLfScale{};
|
||||
BandSplitter mFilter{};
|
||||
BandSplitter mFilter;
|
||||
std::array<float,MaxOutputChannels> Current{};
|
||||
std::array<float,MaxOutputChannels> Target{};
|
||||
};
|
||||
@@ -264,8 +264,8 @@ void ConvolutionState::NormalMix(const al::span<FloatBufferLine> samplesOut,
|
||||
const size_t samplesToDo)
|
||||
{
|
||||
for(auto &chan : mChans)
|
||||
MixSamples({chan.mBuffer.data(), samplesToDo}, samplesOut, chan.Current.data(),
|
||||
chan.Target.data(), samplesToDo, 0);
|
||||
MixSamples(al::span{chan.mBuffer}.first(samplesToDo), samplesOut, chan.Current,
|
||||
chan.Target, samplesToDo, 0);
|
||||
}
|
||||
|
||||
void ConvolutionState::UpsampleMix(const al::span<FloatBufferLine> samplesOut,
|
||||
@@ -273,9 +273,9 @@ void ConvolutionState::UpsampleMix(const al::span<FloatBufferLine> samplesOut,
|
||||
{
|
||||
for(auto &chan : mChans)
|
||||
{
|
||||
const al::span<float> src{chan.mBuffer.data(), samplesToDo};
|
||||
const auto src = al::span{chan.mBuffer}.first(samplesToDo);
|
||||
chan.mFilter.processScale(src, chan.mHfScale, chan.mLfScale);
|
||||
MixSamples(src, samplesOut, chan.Current.data(), chan.Target.data(), samplesToDo, 0);
|
||||
MixSamples(src, samplesOut, chan.Current, chan.Target, samplesToDo, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,13 +322,13 @@ void ConvolutionState::deviceUpdate(const DeviceBase *device, const BufferStorag
|
||||
* called very infrequently, go ahead and use the polyphase resampler.
|
||||
*/
|
||||
PPhaseResampler resampler;
|
||||
if(device->Frequency != buffer->mSampleRate)
|
||||
resampler.init(buffer->mSampleRate, device->Frequency);
|
||||
if(device->mSampleRate != buffer->mSampleRate)
|
||||
resampler.init(buffer->mSampleRate, device->mSampleRate);
|
||||
const auto resampledCount = static_cast<uint>(
|
||||
(uint64_t{buffer->mSampleLen}*device->Frequency+(buffer->mSampleRate-1)) /
|
||||
(uint64_t{buffer->mSampleLen}*device->mSampleRate+(buffer->mSampleRate-1)) /
|
||||
buffer->mSampleRate);
|
||||
|
||||
const BandSplitter splitter{device->mXOverFreq / static_cast<float>(device->Frequency)};
|
||||
const BandSplitter splitter{device->mXOverFreq / static_cast<float>(device->mSampleRate)};
|
||||
for(auto &e : mChans)
|
||||
e.mFilter = splitter;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace {
|
||||
|
||||
using uint = unsigned int;
|
||||
|
||||
struct DedicatedState : public EffectState {
|
||||
struct DedicatedState final : public EffectState {
|
||||
/* The "dedicated" effect can output to the real output, so should have
|
||||
* gains for all possible output channels and not just the main ambisonic
|
||||
* buffer.
|
||||
@@ -53,90 +53,72 @@ struct DedicatedState : public EffectState {
|
||||
|
||||
|
||||
void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) final;
|
||||
void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props,
|
||||
const EffectTarget target) override;
|
||||
void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props_,
|
||||
const EffectTarget target) final;
|
||||
void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn,
|
||||
const al::span<FloatBufferLine> samplesOut) final;
|
||||
};
|
||||
|
||||
struct DedicatedLfeState final : public DedicatedState {
|
||||
void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props,
|
||||
const EffectTarget target) final;
|
||||
};
|
||||
|
||||
void DedicatedState::deviceUpdate(const DeviceBase*, const BufferStorage*)
|
||||
{
|
||||
std::fill(mCurrentGains.begin(), mCurrentGains.end(), 0.0f);
|
||||
}
|
||||
|
||||
void DedicatedState::update(const ContextBase*, const EffectSlot *slot,
|
||||
const EffectProps *props, const EffectTarget target)
|
||||
const EffectProps *props_, const EffectTarget target)
|
||||
{
|
||||
std::fill(mTargetGains.begin(), mTargetGains.end(), 0.0f);
|
||||
|
||||
const float Gain{slot->Gain * std::get<DedicatedDialogProps>(*props).Gain};
|
||||
auto &props = std::get<DedicatedProps>(*props_);
|
||||
const float Gain{slot->Gain * props.Gain};
|
||||
|
||||
/* Dialog goes to the front-center speaker if it exists, otherwise it plays
|
||||
* from the front-center location.
|
||||
*/
|
||||
const size_t idx{target.RealOut ? target.RealOut->ChannelIndex[FrontCenter]
|
||||
: InvalidChannelIndex};
|
||||
if(idx != InvalidChannelIndex)
|
||||
if(props.Target == DedicatedProps::Dialog)
|
||||
{
|
||||
mOutTarget = target.RealOut->Buffer;
|
||||
mTargetGains[idx] = Gain;
|
||||
/* Dialog goes to the front-center speaker if it exists, otherwise it
|
||||
* plays from the front-center location.
|
||||
*/
|
||||
const size_t idx{target.RealOut ? target.RealOut->ChannelIndex[FrontCenter]
|
||||
: InvalidChannelIndex};
|
||||
if(idx != InvalidChannelIndex)
|
||||
{
|
||||
mOutTarget = target.RealOut->Buffer;
|
||||
mTargetGains[idx] = Gain;
|
||||
}
|
||||
else
|
||||
{
|
||||
static constexpr auto coeffs = CalcDirectionCoeffs(std::array{0.0f, 0.0f, -1.0f});
|
||||
|
||||
mOutTarget = target.Main->Buffer;
|
||||
ComputePanGains(target.Main, coeffs, Gain, mTargetGains);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(props.Target == DedicatedProps::Lfe)
|
||||
{
|
||||
static constexpr auto coeffs = CalcDirectionCoeffs(std::array{0.0f, 0.0f, -1.0f});
|
||||
|
||||
mOutTarget = target.Main->Buffer;
|
||||
ComputePanGains(target.Main, coeffs, Gain, mTargetGains);
|
||||
}
|
||||
}
|
||||
|
||||
void DedicatedLfeState::update(const ContextBase*, const EffectSlot *slot,
|
||||
const EffectProps *props, const EffectTarget target)
|
||||
{
|
||||
std::fill(mTargetGains.begin(), mTargetGains.end(), 0.0f);
|
||||
|
||||
const float Gain{slot->Gain * std::get<DedicatedLfeProps>(*props).Gain};
|
||||
|
||||
const size_t idx{target.RealOut ? target.RealOut->ChannelIndex[LFE] : InvalidChannelIndex};
|
||||
if(idx != InvalidChannelIndex)
|
||||
{
|
||||
mOutTarget = target.RealOut->Buffer;
|
||||
mTargetGains[idx] = Gain;
|
||||
const size_t idx{target.RealOut ? target.RealOut->ChannelIndex[LFE] : InvalidChannelIndex};
|
||||
if(idx != InvalidChannelIndex)
|
||||
{
|
||||
mOutTarget = target.RealOut->Buffer;
|
||||
mTargetGains[idx] = Gain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DedicatedState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
|
||||
{
|
||||
MixSamples({samplesIn[0].data(), samplesToDo}, samplesOut, mCurrentGains.data(),
|
||||
mTargetGains.data(), samplesToDo, 0);
|
||||
MixSamples(al::span{samplesIn[0]}.first(samplesToDo), samplesOut, mCurrentGains, mTargetGains,
|
||||
samplesToDo, 0);
|
||||
}
|
||||
|
||||
|
||||
struct DedicatedDialogStateFactory final : public EffectStateFactory {
|
||||
struct DedicatedStateFactory final : public EffectStateFactory {
|
||||
al::intrusive_ptr<EffectState> create() override
|
||||
{ return al::intrusive_ptr<EffectState>{new DedicatedState{}}; }
|
||||
};
|
||||
|
||||
struct DedicatedLfeStateFactory final : public EffectStateFactory {
|
||||
al::intrusive_ptr<EffectState> create() override
|
||||
{ return al::intrusive_ptr<EffectState>{new DedicatedLfeState{}}; }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
EffectStateFactory *DedicatedDialogStateFactory_getFactory()
|
||||
EffectStateFactory *DedicatedStateFactory_getFactory()
|
||||
{
|
||||
static DedicatedDialogStateFactory DedicatedFactory{};
|
||||
return &DedicatedFactory;
|
||||
}
|
||||
|
||||
EffectStateFactory *DedicatedLfeStateFactory_getFactory()
|
||||
{
|
||||
static DedicatedLfeStateFactory DedicatedFactory{};
|
||||
static DedicatedStateFactory DedicatedFactory{};
|
||||
return &DedicatedFactory;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ void DistortionState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
/* Divide normalized frequency by the amount of oversampling done during
|
||||
* processing.
|
||||
*/
|
||||
auto frequency = static_cast<float>(device->Frequency);
|
||||
auto frequency = static_cast<float>(device->mSampleRate);
|
||||
mLowpass.setParamsFromBandwidth(BiquadType::LowPass, cutoff/frequency/4.0f, 1.0f, bandwidth);
|
||||
|
||||
cutoff = props.EQCenter;
|
||||
@@ -124,7 +124,7 @@ void DistortionState::process(const size_t samplesToDo, const al::span<const Flo
|
||||
* (which is fortunately first step of distortion). So combine three
|
||||
* operations into the one.
|
||||
*/
|
||||
mLowpass.process({mBuffer[0].data(), todo}, mBuffer[1]);
|
||||
mLowpass.process(al::span{mBuffer[0]}.first(todo), mBuffer[1]);
|
||||
|
||||
/* Second step, do distortion using waveshaper function to emulate
|
||||
* signal processing during tube overdriving. Three steps of
|
||||
@@ -142,22 +142,30 @@ void DistortionState::process(const size_t samplesToDo, const al::span<const Flo
|
||||
proc_sample);
|
||||
|
||||
/* Third step, do bandpass filtering of distorted signal. */
|
||||
mBandpass.process({mBuffer[0].data(), todo}, mBuffer[1]);
|
||||
mBandpass.process(al::span{mBuffer[0]}.first(todo), mBuffer[1]);
|
||||
|
||||
todo >>= 2;
|
||||
auto outgains = mGain.cbegin();
|
||||
for(FloatBufferLine &RESTRICT output : samplesOut)
|
||||
auto proc_bufline = [this,base,todo,&outgains](FloatBufferSpan output)
|
||||
{
|
||||
/* Fourth step, final, do attenuation and perform decimation,
|
||||
* storing only one sample out of four.
|
||||
*/
|
||||
const float gain{*(outgains++)};
|
||||
if(!(std::fabs(gain) > GainSilenceThreshold))
|
||||
continue;
|
||||
return;
|
||||
|
||||
for(size_t i{0u};i < todo;i++)
|
||||
output[base+i] += gain * mBuffer[1][i*4];
|
||||
}
|
||||
auto src = mBuffer[1].cbegin();
|
||||
const auto dst = al::span{output}.subspan(base, todo);
|
||||
auto dec_sample = [gain,&src](float sample) noexcept -> float
|
||||
{
|
||||
sample += *src * gain;
|
||||
src += 4;
|
||||
return sample;
|
||||
};
|
||||
std::transform(dst.begin(), dst.end(), dst.begin(), dec_sample);
|
||||
};
|
||||
std::for_each(samplesOut.begin(), samplesOut.end(), proc_bufline);
|
||||
|
||||
base += todo;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ struct EchoState final : public EffectState {
|
||||
|
||||
void EchoState::deviceUpdate(const DeviceBase *Device, const BufferStorage*)
|
||||
{
|
||||
const auto frequency = static_cast<float>(Device->Frequency);
|
||||
const auto frequency = static_cast<float>(Device->mSampleRate);
|
||||
|
||||
// Use the next power of 2 for the buffer length, so the tap offsets can be
|
||||
// wrapped using a mask instead of a modulo
|
||||
@@ -100,7 +100,7 @@ void EchoState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
{
|
||||
auto &props = std::get<EchoProps>(*props_);
|
||||
const DeviceBase *device{context->mDevice};
|
||||
const auto frequency = static_cast<float>(device->Frequency);
|
||||
const auto frequency = static_cast<float>(device->mSampleRate);
|
||||
|
||||
mDelayTap[0] = std::max(float2uint(std::round(props.Delay*frequency)), 1u);
|
||||
mDelayTap[1] = float2uint(std::round(props.LRDelay*frequency)) + mDelayTap[0];
|
||||
@@ -160,8 +160,8 @@ void EchoState::process(const size_t samplesToDo, const al::span<const FloatBuff
|
||||
mOffset = offset;
|
||||
|
||||
for(size_t c{0};c < 2;c++)
|
||||
MixSamples({mTempBuffer[c].data(), samplesToDo}, samplesOut, mGains[c].Current.data(),
|
||||
mGains[c].Target.data(), samplesToDo, 0);
|
||||
MixSamples(al::span{mTempBuffer[c]}.first(samplesToDo), samplesOut, mGains[c].Current,
|
||||
mGains[c].Target, samplesToDo, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ void EqualizerState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
{
|
||||
auto &props = std::get<EqualizerProps>(*props_);
|
||||
const DeviceBase *device{context->mDevice};
|
||||
auto frequency = static_cast<float>(device->Frequency);
|
||||
auto frequency = static_cast<float>(device->mSampleRate);
|
||||
|
||||
/* Calculate coefficients for the each type of filter. Note that the shelf
|
||||
* and peaking filters' gain is for the centerpoint of the transition band,
|
||||
@@ -169,18 +169,17 @@ void EqualizerState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
|
||||
void EqualizerState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
|
||||
{
|
||||
const al::span<float> buffer{mSampleBuffer.data(), samplesToDo};
|
||||
const auto buffer = al::span{mSampleBuffer}.first(samplesToDo);
|
||||
auto chan = mChans.begin();
|
||||
for(const auto &input : samplesIn)
|
||||
{
|
||||
const size_t outidx{chan->mTargetChannel};
|
||||
if(outidx != InvalidChannelIndex)
|
||||
if(const size_t outidx{chan->mTargetChannel}; outidx != InvalidChannelIndex)
|
||||
{
|
||||
const al::span<const float> inbuf{input.data(), samplesToDo};
|
||||
const auto inbuf = al::span{input}.first(samplesToDo);
|
||||
DualBiquad{chan->mFilter[0], chan->mFilter[1]}.process(inbuf, buffer);
|
||||
DualBiquad{chan->mFilter[2], chan->mFilter[3]}.process(buffer, buffer);
|
||||
|
||||
MixSamples(buffer, samplesOut[outidx].data(), chan->mCurrentGain, chan->mTargetGain,
|
||||
MixSamples(buffer, samplesOut[outidx], chan->mCurrentGain, chan->mTargetGain,
|
||||
samplesToDo);
|
||||
}
|
||||
++chan;
|
||||
|
||||
@@ -134,7 +134,7 @@ void FshifterState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
auto &props = std::get<FshifterProps>(*props_);
|
||||
const DeviceBase *device{context->mDevice};
|
||||
|
||||
const float step{props.Frequency / static_cast<float>(device->Frequency)};
|
||||
const float step{props.Frequency / static_cast<float>(device->mSampleRate)};
|
||||
mPhaseStep[0] = mPhaseStep[1] = fastf2u(std::min(step, 1.0f) * MixerFracOne);
|
||||
|
||||
switch(props.LeftDirection)
|
||||
@@ -239,8 +239,8 @@ void FshifterState::process(const size_t samplesToDo, const al::span<const Float
|
||||
mPhase[c] = phase_idx;
|
||||
|
||||
/* Now, mix the processed sound data to the output. */
|
||||
MixSamples({mBufferOut.data(), samplesToDo}, samplesOut, mGains[c].Current.data(),
|
||||
mGains[c].Target.data(), std::max(samplesToDo, 512_uz), 0);
|
||||
MixSamples(al::span{mBufferOut}.first(samplesToDo), samplesOut, mGains[c].Current,
|
||||
mGains[c].Target, std::max(samplesToDo, 512_uz), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,10 +122,10 @@ void ModulatorState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
* many iterations per sample.
|
||||
*/
|
||||
const float samplesPerCycle{props.Frequency > 0.0f
|
||||
? static_cast<float>(device->Frequency)/props.Frequency + 0.5f
|
||||
? static_cast<float>(device->mSampleRate)/props.Frequency + 0.5f
|
||||
: 1.0f};
|
||||
const uint range{static_cast<uint>(std::clamp(samplesPerCycle, 1.0f,
|
||||
static_cast<float>(device->Frequency)))};
|
||||
static_cast<float>(device->mSampleRate)))};
|
||||
mIndex = static_cast<uint>(uint64_t{mIndex} * range / mRange);
|
||||
mRange = range;
|
||||
|
||||
@@ -155,7 +155,7 @@ void ModulatorState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
mSampleGen.emplace<SquareFunc>();
|
||||
}
|
||||
|
||||
float f0norm{props.HighPassCutoff / static_cast<float>(device->Frequency)};
|
||||
float f0norm{props.HighPassCutoff / static_cast<float>(device->mSampleRate)};
|
||||
f0norm = std::clamp(f0norm, 1.0f/512.0f, 0.49f);
|
||||
/* Bandwidth value is constant in octaves. */
|
||||
mChans[0].mFilter.setParamsFromBandwidth(BiquadType::HighPass, f0norm, 1.0f, 0.75f);
|
||||
@@ -198,14 +198,13 @@ void ModulatorState::process(const size_t samplesToDo, const al::span<const Floa
|
||||
auto chandata = mChans.begin();
|
||||
for(const auto &input : samplesIn)
|
||||
{
|
||||
const size_t outidx{chandata->mTargetChannel};
|
||||
if(outidx != InvalidChannelIndex)
|
||||
if(const size_t outidx{chandata->mTargetChannel}; outidx != InvalidChannelIndex)
|
||||
{
|
||||
chandata->mFilter.process({input.data(), samplesToDo}, mBuffer);
|
||||
chandata->mFilter.process(al::span{input}.first(samplesToDo), mBuffer);
|
||||
std::transform(mBuffer.cbegin(), mBuffer.cbegin()+samplesToDo, mModSamples.cbegin(),
|
||||
mBuffer.begin(), std::multiplies<>{});
|
||||
|
||||
MixSamples({mBuffer.data(), samplesToDo}, samplesOut[outidx].data(),
|
||||
MixSamples(al::span{mBuffer}.first(samplesToDo), samplesOut[outidx],
|
||||
chandata->mCurrentGain, chandata->mTargetGain, std::min(samplesToDo, 64_uz));
|
||||
}
|
||||
++chandata;
|
||||
|
||||
@@ -306,8 +306,8 @@ void PshifterState::process(const size_t samplesToDo,
|
||||
}
|
||||
|
||||
/* Now, mix the processed sound data to the output. */
|
||||
MixSamples({mBufferOut.data(), samplesToDo}, samplesOut, mCurrentGains.data(),
|
||||
mTargetGains.data(), std::max(samplesToDo, 512_uz), 0);
|
||||
MixSamples(al::span{mBufferOut}.first(samplesToDo), samplesOut, mCurrentGains, mTargetGains,
|
||||
std::max(samplesToDo, 512_uz), 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -249,7 +249,7 @@ void VmorpherState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
{
|
||||
auto &props = std::get<VmorpherProps>(*props_);
|
||||
const DeviceBase *device{context->mDevice};
|
||||
const float frequency{static_cast<float>(device->Frequency)};
|
||||
const float frequency{static_cast<float>(device->mSampleRate)};
|
||||
const float step{props.Rate / frequency};
|
||||
mStep = fastf2u(std::clamp(step*WaveformFracOne, 0.0f, WaveformFracOne-1.0f));
|
||||
|
||||
@@ -286,6 +286,8 @@ void VmorpherState::update(const ContextBase *context, const EffectSlot *slot,
|
||||
|
||||
void VmorpherState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
|
||||
{
|
||||
alignas(16) std::array<float,MaxUpdateSamples> blended{};
|
||||
|
||||
/* Following the EFX specification for a conformant implementation which describes
|
||||
* the effect as a pair of 4-band formant filters blended together using an LFO.
|
||||
*/
|
||||
@@ -324,12 +326,11 @@ void VmorpherState::process(const size_t samplesToDo, const al::span<const Float
|
||||
vowelB[2].process(&input[base], mSampleBufferB.data(), td);
|
||||
vowelB[3].process(&input[base], mSampleBufferB.data(), td);
|
||||
|
||||
alignas(16) std::array<float,MaxUpdateSamples> blended;
|
||||
for(size_t i{0u};i < td;i++)
|
||||
blended[i] = lerpf(mSampleBufferA[i], mSampleBufferB[i], mLfo[i]);
|
||||
|
||||
/* Now, mix the processed sound data to the output. */
|
||||
MixSamples({blended.data(), td}, samplesOut[outidx].data()+base,
|
||||
MixSamples(al::span{blended}.first(td), al::span{samplesOut[outidx]}.subspan(base),
|
||||
chandata->mCurrentGain, chandata->mTargetGain, samplesToDo-base);
|
||||
++chandata;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user