diff options
-rw-r--r-- | Alc/alc.cpp | 16 | ||||
-rw-r--r-- | Alc/alu.cpp | 37 | ||||
-rw-r--r-- | Alc/panning.cpp | 11 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 35 |
4 files changed, 52 insertions, 47 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index fa909091..fa7b9f44 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -1994,12 +1994,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) al_free(device->Bs2b); device->Bs2b = nullptr; - al_free(device->ChannelDelay[0].Buffer); - for(i = 0;i < MAX_OUTPUT_CHANNELS;i++) - { - device->ChannelDelay[i].Length = 0; - device->ChannelDelay[i].Buffer = nullptr; - } + device->ChannelDelay.clear(); + device->ChannelDelay.shrink_to_fit(); device->Dry.Buffer = nullptr; device->Dry.NumChannels = 0; @@ -2445,14 +2441,6 @@ ALCdevice_struct::~ALCdevice_struct() al_free(Limiter); Limiter = nullptr; - - al_free(ChannelDelay[0].Buffer); - for(ALsizei i{0};i < MAX_OUTPUT_CHANNELS;i++) - { - ChannelDelay[i].Gain = 1.0f; - ChannelDelay[i].Length = 0; - ChannelDelay[i].Buffer = nullptr; - } } diff --git a/Alc/alu.cpp b/Alc/alu.cpp index 68387f7b..faa011a2 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -26,6 +26,8 @@ #include <ctype.h> #include <assert.h> +#include <algorithm> + #include "alMain.h" #include "alcontext.h" #include "alSource.h" @@ -1568,12 +1570,10 @@ void ApplyStablizer(FrontStablizer *Stablizer, ALfloat (*RESTRICT Buffer)[BUFFER } } -void ApplyDistanceComp(ALfloat (*RESTRICT Samples)[BUFFERSIZE], DistanceComp *distcomp, +void ApplyDistanceComp(ALfloat (*RESTRICT Samples)[BUFFERSIZE], const DistanceComp &distcomp, ALfloat *RESTRICT Values, ALsizei SamplesToDo, ALsizei numchans) { - ALsizei i, c; - - for(c = 0;c < numchans;c++) + for(ALsizei c{0};c < numchans;c++) { ALfloat *RESTRICT inout = Samples[c]; const ALfloat gain = distcomp[c].Gain; @@ -1583,30 +1583,29 @@ void ApplyDistanceComp(ALfloat (*RESTRICT Samples)[BUFFERSIZE], DistanceComp *di if(base == 0) { if(gain < 1.0f) - { - for(i = 0;i < SamplesToDo;i++) - inout[i] *= gain; - } + std::for_each(inout, inout+SamplesToDo, + [gain](ALfloat &in) noexcept -> void + { in *= gain; } + ); continue; } if(LIKELY(SamplesToDo >= base)) { - for(i = 0;i < base;i++) - Values[i] = distbuf[i]; - for(;i < SamplesToDo;i++) - Values[i] = inout[i-base]; - memcpy(distbuf, &inout[SamplesToDo-base], base*sizeof(ALfloat)); + auto out = std::copy_n(distbuf, base, Values); + std::copy_n(inout, SamplesToDo-base, out); + std::copy_n(inout+SamplesToDo-base, base, distbuf); } else { - for(i = 0;i < SamplesToDo;i++) - Values[i] = distbuf[i]; - memmove(distbuf, distbuf+SamplesToDo, (base-SamplesToDo)*sizeof(ALfloat)); - memcpy(distbuf+base-SamplesToDo, inout, SamplesToDo*sizeof(ALfloat)); + std::copy_n(distbuf, SamplesToDo, Values); + auto out = std::copy(distbuf+SamplesToDo, distbuf+base, distbuf); + std::copy_n(inout, SamplesToDo, out); } - for(i = 0;i < SamplesToDo;i++) - inout[i] = Values[i]*gain; + std::transform(Values, Values+SamplesToDo, inout, + [gain](ALfloat in) noexcept -> ALfloat + { return in * gain; } + ); } } diff --git a/Alc/panning.cpp b/Alc/panning.cpp index 806486a3..f538e347 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -445,8 +445,8 @@ static void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const AL if(total > 0) { - device->ChannelDelay[0].Buffer = reinterpret_cast<float*>( - al_calloc(16, total * sizeof(ALfloat))); + device->ChannelDelay.resize(total); + device->ChannelDelay[0].Buffer = device->ChannelDelay.data(); for(i = 1;i < MAX_OUTPUT_CHANNELS;i++) { size_t len = RoundUp(device->ChannelDelay[i-1].Length, 4); @@ -943,12 +943,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf device->NumChannelsPerOrder[i] = 0; device->AvgSpeakerDist = 0.0f; - memset(device->ChannelDelay, 0, sizeof(device->ChannelDelay)); - for(i = 0;i < MAX_OUTPUT_CHANNELS;i++) - { - device->ChannelDelay[i].Gain = 1.0f; - device->ChannelDelay[i].Length = 0; - } + device->ChannelDelay.clear(); al_free(device->Stablizer); device->Stablizer = NULL; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index c7bdcc2a..e6ad849e 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -556,11 +556,34 @@ typedef struct EnumeratedHrtf { /* Maximum delay in samples for speaker distance compensation. */ #define MAX_DELAY_LENGTH 1024 -typedef struct DistanceComp { - ALfloat Gain{1.0f}; - ALsizei Length{0}; /* Valid range is [0...MAX_DELAY_LENGTH). */ - ALfloat *Buffer{nullptr}; -} DistanceComp; +class DistanceComp { + struct DistData { + ALfloat Gain{1.0f}; + ALsizei Length{0}; /* Valid range is [0...MAX_DELAY_LENGTH). */ + ALfloat *Buffer{nullptr}; + } mChannel[MAX_OUTPUT_CHANNELS]; + al::vector<ALfloat,16> mSamples; + +public: + void resize(size_t amt) { mSamples.resize(amt); } + void shrink_to_fit() { mSamples.shrink_to_fit(); } + void clear() noexcept + { + for(auto &chan : mChannel) + { + chan.Gain = 1.0f; + chan.Length = 0; + chan.Buffer = nullptr; + } + mSamples.clear(); + } + + ALfloat *data() noexcept { return mSamples.data(); } + const ALfloat *data() const noexcept { return mSamples.data(); } + + DistData& operator[](size_t o) noexcept { return mChannel[o]; } + const DistData& operator[](size_t o) const noexcept { return mChannel[o]; } +}; /* Size for temporary storage of buffer data, in ALfloats. Larger values need * more memory, while smaller values may need more iterations. The value needs @@ -695,7 +718,7 @@ struct ALCdevice_struct { ALfloat AvgSpeakerDist{0.0f}; /* Delay buffers used to compensate for speaker distances. */ - DistanceComp ChannelDelay[MAX_OUTPUT_CHANNELS]; + DistanceComp ChannelDelay; /* Dithering control. */ ALfloat DitherDepth{0.0f}; |