Allocate the effect slot wet buffer dynamically

This commit is contained in:
Chris Robinson 2019-02-20 21:01:08 -08:00
parent 77ba61ecb3
commit c43381d811
4 changed files with 38 additions and 37 deletions

View File

@ -2068,8 +2068,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if(context->DefaultSlot)
{
ALeffectslot *slot = context->DefaultSlot.get();
EffectState *state = slot->Effect.State;
aluInitEffectPanning(slot);
EffectState *state{slot->Effect.State};
state->mOutBuffer = device->Dry.Buffer;
state->mOutChannels = device->Dry.NumChannels;
if(state->deviceUpdate(device) == AL_FALSE)
@ -2082,8 +2083,10 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
std::unique_lock<std::mutex> slotlock{context->EffectSlotLock};
for(auto &slot : context->EffectSlotList)
{
EffectState *state = slot->Effect.State;
if(!slot) continue;
aluInitEffectPanning(slot.get());
EffectState *state{slot->Effect.State};
state->mOutBuffer = device->Dry.Buffer;
state->mOutChannels = device->Dry.NumChannels;
if(state->deviceUpdate(device) == AL_FALSE)

View File

@ -446,8 +446,8 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force)
auto iter = std::copy(std::begin(target->ChanMap), std::end(target->ChanMap),
std::begin(params.AmbiMap));
std::fill(iter, std::end(params.AmbiMap), BFChannelConfig{});
params.Buffer = target->WetBuffer;
params.NumChannels = target->NumChannels;
params.Buffer = &reinterpret_cast<ALfloat(&)[BUFFERSIZE]>(target->WetBuffer[0]);
params.NumChannels = target->WetBuffer.size();
output = EffectTarget{&params, &params, nullptr};
}
@ -651,7 +651,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
for(ALsizei i{0};i < NumSends;i++)
{
if(const ALeffectslot *Slot{SendSlots[i]})
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs,
WetGain[i]*scale0, voice->Send[i].Params[0].Gains.Target);
}
}
@ -714,7 +714,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
{
if(const ALeffectslot *Slot{SendSlots[i]})
for(ALsizei c{0};c < num_channels;c++)
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, matrix[c].data(),
ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), matrix[c].data(),
WetGain[i], voice->Send[i].Params[c].Gains.Target
);
}
@ -745,7 +745,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
for(ALsizei i{0};i < NumSends;i++)
{
if(const ALeffectslot *Slot{SendSlots[i]})
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs,
WetGain[i], voice->Send[i].Params[c].Gains.Target
);
}
@ -790,7 +790,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
{
/* Skip LFE */
if(chans[c].channel != LFE)
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs,
WetGain[i]*downmix_gain, voice->Send[i].Params[c].Gains.Target
);
}
@ -824,7 +824,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
for(ALsizei i{0};i < NumSends;i++)
{
if(const ALeffectslot *Slot{SendSlots[i]})
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs,
WetGain[i], voice->Send[i].Params[c].Gains.Target
);
}
@ -890,7 +890,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
{
/* Skip LFE */
if(chans[c].channel != LFE)
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(), coeffs,
WetGain[i]*downmix_gain, voice->Send[i].Params[c].Gains.Target
);
}
@ -942,7 +942,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
for(ALsizei i{0};i < NumSends;i++)
{
if(const ALeffectslot *Slot{SendSlots[i]})
ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels,
ComputePanningGainsBF(Slot->ChanMap, Slot->WetBuffer.size(),
coeffs, WetGain[i], voice->Send[i].Params[c].Gains.Target
);
}
@ -1016,8 +1016,8 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons
}
else
{
voice->Send[i].Buffer = SendSlots[i]->WetBuffer;
voice->Send[i].Channels = SendSlots[i]->NumChannels;
voice->Send[i].Buffer = &reinterpret_cast<ALfloat(&)[BUFFERSIZE]>(SendSlots[i]->WetBuffer[0]);
voice->Send[i].Channels = SendSlots[i]->WetBuffer.size();
}
}
@ -1124,8 +1124,8 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A
}
else
{
voice->Send[i].Buffer = SendSlots[i]->WetBuffer;
voice->Send[i].Channels = SendSlots[i]->NumChannels;
voice->Send[i].Buffer = &reinterpret_cast<ALfloat(&)[BUFFERSIZE]>(SendSlots[i]->WetBuffer[0]);
voice->Send[i].Channels = SendSlots[i]->WetBuffer.size();
}
}
@ -1465,10 +1465,8 @@ void ProcessContext(ALCcontext *ctx, const ALsizei SamplesToDo)
std::for_each(auxslots->begin(), auxslots->end(),
[SamplesToDo](ALeffectslot *slot) -> void
{
std::for_each(slot->WetBuffer, slot->WetBuffer+slot->NumChannels,
[SamplesToDo](ALfloat *buffer) -> void
{ std::fill_n(buffer, SamplesToDo, 0.0f); }
);
for(auto &buffer : slot->WetBuffer)
std::fill_n(buffer.begin(), SamplesToDo, 0.0f);
}
);
@ -1529,8 +1527,9 @@ void ProcessContext(ALCcontext *ctx, const ALsizei SamplesToDo)
[SamplesToDo](const ALeffectslot *slot) -> void
{
EffectState *state{slot->Params.mEffectState};
state->process(SamplesToDo, slot->WetBuffer, state->mOutBuffer,
state->mOutChannels);
state->process(SamplesToDo,
&reinterpret_cast<const ALfloat(&)[BUFFERSIZE]>(slot->WetBuffer[0]),
state->mOutBuffer, state->mOutChannels);
}
);
}

