Update OpenAL-soft to 1.23.1-bc7cb17.

This commit is contained in:
Miku AuahDark
2024-03-20 11:06:03 +08:00
parent 4a512be715
commit 73a6fc9196
294 changed files with 44342 additions and 40077 deletions
+74 -61
View File
@@ -22,24 +22,24 @@
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <iterator>
#include <utility>
#include <variant>
#include "alc/effects/base.h"
#include "almalloc.h"
#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
#include "core/ambidefs.h"
#include "core/bufferline.h"
#include "core/context.h"
#include "core/devformat.h"
#include "core/device.h"
#include "core/effects/base.h"
#include "core/effectslot.h"
#include "core/mixer.h"
#include "intrusive_ptr.h"
struct BufferStorage;
namespace {
@@ -50,45 +50,47 @@ constexpr float QFactor{5.0f};
struct AutowahState final : public EffectState {
/* Effect parameters */
float mAttackRate;
float mReleaseRate;
float mResonanceGain;
float mPeakGain;
float mFreqMinNorm;
float mBandwidthNorm;
float mEnvDelay;
float mAttackRate{};
float mReleaseRate{};
float mResonanceGain{};
float mPeakGain{};
float mFreqMinNorm{};
float mBandwidthNorm{};
float mEnvDelay{};
/* Filter components derived from the envelope. */
struct {
float cos_w0;
float alpha;
} mEnv[BufferLineSize];
struct FilterParam {
float cos_w0{};
float alpha{};
};
std::array<FilterParam,BufferLineSize> mEnv;
struct {
/* Effect filters' history. */
struct {
float z1, z2;
} Filter;
struct ChannelData {
uint mTargetChannel{InvalidChannelIndex};
struct FilterHistory {
float z1{}, z2{};
};
FilterHistory mFilter;
/* Effect gains for each output channel */
float CurrentGains[MAX_OUTPUT_CHANNELS];
float TargetGains[MAX_OUTPUT_CHANNELS];
} mChans[MaxAmbiChannels];
float mCurrentGain{};
float mTargetGain{};
};
std::array<ChannelData,MaxAmbiChannels> mChans;
/* Effects buffers */
alignas(16) float mBufferOut[BufferLineSize];
alignas(16) FloatBufferLine mBufferOut{};
void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override;
void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override;
void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props,
const EffectTarget target) override;
void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn,
const al::span<FloatBufferLine> samplesOut) override;
DEF_NEWDEL(AutowahState)
};
void AutowahState::deviceUpdate(const DeviceBase*, const Buffer&)
void AutowahState::deviceUpdate(const DeviceBase*, const BufferStorage*)
{
/* (Re-)initializing parameters and clear the buffers. */
@@ -108,32 +110,37 @@ void AutowahState::deviceUpdate(const DeviceBase*, const Buffer&)
for(auto &chan : mChans)
{
std::fill(std::begin(chan.CurrentGains), std::end(chan.CurrentGains), 0.0f);
chan.Filter.z1 = 0.0f;
chan.Filter.z2 = 0.0f;
chan.mTargetChannel = InvalidChannelIndex;
chan.mFilter.z1 = 0.0f;
chan.mFilter.z2 = 0.0f;
chan.mCurrentGain = 0.0f;
}
}
void AutowahState::update(const ContextBase *context, const EffectSlot *slot,
const EffectProps *props, const EffectTarget target)
const EffectProps *props_, const EffectTarget target)
{
auto &props = std::get<AutowahProps>(*props_);
const DeviceBase *device{context->mDevice};
const auto frequency = static_cast<float>(device->Frequency);
const float ReleaseTime{clampf(props->Autowah.ReleaseTime, 0.001f, 1.0f)};
const float ReleaseTime{std::clamp(props.ReleaseTime, 0.001f, 1.0f)};
mAttackRate = std::exp(-1.0f / (props->Autowah.AttackTime*frequency));
mAttackRate = std::exp(-1.0f / (props.AttackTime*frequency));
mReleaseRate = std::exp(-1.0f / (ReleaseTime*frequency));
/* 0-20dB Resonance Peak gain */
mResonanceGain = std::sqrt(std::log10(props->Autowah.Resonance)*10.0f / 3.0f);
mPeakGain = 1.0f - std::log10(props->Autowah.PeakGain / GainScale);
mResonanceGain = std::sqrt(std::log10(props.Resonance)*10.0f / 3.0f);
mPeakGain = 1.0f - std::log10(props.PeakGain / GainScale);
mFreqMinNorm = MinFreq / frequency;
mBandwidthNorm = (MaxFreq-MinFreq) / frequency;
mOutTarget = target.Main->Buffer;
auto set_gains = [slot,target](auto &chan, al::span<const float,MaxAmbiChannels> coeffs)
{ ComputePanGains(target.Main, coeffs.data(), slot->Gain, chan.TargetGains); };
SetAmbiPanIdentity(std::begin(mChans), slot->Wet.Buffer.size(), set_gains);
auto set_channel = [this](size_t idx, uint outchan, float outgain)
{
mChans[idx].mTargetChannel = outchan;
mChans[idx].mTargetGain = outgain;
};
target.Main->setAmbiMixParams(slot->Wet, slot->Gain, set_channel);
}
void AutowahState::process(const size_t samplesToDo,
@@ -149,60 +156,66 @@ void AutowahState::process(const size_t samplesToDo,
float env_delay{mEnvDelay};
for(size_t i{0u};i < samplesToDo;i++)
{
float w0, sample, a;
/* Envelope follower described on the book: Audio Effects, Theory,
* Implementation and Application.
*/
sample = peak_gain * std::fabs(samplesIn[0][i]);
a = (sample > env_delay) ? attack_rate : release_rate;
const float sample{peak_gain * std::fabs(samplesIn[0][i])};
const float a{(sample > env_delay) ? attack_rate : release_rate};
env_delay = lerpf(sample, env_delay, a);
/* Calculate the cos and alpha components for this sample's filter. */
w0 = minf((bandwidth*env_delay + freq_min), 0.46f) * (al::numbers::pi_v<float>*2.0f);
const float w0{std::min(bandwidth*env_delay + freq_min, 0.46f) *
(al::numbers::pi_v<float>*2.0f)};
mEnv[i].cos_w0 = std::cos(w0);
mEnv[i].alpha = std::sin(w0)/(2.0f * QFactor);
}
mEnvDelay = env_delay;
auto chandata = std::addressof(mChans[0]);
auto chandata = mChans.begin();
for(const auto &insamples : samplesIn)
{
const size_t outidx{chandata->mTargetChannel};
if(outidx == InvalidChannelIndex)
{
++chandata;
continue;
}
/* This effectively inlines BiquadFilter_setParams for a peaking
* filter and BiquadFilter_processC. The alpha and cosine components
* for the filter coefficients were previously calculated with the
* envelope. Because the filter changes for each sample, the
* coefficients are transient and don't need to be held.
*/
float z1{chandata->Filter.z1};
float z2{chandata->Filter.z2};
float z1{chandata->mFilter.z1};
float z2{chandata->mFilter.z2};
for(size_t i{0u};i < samplesToDo;i++)
{
const float alpha{mEnv[i].alpha};
const float cos_w0{mEnv[i].cos_w0};
float input, output;
float a[3], b[3];
b[0] = 1.0f + alpha*res_gain;
b[1] = -2.0f * cos_w0;
b[2] = 1.0f - alpha*res_gain;
a[0] = 1.0f + alpha/res_gain;
a[1] = -2.0f * cos_w0;
a[2] = 1.0f - alpha/res_gain;
const std::array b{
1.0f + alpha*res_gain,
-2.0f * cos_w0,
1.0f - alpha*res_gain};
const std::array a{
1.0f + alpha/res_gain,
-2.0f * cos_w0,
1.0f - alpha/res_gain};
input = insamples[i];
output = input*(b[0]/a[0]) + z1;
const float input{insamples[i]};
const float output{input*(b[0]/a[0]) + z1};
z1 = input*(b[1]/a[0]) - output*(a[1]/a[0]) + z2;
z2 = input*(b[2]/a[0]) - output*(a[2]/a[0]);
mBufferOut[i] = output;
}
chandata->Filter.z1 = z1;
chandata->Filter.z2 = z2;
chandata->mFilter.z1 = z1;
chandata->mFilter.z2 = z2;
/* Now, mix the processed sound data to the output. */
MixSamples({mBufferOut, samplesToDo}, samplesOut, chandata->CurrentGains,
chandata->TargetGains, samplesToDo, 0);
MixSamples({mBufferOut.data(), samplesToDo}, samplesOut[outidx].data(),
chandata->mCurrentGain, chandata->mTargetGain, samplesToDo);
++chandata;
}
}