From aa05feec4a1d77eb37043aa93fc3237f70dc12ef Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Thu, 3 Dec 2020 23:26:07 -0800
Subject: Avoid a global MAX_PITCH macro

---
 alc/alu.cpp       | 14 ++++++++++----
 alc/alu.h         |  1 -
 alc/converter.cpp | 12 ++++++++++--
 alc/converter.h   |  7 +------
 alc/voice.cpp     |  5 -----
 5 files changed, 21 insertions(+), 18 deletions(-)

(limited to 'alc')

diff --git a/alc/alu.cpp b/alc/alu.cpp
index a1ea92da..eb1fb291 100644
--- a/alc/alu.cpp
+++ b/alc/alu.cpp
@@ -109,6 +109,12 @@ static_assert(!(MaxResamplerPadding&1), "MaxResamplerPadding is not a multiple o
 
 namespace {
 
+constexpr uint MaxPitch{10};
+
+static_assert((BufferLineSize-1)/MaxPitch > 0, "MaxPitch is too large for BufferLineSize!");
+static_assert((INT_MAX>>MixerFracBits)/MaxPitch > BufferLineSize,
+    "MaxPitch and/or BufferLineSize are too large for MixerFracBits!");
+
 using namespace std::placeholders;
 
 float InitConeScale()
@@ -1217,8 +1223,8 @@ void CalcNonAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcon
     /* Calculate the stepping value */
     const auto Pitch = static_cast<float>(voice->mFrequency) /
         static_cast<float>(Device->Frequency) * props->Pitch;
-    if(Pitch > float{MAX_PITCH})
-        voice->mStep = MAX_PITCH<<MixerFracBits;
+    if(Pitch > float{MaxPitch})
+        voice->mStep = MaxPitch<<MixerFracBits;
     else
         voice->mStep = maxu(fastf2u(Pitch * MixerFracOne), 1);
     voice->mResampler = PrepareResampler(props->mResampler, voice->mStep, &voice->mResampleState);
@@ -1527,8 +1533,8 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
      * fixed-point stepping value.
      */
     Pitch *= static_cast<float>(voice->mFrequency) / static_cast<float>(Device->Frequency);
-    if(Pitch > float{MAX_PITCH})
-        voice->mStep = MAX_PITCH<<MixerFracBits;
+    if(Pitch > float{MaxPitch})
+        voice->mStep = MaxPitch<<MixerFracBits;
     else
         voice->mStep = maxu(fastf2u(Pitch * MixerFracOne), 1);
     voice->mResampler = PrepareResampler(props->mResampler, voice->mStep, &voice->mResampleState);
diff --git a/alc/alu.h b/alc/alu.h
index ac9dddf4..7e7f8996 100644
--- a/alc/alu.h
+++ b/alc/alu.h
@@ -17,7 +17,6 @@ struct ALeffectslot;
 struct MixParams;
 
 
-#define MAX_PITCH  10
 #define MAX_SENDS  6
 
 
diff --git a/alc/converter.cpp b/alc/converter.cpp
index 57b902b8..de6f4587 100644
--- a/alc/converter.cpp
+++ b/alc/converter.cpp
@@ -4,11 +4,13 @@
 #include "converter.h"
 
 #include <algorithm>
+#include <cmath>
 #include <cstdint>
 #include <iterator>
+#include <limits.h>
 
 #include "albyte.h"
-#include "alu.h"
+#include "alnumeric.h"
 #include "fpu_ctrl.h"
 #include "mixer/defs.h"
 
@@ -18,6 +20,12 @@ struct CopyTag;
 
 namespace {
 
+constexpr uint MaxPitch{10};
+
+static_assert((BufferLineSize-1)/MaxPitch > 0, "MaxPitch is too large for BufferLineSize!");
+static_assert((INT_MAX>>MixerFracBits)/MaxPitch > BufferLineSize,
+    "MaxPitch and/or BufferLineSize are too large for MixerFracBits!");
+
 /* Base template left undefined. Should be marked =delete, but Clang 3.8.1
  * chokes on that given the inline specializations.
  */
@@ -173,7 +181,7 @@ SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType,
     /* Have to set the mixer FPU mode since that's what the resampler code expects. */
     FPUCtl mixer_mode{};
     auto step = static_cast<uint>(
-        mind(srcRate*double{MixerFracOne}/dstRate + 0.5, MAX_PITCH*MixerFracOne));
+        mind(srcRate*double{MixerFracOne}/dstRate + 0.5, MaxPitch*MixerFracOne));
     converter->mIncrement = maxu(step, 1);
     if(converter->mIncrement == MixerFracOne)
         converter->mResample = Resample_<CopyTag,CTag>;
diff --git a/alc/converter.h b/alc/converter.h
index 2ae77764..f84efd72 100644
--- a/alc/converter.h
+++ b/alc/converter.h
@@ -4,14 +4,9 @@
 #include <cstddef>
 #include <memory>
 
-#include "AL/al.h"
-
-#include "alcmain.h"
 #include "almalloc.h"
-#include "alnumeric.h"
-#include "alu.h"
 #include "core/devformat.h"
-#include "voice.h"
+#include "mixer/defs.h"
 
 using uint = unsigned int;
 
diff --git a/alc/voice.cpp b/alc/voice.cpp
index a1f49d6b..54775a72 100644
--- a/alc/voice.cpp
+++ b/alc/voice.cpp
@@ -71,11 +71,6 @@ struct NEONTag;
 struct CopyTag;
 
 
-static_assert((BufferLineSize-1)/MAX_PITCH > 0, "MAX_PITCH is too large for BufferLineSize!");
-static_assert((INT_MAX>>MixerFracBits)/MAX_PITCH > BufferLineSize,
-    "MAX_PITCH and/or BufferLineSize are too large for MixerFracBits!");
-
-
 Resampler ResamplerDefault{Resampler::Linear};
 
 MixerFunc MixSamples{Mix_<CTag>};
-- 
cgit v1.2.3