aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/mastering.c
diff options
context:
space:
mode:
Diffstat (limited to 'Alc/mastering.c')
-rw-r--r--Alc/mastering.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/Alc/mastering.c b/Alc/mastering.c
index 52ff5b23..5ccf3a9e 100644
--- a/Alc/mastering.c
+++ b/Alc/mastering.c
@@ -6,6 +6,19 @@
#include "alu.h"
#include "almalloc.h"
#include "static_assert.h"
+#include "math_defs.h"
+
+
+/* Early MSVC lacks round/roundf */
+#if defined(_MSC_VER) && _MSC_VER < 1800
+static double round(double val)
+{
+ if(val < 0.0)
+ return ceil(val-0.5);
+ return floor(val+0.5);
+}
+#define roundf(f) ((float)round((float)(f)))
+#endif
/* These structures assume BUFFERSIZE is a power of 2. */
@@ -83,8 +96,8 @@ static ALfloat UpdateSlidingHold(SlidingHold *Hold, const ALsizei i, const ALflo
{
const ALsizei mask = BUFFERSIZE - 1;
const ALsizei length = Hold->Length;
- ALfloat *restrict values = Hold->Values;
- ALsizei *restrict expiries = Hold->Expiries;
+ ALfloat *RESTRICT values = Hold->Values;
+ ALsizei *RESTRICT expiries = Hold->Expiries;
ALsizei lowerIndex = Hold->LowerIndex;
ALsizei upperIndex = Hold->UpperIndex;
@@ -122,7 +135,7 @@ static ALfloat UpdateSlidingHold(SlidingHold *Hold, const ALsizei i, const ALflo
static void ShiftSlidingHold(SlidingHold *Hold, const ALsizei n)
{
const ALsizei lowerIndex = Hold->LowerIndex;
- ALsizei *restrict expiries = Hold->Expiries;
+ ALsizei *RESTRICT expiries = Hold->Expiries;
ALsizei i = Hold->UpperIndex;
if(lowerIndex < i)
@@ -140,11 +153,11 @@ static void ShiftSlidingHold(SlidingHold *Hold, const ALsizei n)
/* Multichannel compression is linked via the absolute maximum of all
* channels.
*/
-static void LinkChannels(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*restrict OutBuffer)[BUFFERSIZE])
+static void LinkChannels(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE])
{
const ALsizei index = Comp->LookAhead;
const ALsizei numChans = Comp->NumChans;
- ALfloat *restrict sideChain = Comp->SideChain;
+ ALfloat *RESTRICT sideChain = Comp->SideChain;
ALsizei c, i;
ASSUME(SamplesToDo > 0);
@@ -173,8 +186,8 @@ static void CrestDetector(Compressor *Comp, const ALsizei SamplesToDo)
{
const ALfloat a_crest = Comp->CrestCoeff;
const ALsizei index = Comp->LookAhead;
- const ALfloat *restrict sideChain = Comp->SideChain;
- ALfloat *restrict crestFactor = Comp->CrestFactor;
+ const ALfloat *RESTRICT sideChain = Comp->SideChain;
+ ALfloat *RESTRICT crestFactor = Comp->CrestFactor;
ALfloat y2_peak = Comp->LastPeakSq;
ALfloat y2_rms = Comp->LastRmsSq;
ALsizei i;
@@ -202,7 +215,7 @@ static void CrestDetector(Compressor *Comp, const ALsizei SamplesToDo)
static void PeakDetector(Compressor *Comp, const ALsizei SamplesToDo)
{
const ALsizei index = Comp->LookAhead;
- ALfloat *restrict sideChain = Comp->SideChain;
+ ALfloat *RESTRICT sideChain = Comp->SideChain;
ALsizei i;
ASSUME(SamplesToDo > 0);
@@ -223,7 +236,7 @@ static void PeakDetector(Compressor *Comp, const ALsizei SamplesToDo)
static void PeakHoldDetector(Compressor *Comp, const ALsizei SamplesToDo)
{
const ALsizei index = Comp->LookAhead;
- ALfloat *restrict sideChain = Comp->SideChain;
+ ALfloat *RESTRICT sideChain = Comp->SideChain;
SlidingHold *hold = Comp->Hold;
ALsizei i;
@@ -260,8 +273,8 @@ static void GainCompressor(Compressor *Comp, const ALsizei SamplesToDo)
const ALfloat release = Comp->Release;
const ALfloat c_est = Comp->GainEstimate;
const ALfloat a_adp = Comp->AdaptCoeff;
- const ALfloat *restrict crestFactor = Comp->CrestFactor;
- ALfloat *restrict sideChain = Comp->SideChain;
+ const ALfloat *RESTRICT crestFactor = Comp->CrestFactor;
+ ALfloat *RESTRICT sideChain = Comp->SideChain;
ALfloat postGain = Comp->PostGain;
ALfloat knee = Comp->Knee;
ALfloat t_att = attack;
@@ -353,13 +366,13 @@ static void GainCompressor(Compressor *Comp, const ALsizei SamplesToDo)
* reaching the offending impulse. This is best used when operating as a
* limiter.
*/
-static void SignalDelay(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*restrict OutBuffer)[BUFFERSIZE])
+static void SignalDelay(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE])
{
const ALsizei mask = BUFFERSIZE - 1;
const ALsizei numChans = Comp->NumChans;
const ALsizei indexIn = Comp->DelayIndex;
const ALsizei indexOut = Comp->DelayIndex - Comp->LookAhead;
- ALfloat (*restrict delay)[BUFFERSIZE] = Comp->Delay;
+ ALfloat (*RESTRICT delay)[BUFFERSIZE] = Comp->Delay;
ALsizei c, i;
ASSUME(SamplesToDo > 0);
@@ -463,14 +476,14 @@ Compressor* CompressorInit(const ALsizei NumChans, const ALuint SampleRate,
if(hold > 0)
{
Comp->Hold = (SlidingHold*)(Comp + 1);
- Comp->Hold->Values[0] = -INFINITY;
+ Comp->Hold->Values[0] = -HUGE_VALF;
Comp->Hold->Expiries[0] = hold;
Comp->Hold->Length = hold;
- Comp->Delay = (ALfloat(*)[])(Comp->Hold + 1);
+ Comp->Delay = (ALfloat(*)[BUFFERSIZE])(Comp->Hold + 1);
}
else
{
- Comp->Delay = (ALfloat(*)[])(Comp + 1);
+ Comp->Delay = (ALfloat(*)[BUFFERSIZE])(Comp + 1);
}
}
@@ -481,11 +494,11 @@ Compressor* CompressorInit(const ALsizei NumChans, const ALuint SampleRate,
return Comp;
}
-void ApplyCompression(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*restrict OutBuffer)[BUFFERSIZE])
+void ApplyCompression(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE])
{
const ALsizei numChans = Comp->NumChans;
const ALfloat preGain = Comp->PreGain;
- ALfloat *restrict sideChain;
+ ALfloat *RESTRICT sideChain;
ALsizei c, i;
ASSUME(SamplesToDo > 0);