diff options
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alc.cpp | 16 | ||||
-rw-r--r-- | Alc/alu.cpp | 37 | ||||
-rw-r--r-- | Alc/panning.cpp | 11 |
3 files changed, 23 insertions, 41 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; |