Use a span for MixParams

This commit is contained in:
Chris Robinson 2019-07-04 15:02:12 -07:00
parent 729ffe02d6
commit 3fe5ef272f
16 changed files with 46 additions and 49 deletions

View File

@ -1903,8 +1903,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->ChannelDelay.clear();
device->Dry.AmbiMap.fill(BFChannelConfig{});
device->Dry.Buffer = nullptr;
device->Dry.NumChannels = 0;
device->Dry.Buffer = {};
std::fill(std::begin(device->NumChannelsPerOrder), std::end(device->NumChannelsPerOrder), 0u);
device->RealOut.ChannelIndex.fill(-1);
device->RealOut.Buffer = {};
@ -2158,7 +2157,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
aluInitEffectPanning(slot, device);
EffectState *state{slot->Effect.State};
state->mOutTarget = {device->Dry.Buffer, device->Dry.NumChannels};
state->mOutTarget = device->Dry.Buffer;
if(state->deviceUpdate(device) == AL_FALSE)
update_failed = AL_TRUE;
else
@ -2180,7 +2179,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
aluInitEffectPanning(slot, device);
EffectState *state{slot->Effect.State};
state->mOutTarget = {device->Dry.Buffer, device->Dry.NumChannels};
state->mOutTarget = device->Dry.Buffer;
if(state->deviceUpdate(device) == AL_FALSE)
update_failed = AL_TRUE;
else

View File

