diff options
author | Chris Robinson <[email protected]> | 2019-01-12 01:25:33 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-01-12 01:25:33 -0800 |
commit | d64eaba3229f48a519586c0436235e3c2809329b (patch) | |
tree | d578ef76627df78c0ec7b1ef2bca1fd1e8af0db1 /Alc | |
parent | ab1667146627e93688cfeb4cf877764f220c0c3e (diff) |
Use a flexible array for DirectHrtfState and ALvoice
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alc.cpp | 12 | ||||
-rw-r--r-- | Alc/alu.cpp | 2 | ||||
-rw-r--r-- | Alc/hrtf.cpp | 6 | ||||
-rw-r--r-- | Alc/hrtf.h | 14 | ||||
-rw-r--r-- | Alc/mixvoice.cpp | 6 |
5 files changed, 22 insertions, 18 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index cea1fb61..3dbc0524 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2594,7 +2594,7 @@ void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends) * property set (including the dynamically-sized Send[] array) in one * chunk. */ - const size_t sizeof_voice{RoundUp(FAM_SIZE(ALvoice, Send, num_sends), 16)}; + const size_t sizeof_voice{RoundUp(ALvoice::Sizeof(num_sends), 16)}; const size_t size{sizeof(ALvoice*) + sizeof_voice}; auto voices = static_cast<ALvoice**>(al_calloc(16, RoundUp(size*num_voices, 16))); @@ -2608,9 +2608,9 @@ void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends) const ALsizei s_count = mini(old_sends, num_sends); /* Copy the old voice data to the new storage. */ - auto copy_voice = [&voice,sizeof_voice,s_count](ALvoice *old_voice) -> ALvoice* + auto copy_voice = [&voice,num_sends,sizeof_voice,s_count](ALvoice *old_voice) -> ALvoice* { - voice = new (voice) ALvoice{}; + voice = new (voice) ALvoice{static_cast<size_t>(num_sends)}; /* Make sure the old voice's Update (if any) is cleared so it * doesn't get deleted on deinit. @@ -2655,7 +2655,7 @@ void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends) voice->ResampleState = old_voice->ResampleState; voice->Direct = old_voice->Direct; - std::copy_n(old_voice->Send, s_count, voice->Send); + std::copy_n(old_voice->Send.begin(), s_count, voice->Send.begin()); /* Set this voice's reference. */ ALvoice *ret = voice; @@ -2670,9 +2670,9 @@ void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends) std::for_each(context->Voices, voices_end, DeinitVoice); } /* Finish setting the voices and references. */ - auto init_voice = [&voice,sizeof_voice]() -> ALvoice* + auto init_voice = [&voice,num_sends,sizeof_voice]() -> ALvoice* { - ALvoice *ret = new (voice) ALvoice{}; + ALvoice *ret = new (voice) ALvoice{static_cast<size_t>(num_sends)}; voice = reinterpret_cast<ALvoice*>(reinterpret_cast<char*>(voice) + sizeof_voice); return ret; }; diff --git a/Alc/alu.cpp b/Alc/alu.cpp index 55e4e5c7..b3ca26cb 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -592,7 +592,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev ); const ALsizei NumSends{Device->NumAuxSends}; ASSUME(NumSends >= 0); - std::for_each(voice->Send+0, voice->Send+NumSends, + std::for_each(voice->Send.begin(), voice->Send.end(), [num_channels](ALvoice::SendData &send) -> void { std::for_each(std::begin(send.Params), std::begin(send.Params)+num_channels, diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp index 699ec1b9..b0865811 100644 --- a/Alc/hrtf.cpp +++ b/Alc/hrtf.cpp @@ -290,10 +290,10 @@ void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, AL } -std::unique_ptr<DirectHrtfState> DirectHrtfState::Create(ALsizei num_chans) +std::unique_ptr<DirectHrtfState> DirectHrtfState::Create(size_t num_chans) { - void *ptr{al_calloc(16, FAM_SIZE(DirectHrtfState, Chan, num_chans))}; - return std::unique_ptr<DirectHrtfState>{new (ptr) DirectHrtfState{}}; + void *ptr{al_calloc(16, DirectHrtfState::Sizeof(num_chans))}; + return std::unique_ptr<DirectHrtfState>{new (ptr) DirectHrtfState{num_chans}}; } void BuildBFormatHrtf(const HrtfEntry *Hrtf, DirectHrtfState *state, const ALsizei NumChannels, const AngularPoint *AmbiPoints, const ALfloat (*RESTRICT AmbiMatrix)[MAX_AMBI_COEFFS], const ALsizei AmbiCount, const ALfloat *RESTRICT AmbiOrderHFGain) @@ -59,13 +59,19 @@ struct DirectHrtfState { /* HRTF filter state for dry buffer content */ ALsizei Offset{0}; ALsizei IrSize{0}; - struct { + struct ChanData { alignas(16) ALfloat Values[HRIR_LENGTH][2]; alignas(16) ALfloat Coeffs[HRIR_LENGTH][2]; - } Chan[]; + }; + al::FlexArray<ChanData> Chan; - DirectHrtfState() noexcept { } - static std::unique_ptr<DirectHrtfState> Create(ALsizei num_chans); + DirectHrtfState(size_t numchans) : Chan{numchans} { } + DirectHrtfState(const DirectHrtfState&) = delete; + DirectHrtfState& operator=(const DirectHrtfState&) = delete; + + static std::unique_ptr<DirectHrtfState> Create(size_t num_chans); + static constexpr size_t Sizeof(size_t numchans) noexcept + { return al::FlexArray<ChanData>::Sizeof(numchans, offsetof(DirectHrtfState, Chan)); } DEF_PLACE_NEWDEL() }; diff --git a/Alc/mixvoice.cpp b/Alc/mixvoice.cpp index 7d30ad12..b23b8d2e 100644 --- a/Alc/mixvoice.cpp +++ b/Alc/mixvoice.cpp @@ -311,12 +311,10 @@ ALboolean MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context, ALCdevice *Device{Context->Device}; const ALsizei IrSize{Device->mHrtf ? Device->mHrtf->irSize : 0}; - const ALsizei NumAuxSends{Device->NumAuxSends}; const int OutLIdx{GetChannelIdxByName(Device->RealOut, FrontLeft)}; const int OutRIdx{GetChannelIdxByName(Device->RealOut, FrontRight)}; ASSUME(IrSize >= 0); - ASSUME(NumAuxSends >= 0); ResamplerFunc Resample{(increment == FRACTIONONE && DataPosFrac == 0) ? Resample_copy_C : voice->Resampler}; @@ -342,7 +340,7 @@ ALboolean MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context, std::copy(std::begin(parms.Gains.Target), std::end(parms.Gains.Target), std::begin(parms.Gains.Current)); }; - std::for_each(voice->Send, voice->Send+NumAuxSends, set_current); + std::for_each(voice->Send.begin(), voice->Send.end(), set_current); } } else if((voice->Flags&VOICE_HAS_HRTF)) @@ -667,7 +665,7 @@ ALboolean MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context, MixSamples(samples, send.Channels, send.Buffer, parms.Gains.Current, parms.Gains.Target, Counter, OutPos, DstBufferSize); }; - std::for_each(voice->Send, voice->Send+NumAuxSends, mix_send); + std::for_each(voice->Send.begin(), voice->Send.end(), mix_send); } /* Update positions */ DataPosFrac += increment*DstBufferSize; |