diff options
author | Chris Robinson <[email protected]> | 2019-05-29 23:06:24 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-05-29 23:06:24 -0700 |
commit | dbdf516dbf628c65d4115a00c78f5679308a0573 (patch) | |
tree | d0dbef5d52259e47385b8a98b1d04220475e6e12 | |
parent | 2909f263fd1a2e7122b0345c6d11209084815fd1 (diff) |
Use a span for the voice's buffer references
-rw-r--r-- | Alc/alu.cpp | 32 | ||||
-rw-r--r-- | Alc/mixvoice.cpp | 18 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 6 |
3 files changed, 23 insertions, 33 deletions
diff --git a/Alc/alu.cpp b/Alc/alu.cpp index 2f172b99..befddd9a 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -641,7 +641,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo voice->mDirect.Params[0].NFCtrlFilter.adjust(0.0f); voice->mDirect.ChannelsPerOrder[0] = 1; - voice->mDirect.ChannelsPerOrder[1] = mini(voice->mDirect.Channels-1, 3); + voice->mDirect.ChannelsPerOrder[1] = minz(voice->mDirect.Buffer.size()-1, 3); std::fill(std::begin(voice->mDirect.ChannelsPerOrder)+2, std::end(voice->mDirect.ChannelsPerOrder), 0); voice->mFlags |= VOICE_HAS_NFC; @@ -697,8 +697,8 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo /* Direct source channels always play local. Skip the virtual channels * and write inputs to the matching real outputs. */ - voice->mDirect.Buffer = Device->RealOut.Buffer; - voice->mDirect.Channels = Device->RealOut.NumChannels; + voice->mDirect.Buffer = {Device->RealOut.Buffer, + static_cast<size_t>(Device->RealOut.NumChannels)}; for(ALsizei c{0};c < num_channels;c++) { @@ -727,8 +727,8 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo /* Full HRTF rendering. Skip the virtual channels and render to the * real outputs. */ - voice->mDirect.Buffer = Device->RealOut.Buffer; - voice->mDirect.Channels = Device->RealOut.NumChannels; + voice->mDirect.Buffer = {Device->RealOut.Buffer, + static_cast<size_t>(Device->RealOut.NumChannels)}; if(Distance > std::numeric_limits<float>::epsilon()) { @@ -970,8 +970,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons const ALCdevice *Device{ALContext->Device}; ALeffectslot *SendSlots[MAX_SENDS]; - voice->mDirect.Buffer = Device->Dry.Buffer; - voice->mDirect.Channels = Device->Dry.NumChannels; + voice->mDirect.Buffer = {Device->Dry.Buffer, static_cast<size_t>(Device->Dry.NumChannels)}; for(ALsizei i{0};i < Device->NumAuxSends;i++) { SendSlots[i] = props->Send[i].Slot; @@ -980,13 +979,12 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons if(!SendSlots[i] || SendSlots[i]->Params.EffectType == AL_EFFECT_NULL) { SendSlots[i] = nullptr; - voice->mSend[i].Buffer = nullptr; - voice->mSend[i].Channels = 0; + voice->mSend[i].Buffer = {}; } else { - voice->mSend[i].Buffer = SendSlots[i]->Wet.Buffer; - voice->mSend[i].Channels = SendSlots[i]->Wet.NumChannels; + voice->mSend[i].Buffer = {SendSlots[i]->Wet.Buffer, + static_cast<size_t>(SendSlots[i]->Wet.NumChannels)}; } } @@ -1031,8 +1029,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; - voice->mDirect.Channels = Device->Dry.NumChannels; + voice->mDirect.Buffer = {Device->Dry.Buffer, static_cast<size_t>(Device->Dry.NumChannels)}; ALeffectslot *SendSlots[MAX_SENDS]; ALfloat RoomRolloff[MAX_SENDS]; ALfloat DecayDistance[MAX_SENDS]; @@ -1087,14 +1084,11 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A } if(!SendSlots[i]) - { - voice->mSend[i].Buffer = nullptr; - voice->mSend[i].Channels = 0; - } + voice->mSend[i].Buffer = {}; else { - voice->mSend[i].Buffer = SendSlots[i]->Wet.Buffer; - voice->mSend[i].Channels = SendSlots[i]->Wet.NumChannels; + voice->mSend[i].Buffer = {SendSlots[i]->Wet.Buffer, + static_cast<size_t>(SendSlots[i]->Wet.NumChannels)}; } } diff --git a/Alc/mixvoice.cpp b/Alc/mixvoice.cpp index d3b76492..fc70fa2e 100644 --- a/Alc/mixvoice.cpp +++ b/Alc/mixvoice.cpp @@ -561,7 +561,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc parms.Hrtf.Old = parms.Hrtf.Target; auto set_current = [chan](ALvoice::SendData &send) -> void { - if(!send.Buffer) + if(send.Buffer.empty()) return; SendParams &parms = send.Params[chan]; @@ -801,7 +801,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc SilentTarget : parms.Gains.Target}; const auto outcount = static_cast<size_t>(voice->mDirect.ChannelsPerOrder[0]); - MixSamples(samples, {voice->mDirect.Buffer, outcount}, parms.Gains.Current, + MixSamples(samples, voice->mDirect.Buffer.first(outcount), parms.Gains.Current, TargetGains, Counter, OutPos, DstBufferSize); ALfloat (&nfcsamples)[BUFFERSIZE] = Device->NfcSampleData; @@ -813,7 +813,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc voice->mDirect.ChannelsPerOrder[order]); if(outcount < 1) return; (parms.NFCtrlFilter.*process)(nfcsamples, samples, DstBufferSize); - MixSamples(nfcsamples, {voice->mDirect.Buffer+chanoffset, outcount}, + MixSamples(nfcsamples, voice->mDirect.Buffer.subspan(chanoffset, outcount), parms.Gains.Current+chanoffset, TargetGains+chanoffset, Counter, OutPos, DstBufferSize); chanoffset += outcount; @@ -826,16 +826,15 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc { const ALfloat *TargetGains{UNLIKELY(vstate == ALvoice::Stopping) ? SilentTarget : parms.Gains.Target}; - const auto outcount = static_cast<size_t>(voice->mDirect.Channels); - MixSamples(samples, {voice->mDirect.Buffer, outcount}, parms.Gains.Current, - TargetGains, Counter, OutPos, DstBufferSize); + MixSamples(samples, voice->mDirect.Buffer, parms.Gains.Current, TargetGains, + Counter, OutPos, DstBufferSize); } } ALfloat (&FilterBuf)[BUFFERSIZE] = Device->FilteredData; auto mix_send = [vstate,Counter,OutPos,DstBufferSize,chan,ResampledData,&FilterBuf](ALvoice::SendData &send) -> void { - if(!send.Buffer) + if(send.Buffer.empty()) return; SendParams &parms = send.Params[chan]; @@ -844,9 +843,8 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc const ALfloat *TargetGains{UNLIKELY(vstate==ALvoice::Stopping) ? SilentTarget : parms.Gains.Target}; - const auto outcount = static_cast<size_t>(send.Channels); - MixSamples(samples, {send.Buffer, outcount}, parms.Gains.Current, TargetGains, - Counter, OutPos, DstBufferSize); + MixSamples(samples, send.Buffer, parms.Gains.Current, TargetGains, Counter, OutPos, + DstBufferSize); }; std::for_each(voice->mSend.begin(), voice->mSend.end(), mix_send); } diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index b6914c37..cb0b675c 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -265,8 +265,7 @@ struct ALvoice { int FilterType; DirectParams Params[MAX_INPUT_CHANNELS]; - FloatBufferLine *Buffer; - ALsizei Channels; + al::span<FloatBufferLine> Buffer; ALsizei ChannelsPerOrder[MAX_AMBI_ORDER+1]; } mDirect; @@ -274,8 +273,7 @@ struct ALvoice { int FilterType; SendParams Params[MAX_INPUT_CHANNELS]; - FloatBufferLine *Buffer; - ALsizei Channels; + al::span<FloatBufferLine> Buffer; }; al::FlexArray<SendData> mSend; |