@ -140,14 +140,14 @@ void ProcessHrtf(ALCdevice *device, const ALsizei SamplesToDo)
ASSUME(lidx >= 0 && ridx >= 0);
DirectHrtfState *state{device->mHrtfState.get()};
MixDirectHrtf(device->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx],
{device->Dry.Buffer, device->Dry.NumChannels}, device->HrtfAccumData, state, SamplesToDo);
MixDirectHrtf(device->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx], device->Dry.Buffer,
device->HrtfAccumData, state, SamplesToDo);
}
void ProcessAmbiDec(ALCdevice *device, const ALsizei SamplesToDo)
{
BFormatDec *ambidec{device->AmbiDecoder.get()};
ambidec->process(device->RealOut.Buffer, device->Dry.Buffer, SamplesToDo);
ambidec->process(device->RealOut.Buffer, device->Dry.Buffer.data(), SamplesToDo);
}
void ProcessUhj(ALCdevice *device, const ALsizei SamplesToDo)
@ -160,14 +160,14 @@ void ProcessUhj(ALCdevice *device, const ALsizei SamplesToDo)
/* Encode to stereo-compatible 2-channel UHJ output. */
Uhj2Encoder *uhj2enc{device->Uhj_Encoder.get()};
uhj2enc->encode(device->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx],
device->Dry.Buffer, SamplesToDo);
device->Dry.Buffer.data(), SamplesToDo);
}
void ProcessBs2b(ALCdevice *device, const ALsizei SamplesToDo)
{
/* First, decode the ambisonic mix to the "real" output. */
BFormatDec *ambidec{device->AmbiDecoder.get()};
ambidec->process(device->RealOut.Buffer, device->Dry.Buffer, SamplesToDo);
ambidec->process(device->RealOut.Buffer, device->Dry.Buffer.data(), SamplesToDo);
/* BS2B is stereo output only. */
const int lidx{device->RealOut.ChannelIndex[FrontLeft]};
@ -811,7 +811,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo
/* Special-case LFE */
if(chans[c].channel == LFE)
{
if(Device->Dry.Buffer == Device->RealOut.Buffer.data())
if(Device->Dry.Buffer.data() == Device->RealOut.Buffer.data())
{
int idx = GetChannelIdxByName(Device->RealOut, chans[c].channel);
if(idx != -1) voice->mChans[c].mDryParams.Gains.Target[idx] = DryGain;
@ -858,7 +858,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo
/* Special-case LFE */
if(chans[c].channel == LFE)
{
if(Device->Dry.Buffer == Device->RealOut.Buffer.data())
if(Device->Dry.Buffer.data() == Device->RealOut.Buffer.data())
{
int idx = GetChannelIdxByName(Device->RealOut, chans[c].channel);
if(idx != -1) voice->mChans[c].mDryParams.Gains.Target[idx] = DryGain;
@ -936,7 +936,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons
const ALCdevice *Device{ALContext->Device};
ALeffectslot *SendSlots[MAX_SENDS];
voice->mDirect.Buffer = {Device->Dry.Buffer, static_cast<size_t>(Device->Dry.NumChannels)};
voice->mDirect.Buffer = Device->Dry.Buffer;
for(ALsizei i{0};i < Device->NumAuxSends;i++)
{
SendSlots[i] = props->Send[i].Slot;
@ -948,9 +948,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons
voice->mSend[i].Buffer = {};
}
else
{
voice->mSend[i].Buffer = {SendSlots[i]->Wet.Buffer, SendSlots[i]->Wet.NumChannels};
}
voice->mSend[i].Buffer = SendSlots[i]->Wet.Buffer;
}
/* Calculate the stepping value */
@ -994,7 +992,7 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A
const ALlistener &Listener = ALContext->Listener;
/* Set mixing buffers and get send parameters. */
voice->mDirect.Buffer = {Device->Dry.Buffer, Device->Dry.NumChannels};
voice->mDirect.Buffer = Device->Dry.Buffer;
ALeffectslot *SendSlots[MAX_SENDS];
ALfloat RoomRolloff[MAX_SENDS];
ALfloat DecayDistance[MAX_SENDS];
@ -1051,7 +1049,7 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A
if(!SendSlots[i])
voice->mSend[i].Buffer = {};
else
voice->mSend[i].Buffer = {SendSlots[i]->Wet.Buffer, SendSlots[i]->Wet.NumChannels};
voice->mSend[i].Buffer = SendSlots[i]->Wet.Buffer;
}
/* Transform source to listener space (convert to head relative) */
@ -1424,8 +1422,8 @@ void ProcessContext(ALCcontext *ctx, const ALsizei SamplesToDo)
[SamplesToDo](const ALeffectslot *slot) -> void
{
EffectState *state{slot->Params.mEffectState};
state->process(SamplesToDo, slot->Wet.Buffer, slot->Wet.NumChannels,
state->mOutTarget);
state->process(SamplesToDo, slot->Wet.Buffer.data(),
static_cast<ALsizei>(slot->Wet.Buffer.size()), state->mOutTarget);
}
);
}

View File

@ -119,8 +119,8 @@ void ALautowahState::update(const ALCcontext *context, const ALeffectslot *slot,
mFreqMinNorm = MIN_FREQ / device->Frequency;
mBandwidthNorm = (MAX_FREQ-MIN_FREQ) / device->Frequency;
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
for(ALuint i{0u};i < slot->Wet.NumChannels;++i)
mOutTarget = target.Main->Buffer;
for(size_t i{0u};i < slot->Wet.Buffer.size();++i)
{
auto coeffs = GetAmbiIdentityRow(i);
ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, mChans[i].TargetGains);

View File

@ -159,7 +159,7 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co
CalcDirectionCoeffs({-1.0f, 0.0f, 0.0f}, 0.0f, coeffs[0]);
CalcDirectionCoeffs({ 1.0f, 0.0f, 0.0f}, 0.0f, coeffs[1]);
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
mOutTarget = target.Main->Buffer;
ComputePanGains(target.Main, coeffs[0], Slot->Params.Gain, mGains[0].Target);
ComputePanGains(target.Main, coeffs[1], Slot->Params.Gain, mGains[1].Target);

View File

@ -78,8 +78,8 @@ void CompressorState::update(const ALCcontext* UNUSED(context), const ALeffectsl
{
mEnabled = props->Compressor.OnOff;
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
for(ALuint i{0u};i < slot->Wet.NumChannels;++i)
mOutTarget = target.Main->Buffer;
for(size_t i{0u};i < slot->Wet.Buffer.size();++i)
{
auto coeffs = GetAmbiIdentityRow(i);
ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, mGain[i]);

View File

@ -81,7 +81,7 @@ void DedicatedState::update(const ALCcontext* UNUSED(context), const ALeffectslo
ALfloat coeffs[MAX_AMBI_CHANNELS];
CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs);
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
mOutTarget = target.Main->Buffer;
ComputePanGains(target.Main, coeffs, Gain, mTargetGains);
}
}

View File

@ -90,7 +90,7 @@ void DistortionState::update(const ALCcontext *context, const ALeffectslot *slot
ALfloat coeffs[MAX_AMBI_CHANNELS];
CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs);
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
mOutTarget = target.Main->Buffer;
ComputePanGains(target.Main, coeffs, slot->Params.Gain*props->Distortion.Gain, mGain);
}

View File

@ -113,7 +113,7 @@ void EchoState::update(const ALCcontext *context, const ALeffectslot *slot, cons
CalcAngleCoeffs(-angle, 0.0f, 0.0f, coeffs[0]);
CalcAngleCoeffs( angle, 0.0f, 0.0f, coeffs[1]);
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
mOutTarget = target.Main->Buffer;
ComputePanGains(target.Main, coeffs[0], slot->Params.Gain, mGains[0].Target);
ComputePanGains(target.Main, coeffs[1], slot->Params.Gain, mGains[1].Target);
}

View File

@ -141,7 +141,7 @@ void EqualizerState::update(const ALCcontext *context, const ALeffectslot *slot,
BiquadFilter::rcpQFromSlope(gain, 0.75f));
/* Copy the filter coefficients for the other input channels. */
for(ALuint i{1u};i < slot->Wet.NumChannels;++i)
for(size_t i{1u};i < slot->Wet.Buffer.size();++i)
{
mChans[i].filter[0].copyParamsFrom(mChans[0].filter[0]);
mChans[i].filter[1].copyParamsFrom(mChans[0].filter[1]);
@ -149,8 +149,8 @@ void EqualizerState::update(const ALCcontext *context, const ALeffectslot *slot,
mChans[i].filter[3].copyParamsFrom(mChans[0].filter[3]);
}
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
for(ALuint i{0u};i < slot->Wet.NumChannels;++i)
mOutTarget = target.Main->Buffer;
for(size_t i{0u};i < slot->Wet.Buffer.size();++i)
{
auto coeffs = GetAmbiIdentityRow(i);
ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, mChans[i].TargetGains);

View File

@ -133,7 +133,7 @@ void FshifterState::update(const ALCcontext *context, const ALeffectslot *slot,
ALfloat coeffs[MAX_AMBI_CHANNELS];
CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs);
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
mOutTarget = target.Main->Buffer;
ComputePanGains(target.Main, coeffs, slot->Params.Gain, mTargetGains);
}

View File

@ -129,11 +129,11 @@ void ModulatorState::update(const ALCcontext *context, const ALeffectslot *slot,
/* Bandwidth value is constant in octaves. */
mChans[0].Filter.setParams(BiquadType::HighPass, 1.0f, f0norm,
BiquadFilter::rcpQFromBandwidth(f0norm, 0.75f));
for(ALuint i{1u};i < slot->Wet.NumChannels;++i)
for(size_t i{1u};i < slot->Wet.Buffer.size();++i)
mChans[i].Filter.copyParamsFrom(mChans[0].Filter);
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
for(ALuint i{0u};i < slot->Wet.NumChannels;++i)
mOutTarget = target.Main->Buffer;
for(size_t i{0u};i < slot->Wet.Buffer.size();++i)
{
auto coeffs = GetAmbiIdentityRow(i);
ComputePanGains(target.Main, coeffs.data(), slot->Params.Gain, mChans[i].TargetGains);

View File

@ -192,7 +192,7 @@ void PshifterState::update(const ALCcontext* UNUSED(context), const ALeffectslot
ALfloat coeffs[MAX_AMBI_CHANNELS];
CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs);
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
mOutTarget = target.Main->Buffer;
ComputePanGains(target.Main, coeffs, slot->Params.Gain, mTargetGains);
}

View File

@ -889,7 +889,7 @@ void ReverbState::update3DPanning(const ALfloat *ReflectionsPan, const ALfloat *
const alu::Matrix earlymat{GetTransformFromVector(ReflectionsPan)};
const alu::Matrix latemat{GetTransformFromVector(LateReverbPan)};
mOutTarget = {target.Main->Buffer, target.Main->NumChannels};
mOutTarget = target.Main->Buffer;
for(ALsizei i{0};i < NUM_LINES;i++)
{
const ALfloat coeffs[MAX_AMBI_CHANNELS]{earlymat[0][i], earlymat[1][i], earlymat[2][i],

View File

@ -116,13 +116,17 @@ void AllocChannels(ALCdevice *device, const ALuint main_chans, const ALuint real
TRACE("Allocating %u channels, %zu bytes\n", num_chans,
num_chans*sizeof(device->MixBuffer[0]));
device->MixBuffer.resize(num_chans);
al::span<FloatBufferLine> buffer{device->MixBuffer.data(), device->MixBuffer.size()};
device->Dry.Buffer = device->MixBuffer.data();
device->Dry.NumChannels = main_chans;
device->Dry.Buffer = buffer.first(main_chans);
buffer = buffer.subspan(main_chans);
if(real_chans != 0)
device->RealOut.Buffer = {device->Dry.Buffer+device->Dry.NumChannels, real_chans};
{
device->RealOut.Buffer = buffer.first(real_chans);
buffer = buffer.subspan(real_chans);
}
else
device->RealOut.Buffer = {device->Dry.Buffer, device->Dry.NumChannels};
device->RealOut.Buffer = device->Dry.Buffer;
}
@ -850,8 +854,7 @@ void aluInitEffectPanning(ALeffectslot *slot, ALCdevice *device)
{ return BFChannelConfig{1.0f, acn}; }
);
std::fill(iter, slot->Wet.AmbiMap.end(), BFChannelConfig{});
slot->Wet.Buffer = slot->MixBuffer.data();
slot->Wet.NumChannels = static_cast<ALuint>(count);
slot->Wet.Buffer = {slot->MixBuffer.data(), slot->MixBuffer.size()};
}
@ -950,10 +953,8 @@ void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALf
void ComputePanGains(const MixParams *mix, const ALfloat *RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS])
{
auto ambimap = mix->AmbiMap.cbegin();
const ALuint numchans{mix->NumChannels};
ASSUME(numchans > 0);
auto iter = std::transform(ambimap, ambimap+numchans, std::begin(gains),
auto iter = std::transform(ambimap, ambimap+mix->Buffer.size(), std::begin(gains),
[coeffs,ingain](const BFChannelConfig &chanmap) noexcept -> ALfloat
{
ASSUME(chanmap.Index >= 0);

View File

@ -308,10 +308,9 @@ using FloatBufferLine = std::array<float,BUFFERSIZE>;
struct MixParams {
/* Coefficient channel mapping for mixing to the buffer. */
std::array<BFChannelConfig,MAX_OUTPUT_CHANNELS> AmbiMap;
std::array<BFChannelConfig,MAX_OUTPUT_CHANNELS> AmbiMap{};
FloatBufferLine *Buffer{nullptr};
ALuint NumChannels{0u};
al::span<FloatBufferLine> Buffer;
};
struct RealMixParams {

View File

@ -643,7 +643,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
FPUCtl mixer_mode{};
ALCdevice *Device{Context->Device};
std::unique_lock<std::mutex> statelock{Device->StateLock};
State->mOutTarget = {Device->Dry.Buffer, Device->Dry.NumChannels};
State->mOutTarget = Device->Dry.Buffer;
if(State->deviceUpdate(Device) == AL_FALSE)
{
statelock.unlock();