aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/alc.cpp12
-rw-r--r--Alc/alu.cpp2
-rw-r--r--Alc/hrtf.cpp6
-rw-r--r--Alc/hrtf.h14
-rw-r--r--Alc/mixvoice.cpp6
-rw-r--r--OpenAL32/Include/alu.h113
-rw-r--r--OpenAL32/alSource.cpp2
7 files changed, 85 insertions, 70 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)
diff --git a/Alc/hrtf.h b/Alc/hrtf.h
index 58c35466..b59cd4ea 100644
--- a/Alc/hrtf.h
+++ b/Alc/hrtf.h
@@ -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;
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index eef7126d..d8e288f1 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -24,6 +24,56 @@
#include "almalloc.h"
+constexpr inline ALfloat minf(ALfloat a, ALfloat b) noexcept
+{ return ((a > b) ? b : a); }
+constexpr inline ALfloat maxf(ALfloat a, ALfloat b) noexcept
+{ return ((a > b) ? a : b); }
+constexpr inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max) noexcept
+{ return minf(max, maxf(min, val)); }
+
+constexpr inline ALdouble mind(ALdouble a, ALdouble b) noexcept
+{ return ((a > b) ? b : a); }
+constexpr inline ALdouble maxd(ALdouble a, ALdouble b) noexcept
+{ return ((a > b) ? a : b); }
+constexpr inline ALdouble clampd(ALdouble val, ALdouble min, ALdouble max) noexcept
+{ return mind(max, maxd(min, val)); }
+
+constexpr inline ALuint minu(ALuint a, ALuint b) noexcept
+{ return ((a > b) ? b : a); }
+constexpr inline ALuint maxu(ALuint a, ALuint b) noexcept
+{ return ((a > b) ? a : b); }
+constexpr inline ALuint clampu(ALuint val, ALuint min, ALuint max) noexcept
+{ return minu(max, maxu(min, val)); }
+
+constexpr inline ALint mini(ALint a, ALint b) noexcept
+{ return ((a > b) ? b : a); }
+constexpr inline ALint maxi(ALint a, ALint b) noexcept
+{ return ((a > b) ? a : b); }
+constexpr inline ALint clampi(ALint val, ALint min, ALint max) noexcept
+{ return mini(max, maxi(min, val)); }
+
+constexpr inline ALint64 mini64(ALint64 a, ALint64 b) noexcept
+{ return ((a > b) ? b : a); }
+constexpr inline ALint64 maxi64(ALint64 a, ALint64 b) noexcept
+{ return ((a > b) ? a : b); }
+constexpr inline ALint64 clampi64(ALint64 val, ALint64 min, ALint64 max) noexcept
+{ return mini64(max, maxi64(min, val)); }
+
+constexpr inline ALuint64 minu64(ALuint64 a, ALuint64 b) noexcept
+{ return ((a > b) ? b : a); }
+constexpr inline ALuint64 maxu64(ALuint64 a, ALuint64 b) noexcept
+{ return ((a > b) ? a : b); }
+constexpr inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max) noexcept
+{ return minu64(max, maxu64(min, val)); }
+
+constexpr inline size_t minz(size_t a, size_t b) noexcept
+{ return ((a > b) ? b : a); }
+constexpr inline size_t maxz(size_t a, size_t b) noexcept
+{ return ((a > b) ? a : b); }
+constexpr inline size_t clampz(size_t val, size_t min, size_t max) noexcept
+{ return minz(max, maxz(min, val)); }
+
+
enum class DistanceModel;
#define MAX_PITCH 255
@@ -267,7 +317,18 @@ struct ALvoice {
ALfloat (*Buffer)[BUFFERSIZE];
ALsizei Channels;
- } Send[];
+ };
+ al::FlexArray<SendData> Send;
+
+ ALvoice(size_t numsends) : Send{numsends} { }
+ ALvoice(const ALvoice&) = delete;
+ ALvoice& operator=(const ALvoice&) = delete;
+
+ static constexpr size_t Sizeof(size_t numsends) noexcept
+ {
+ return maxz(sizeof(ALvoice),
+ al::FlexArray<SendData>::Sizeof(numsends, offsetof(ALvoice, Send)));
+ }
};
void DeinitVoice(ALvoice *voice) noexcept;
@@ -306,56 +367,6 @@ using HrtfDirectMixerFunc = void(*)(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT
#define FRACTIONMASK (FRACTIONONE-1)
-constexpr inline ALfloat minf(ALfloat a, ALfloat b) noexcept
-{ return ((a > b) ? b : a); }
-constexpr inline ALfloat maxf(ALfloat a, ALfloat b) noexcept
-{ return ((a > b) ? a : b); }
-constexpr inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max) noexcept
-{ return minf(max, maxf(min, val)); }
-
-constexpr inline ALdouble mind(ALdouble a, ALdouble b) noexcept
-{ return ((a > b) ? b : a); }
-constexpr inline ALdouble maxd(ALdouble a, ALdouble b) noexcept
-{ return ((a > b) ? a : b); }
-constexpr inline ALdouble clampd(ALdouble val, ALdouble min, ALdouble max) noexcept
-{ return mind(max, maxd(min, val)); }
-
-constexpr inline ALuint minu(ALuint a, ALuint b) noexcept
-{ return ((a > b) ? b : a); }
-constexpr inline ALuint maxu(ALuint a, ALuint b) noexcept
-{ return ((a > b) ? a : b); }
-constexpr inline ALuint clampu(ALuint val, ALuint min, ALuint max) noexcept
-{ return minu(max, maxu(min, val)); }
-
-constexpr inline ALint mini(ALint a, ALint b) noexcept
-{ return ((a > b) ? b : a); }
-constexpr inline ALint maxi(ALint a, ALint b) noexcept
-{ return ((a > b) ? a : b); }
-constexpr inline ALint clampi(ALint val, ALint min, ALint max) noexcept
-{ return mini(max, maxi(min, val)); }
-
-constexpr inline ALint64 mini64(ALint64 a, ALint64 b) noexcept
-{ return ((a > b) ? b : a); }
-constexpr inline ALint64 maxi64(ALint64 a, ALint64 b) noexcept
-{ return ((a > b) ? a : b); }
-constexpr inline ALint64 clampi64(ALint64 val, ALint64 min, ALint64 max) noexcept
-{ return mini64(max, maxi64(min, val)); }
-
-constexpr inline ALuint64 minu64(ALuint64 a, ALuint64 b) noexcept
-{ return ((a > b) ? b : a); }
-constexpr inline ALuint64 maxu64(ALuint64 a, ALuint64 b) noexcept
-{ return ((a > b) ? a : b); }
-constexpr inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max) noexcept
-{ return minu64(max, maxu64(min, val)); }
-
-constexpr inline size_t minz(size_t a, size_t b) noexcept
-{ return ((a > b) ? b : a); }
-constexpr inline size_t maxz(size_t a, size_t b) noexcept
-{ return ((a > b) ? a : b); }
-constexpr inline size_t clampz(size_t val, size_t min, size_t max) noexcept
-{ return minz(max, maxz(min, val)); }
-
-
inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu) noexcept
{ return val1 + (val2-val1)*mu; }
inline ALfloat cubic(ALfloat val1, ALfloat val2, ALfloat val3, ALfloat val4, ALfloat mu) noexcept
diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp
index 236ed144..11bc6cc0 100644
--- a/OpenAL32/alSource.cpp
+++ b/OpenAL32/alSource.cpp
@@ -2824,7 +2824,7 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
if(source->SourceType == AL_STATIC) voice->Flags |= VOICE_IS_STATIC;
std::fill_n(std::begin(voice->Direct.Params), voice->NumChannels, DirectParams{});
- std::for_each(voice->Send+0, voice->Send+source->Send.size(),
+ std::for_each(voice->Send.begin(), voice->Send.end(),
[voice](ALvoice::SendData &send) -> void
{ std::fill_n(std::begin(send.Params), voice->NumChannels, SendParams{}); }
);