mirror of
https://github.com/love2d/megasource.git
synced 2026-08-18 19:54:37 +02:00
update OpenAL-Soft to 1.24.3.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user