View File

@ -861,7 +861,7 @@ void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, con
}
void ComputePanGains(const ALeffectslot *slot, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS])
{ ComputePanningGainsBF(slot->ChanMap, slot->NumChannels, coeffs, ingain, gains); }
{ ComputePanningGainsBF(slot->ChanMap, slot->WetBuffer.size(), coeffs, ingain, gains); }
void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appreq, HrtfRequestMode hrtf_userreq)
@ -1121,10 +1121,12 @@ no_hrtf:
void aluInitEffectPanning(ALeffectslot *slot)
{
const size_t count{countof(slot->ChanMap)};
const size_t count{4u};
slot->WetBuffer.resize(count);
slot->WetBuffer.shrink_to_fit();
auto acnmap_end = AmbiIndex::From3D.begin() + count;
std::transform(AmbiIndex::From3D.begin(), acnmap_end, std::begin(slot->ChanMap),
[](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; }
);
slot->NumChannels = static_cast<ALsizei>(count);
auto iter = std::transform(AmbiIndex::From3D.begin(), acnmap_end, std::begin(slot->ChanMap),
[](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; });
std::fill(iter, std::end(slot->ChanMap), BFChannelConfig{});
}

View File

@ -1,8 +1,11 @@
#ifndef _AL_AUXEFFECTSLOT_H_
#define _AL_AUXEFFECTSLOT_H_
#include <array>
#include "alMain.h"
#include "alEffect.h"
#include "ambidefs.h"
#include "almalloc.h"
#include "atomic.h"
@ -99,19 +102,13 @@ struct ALeffectslot {
/* Self ID */
ALuint id{};
ALsizei NumChannels{};
BFChannelConfig ChanMap[MAX_EFFECT_CHANNELS];
/* Wet buffer configuration is ACN channel order with N3D scaling:
* * Channel 0 is the unattenuated mono signal.
* * Channel 1 is OpenAL -X * sqrt(3)
* * Channel 2 is OpenAL Y * sqrt(3)
* * Channel 3 is OpenAL -Z * sqrt(3)
/* Wet buffer configuration is ACN channel order with N3D scaling.
* Consequently, effects that only want to work with mono input can use
* channel 0 by itself. Effects that want multichannel can process the
* ambisonics signal and make a B-Format source pan for first-order device
* output (FOAOut).
* ambisonics signal and make a B-Format source pan.
*/
alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
al::vector<std::array<ALfloat,BUFFERSIZE>,16> WetBuffer;
BFChannelConfig ChanMap[MAX_AMBI_CHANNELS];
ALeffectslot() { PropsClean.test_and_set(std::memory_order_relaxed); }
ALeffectslot(const ALeffectslot&) = delete;