aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-12-24 07:30:01 -0800
committerChris Robinson <[email protected]>2018-12-24 07:30:01 -0800
commit68352d318863105573e5022d1fc5383ac52f5de2 (patch)
treefbca9e38864fd30c0df729953262b2f835f27f63
parentef101523610a26639228fd88bfd303cb31dbd025 (diff)
Apply the limiter before distance compensation
-rw-r--r--Alc/alu.cpp19
-rw-r--r--OpenAL32/Include/alMain.h4
2 files changed, 12 insertions, 11 deletions
diff --git a/Alc/alu.cpp b/Alc/alu.cpp
index b95f0d7c..fbdbc4b2 100644
--- a/Alc/alu.cpp
+++ b/Alc/alu.cpp
@@ -1559,12 +1559,13 @@ void ApplyStablizer(FrontStablizer *Stablizer, ALfloat (*RESTRICT Buffer)[BUFFER
}
}
-void ApplyDistanceComp(ALfloat (*RESTRICT Samples)[BUFFERSIZE], const DistanceComp &distcomp,
- ALfloat *RESTRICT Values, const ALsizei SamplesToDo, const ALsizei numchans)
+void ApplyDistanceComp(ALfloat (*Samples)[BUFFERSIZE], const DistanceComp &distcomp,
+ ALfloat (&Values)[BUFFERSIZE], const ALsizei SamplesToDo, const ALsizei numchans)
{
ASSUME(SamplesToDo > 0);
ASSUME(numchans > 0);
+ ALfloat *RESTRICT tempvals{al::assume_aligned<16>(&Values[0])};
for(ALsizei c{0};c < numchans;c++)
{
ALfloat *RESTRICT inout{al::assume_aligned<16>(Samples[c])};
@@ -1584,17 +1585,17 @@ void ApplyDistanceComp(ALfloat (*RESTRICT Samples)[BUFFERSIZE], const DistanceCo
if(LIKELY(SamplesToDo >= base))
{
- auto out = std::copy_n(distbuf, base, Values);
+ auto out = std::copy_n(distbuf, base, tempvals);
std::copy_n(inout, SamplesToDo-base, out);
std::copy_n(inout+SamplesToDo-base, base, distbuf);
}
else
{
- std::copy_n(distbuf, SamplesToDo, Values);
+ std::copy_n(distbuf, SamplesToDo, tempvals);
auto out = std::copy(distbuf+SamplesToDo, distbuf+base, distbuf);
std::copy_n(inout, SamplesToDo, out);
}
- std::transform<ALfloat*RESTRICT>(Values, Values+SamplesToDo, inout,
+ std::transform(tempvals, tempvals+SamplesToDo, inout,
[gain](const ALfloat in) noexcept -> ALfloat { return in * gain; }
);
}
@@ -1743,14 +1744,14 @@ void aluMixData(ALCdevice *device, ALvoid *OutBuffer, ALsizei NumSamples)
SamplesToDo, device->RealOut.NumChannels);
}
+ /* Apply compression, limiting sample amplitude if needed or desired. */
+ if(device->Limiter)
+ ApplyCompression(device->Limiter.get(), SamplesToDo, device->RealOut.Buffer);
+
/* Apply delays and attenuation for mismatched speaker distances. */
ApplyDistanceComp(device->RealOut.Buffer, device->ChannelDelay, device->TempBuffer[0],
SamplesToDo, device->RealOut.NumChannels);
- /* Apply compression, limiting final sample amplitude, if desired. */
- if(device->Limiter)
- ApplyCompression(device->Limiter.get(), SamplesToDo, device->RealOut.Buffer);
-
/* Apply dithering. The compressor should have left enough headroom for
* the dither noise to not saturate.
*/
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index bc1dc222..3ed11193 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -778,11 +778,11 @@ struct ALCdevice_struct {
std::unique_ptr<FrontStablizer> Stablizer;
+ std::unique_ptr<Compressor> Limiter;
+
/* Delay buffers used to compensate for speaker distances. */
DistanceComp ChannelDelay;
- std::unique_ptr<Compressor> Limiter;
-
/* Dithering control. */
ALfloat DitherDepth{0.0f};
ALuint DitherSeed{0u};