aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--al/source.h3
-rw-r--r--alc/alu.cpp6
-rw-r--r--alc/effects/convolution.cpp7
-rw-r--r--common/math_defs.h7
-rw-r--r--utils/uhjencoder.cpp95
6 files changed, 58 insertions, 61 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e0662b1..93f2c7ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -637,7 +637,6 @@ set(COMMON_OBJS
common/dynload.cpp
common/dynload.h
common/intrusive_ptr.h
- common/math_defs.h
common/opthelpers.h
common/phase_shifter.h
common/polyphase_resampler.cpp
diff --git a/al/source.h b/al/source.h
index 474d0a91..25ece822 100644
--- a/al/source.h
+++ b/al/source.h
@@ -19,7 +19,6 @@
#include "alnumeric.h"
#include "atomic.h"
#include "core/voice.h"
-#include "math_defs.h"
#include "vector.h"
struct ALbuffer;
@@ -79,7 +78,7 @@ struct ALsource {
/* NOTE: Stereo pan angles are specified in radians, counter-clockwise
* rather than clockwise.
*/
- std::array<float,2> StereoPan{{Deg2Rad( 30.0f), Deg2Rad(-30.0f)}};
+ std::array<float,2> StereoPan{{al::numbers::pi_v<float>/6.0f, -al::numbers::pi_v<float>/6.0f}};
float Radius{0.0f};
float EnhWidth{0.593f};
diff --git a/alc/alu.cpp b/alc/alu.cpp
index dbf4dedf..13e36d6a 100644
--- a/alc/alu.cpp
+++ b/alc/alu.cpp
@@ -72,7 +72,6 @@
#include "core/voice.h"
#include "core/voice_change.h"
#include "intrusive_ptr.h"
-#include "math_defs.h"
#include "opthelpers.h"
#include "ringbuffer.h"
#include "strutils.h"
@@ -678,6 +677,9 @@ void AmbiRotator(std::array<std::array<float,MaxAmbiChannels>,MaxAmbiChannels> &
/* End ambisonic rotation helpers. */
+constexpr float Deg2Rad(float x) noexcept
+{ return static_cast<float>(al::numbers::pi / 180.0 * x); }
+
struct GainTriplet { float Base, HF, LF; };
void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, const float zpos,
@@ -685,7 +687,7 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
const al::span<const GainTriplet,MAX_SENDS> WetGain, EffectSlot *(&SendSlots)[MAX_SENDS],
const VoiceProps *props, const ContextParams &Context, const DeviceBase *Device)
{
- static const ChanMap MonoMap[1]{
+ static constexpr ChanMap MonoMap[1]{
{ FrontCenter, 0.0f, 0.0f }
}, RearMap[2]{
{ BackLeft, Deg2Rad(-150.0f), Deg2Rad(0.0f) },
diff --git a/alc/effects/convolution.cpp b/alc/effects/convolution.cpp
index 10e3dd9d..196238fc 100644
--- a/alc/effects/convolution.cpp
+++ b/alc/effects/convolution.cpp
@@ -35,7 +35,6 @@
#include "core/fmt_traits.h"
#include "core/mixer.h"
#include "intrusive_ptr.h"
-#include "math_defs.h"
#include "polyphase_resampler.h"
#include "vector.h"
@@ -121,6 +120,10 @@ struct ChanMap {
float elevation;
};
+constexpr float Deg2Rad(float x) noexcept
+{ return static_cast<float>(al::numbers::pi / 180.0 * x); }
+
+
using complex_d = std::complex<double>;
constexpr size_t ConvolveUpdateSize{256};
@@ -346,7 +349,7 @@ void ConvolutionState::update(const ContextBase *context, const EffectSlot *slot
* to have its own output target since the main mixing buffer won't have an
* LFE channel (due to being B-Format).
*/
- static const ChanMap MonoMap[1]{
+ static constexpr ChanMap MonoMap[1]{
{ FrontCenter, 0.0f, 0.0f }
}, StereoMap[2]{
{ FrontLeft, Deg2Rad(-45.0f), Deg2Rad(0.0f) },
diff --git a/common/math_defs.h b/common/math_defs.h
deleted file mode 100644
index d66923ea..00000000
--- a/common/math_defs.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef AL_MATH_DEFS_H
-#define AL_MATH_DEFS_H
-
-constexpr float Deg2Rad(float x) noexcept
-{ return static_cast<float>(x * 1.74532925199432955e-02/*pi/180*/); }
-
-#endif /* AL_MATH_DEFS_H */
diff --git a/utils/uhjencoder.cpp b/utils/uhjencoder.cpp
index 700d1b17..2c99d2e1 100644
--- a/utils/uhjencoder.cpp
+++ b/utils/uhjencoder.cpp
@@ -34,8 +34,8 @@
#include <vector>
#include "almalloc.h"
+#include "alnumbers.h"
#include "alspan.h"
-#include "math_defs.h"
#include "opthelpers.h"
#include "phase_shifter.h"
#include "vector.h"
@@ -146,61 +146,61 @@ struct SpeakerPos {
};
/* Azimuth is counter-clockwise. */
-const SpeakerPos StereoMap[2]{
- { SF_CHANNEL_MAP_LEFT, Deg2Rad( 30.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_RIGHT, Deg2Rad(-30.0f), Deg2Rad(0.0f) },
+constexpr SpeakerPos StereoMap[2]{
+ { SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f },
+ { SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f },
}, QuadMap[4]{
- { SF_CHANNEL_MAP_LEFT, Deg2Rad( 45.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_RIGHT, Deg2Rad( -45.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_REAR_LEFT, Deg2Rad( 135.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_REAR_RIGHT, Deg2Rad(-135.0f), Deg2Rad(0.0f) },
+ { SF_CHANNEL_MAP_LEFT, 45.0f, 0.0f },
+ { SF_CHANNEL_MAP_RIGHT, -45.0f, 0.0f },
+ { SF_CHANNEL_MAP_REAR_LEFT, 135.0f, 0.0f },
+ { SF_CHANNEL_MAP_REAR_RIGHT, -135.0f, 0.0f },
}, X51Map[6]{
- { SF_CHANNEL_MAP_LEFT, Deg2Rad( 30.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_RIGHT, Deg2Rad( -30.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_CENTER, Deg2Rad( 0.0f), Deg2Rad(0.0f) },
+ { SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f },
+ { SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f },
+ { SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f },
{ SF_CHANNEL_MAP_LFE, 0.0f, 0.0f },
- { SF_CHANNEL_MAP_SIDE_LEFT, Deg2Rad( 110.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_SIDE_RIGHT, Deg2Rad(-110.0f), Deg2Rad(0.0f) },
+ { SF_CHANNEL_MAP_SIDE_LEFT, 110.0f, 0.0f },
+ { SF_CHANNEL_MAP_SIDE_RIGHT, -110.0f, 0.0f },
}, X51RearMap[6]{
- { SF_CHANNEL_MAP_LEFT, Deg2Rad( 30.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_RIGHT, Deg2Rad( -30.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_CENTER, Deg2Rad( 0.0f), Deg2Rad(0.0f) },
+ { SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f },
+ { SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f },
+ { SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f },
{ SF_CHANNEL_MAP_LFE, 0.0f, 0.0f },
- { SF_CHANNEL_MAP_REAR_LEFT, Deg2Rad( 110.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_REAR_RIGHT, Deg2Rad(-110.0f), Deg2Rad(0.0f) },
+ { SF_CHANNEL_MAP_REAR_LEFT, 110.0f, 0.0f },
+ { SF_CHANNEL_MAP_REAR_RIGHT, -110.0f, 0.0f },
}, X71Map[8]{
- { SF_CHANNEL_MAP_LEFT, Deg2Rad( 30.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_RIGHT, Deg2Rad( -30.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_CENTER, Deg2Rad( 0.0f), Deg2Rad(0.0f) },
+ { SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f },
+ { SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f },
+ { SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f },
{ SF_CHANNEL_MAP_LFE, 0.0f, 0.0f },
- { SF_CHANNEL_MAP_REAR_LEFT, Deg2Rad( 150.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_REAR_RIGHT, Deg2Rad(-150.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_SIDE_LEFT, Deg2Rad( 90.0f), Deg2Rad(0.0f) },
- { SF_CHANNEL_MAP_SIDE_RIGHT, Deg2Rad( -90.0f), Deg2Rad(0.0f) },
+ { SF_CHANNEL_MAP_REAR_LEFT, 150.0f, 0.0f },
+ { SF_CHANNEL_MAP_REAR_RIGHT, -150.0f, 0.0f },
+ { SF_CHANNEL_MAP_SIDE_LEFT, 90.0f, 0.0f },
+ { SF_CHANNEL_MAP_SIDE_RIGHT, -90.0f, 0.0f },
}, X714Map[12]{
- { SF_CHANNEL_MAP_LEFT, Deg2Rad( 30.0f), Deg2Rad( 0.0f) },
- { SF_CHANNEL_MAP_RIGHT, Deg2Rad( -30.0f), Deg2Rad( 0.0f) },
- { SF_CHANNEL_MAP_CENTER, Deg2Rad( 0.0f), Deg2Rad( 0.0f) },
+ { SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f },
+ { SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f },
+ { SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f },
{ SF_CHANNEL_MAP_LFE, 0.0f, 0.0f },
- { SF_CHANNEL_MAP_REAR_LEFT, Deg2Rad( 150.0f), Deg2Rad( 0.0f) },
- { SF_CHANNEL_MAP_REAR_RIGHT, Deg2Rad(-150.0f), Deg2Rad( 0.0f) },
- { SF_CHANNEL_MAP_SIDE_LEFT, Deg2Rad( 90.0f), Deg2Rad( 0.0f) },
- { SF_CHANNEL_MAP_SIDE_RIGHT, Deg2Rad( -90.0f), Deg2Rad( 0.0f) },
- { SF_CHANNEL_MAP_TOP_FRONT_LEFT, Deg2Rad( 45.0f), Deg2Rad(35.0f) },
- { SF_CHANNEL_MAP_TOP_FRONT_RIGHT, Deg2Rad( -45.0f), Deg2Rad(35.0f) },
- { SF_CHANNEL_MAP_TOP_REAR_LEFT, Deg2Rad( 135.0f), Deg2Rad(35.0f) },
- { SF_CHANNEL_MAP_TOP_REAR_RIGHT, Deg2Rad(-135.0f), Deg2Rad(35.0f) },
+ { SF_CHANNEL_MAP_REAR_LEFT, 150.0f, 0.0f },
+ { SF_CHANNEL_MAP_REAR_RIGHT, -150.0f, 0.0f },
+ { SF_CHANNEL_MAP_SIDE_LEFT, 90.0f, 0.0f },
+ { SF_CHANNEL_MAP_SIDE_RIGHT, -90.0f, 0.0f },
+ { SF_CHANNEL_MAP_TOP_FRONT_LEFT, 45.0f, 35.0f },
+ { SF_CHANNEL_MAP_TOP_FRONT_RIGHT, -45.0f, 35.0f },
+ { SF_CHANNEL_MAP_TOP_REAR_LEFT, 135.0f, 35.0f },
+ { SF_CHANNEL_MAP_TOP_REAR_RIGHT, -135.0f, 35.0f },
};
-inline std::array<float,4> GenCoeffs(float x /*+front*/, float y /*+left*/, float z /*+up*/)
+constexpr auto GenCoeffs(double x /*+front*/, double y /*+left*/, double z /*+up*/) noexcept
{
/* Coefficients are +3dB of FuMa. */
- std::array<float,4> coeffs;
- coeffs[0] = 1.0f;
- coeffs[1] = 1.41421356237f * x;
- coeffs[2] = 1.41421356237f * y;
- coeffs[3] = 1.41421356237f * z;
- return coeffs;
+ return std::array<float,4>{{
+ 1.0f,
+ static_cast<float>(al::numbers::sqrt2 * x),
+ static_cast<float>(al::numbers::sqrt2 * y),
+ static_cast<float>(al::numbers::sqrt2 * z)
+ }};
}
} // namespace
@@ -382,7 +382,7 @@ int main(int argc, char **argv)
/* B-Format is already in the correct order. It just needs a
* +3dB boost.
*/
- constexpr float scale{1.41421356237f};
+ constexpr float scale{al::numbers::sqrt2_v<float>};
const size_t chans{std::min<size_t>(static_cast<uint>(ininfo.channels), 4u)};
for(size_t c{0};c < chans;++c)
{
@@ -404,10 +404,11 @@ int main(int argc, char **argv)
srcmem[i] = inmem[i * static_cast<uint>(ininfo.channels)];
++inmem;
+ constexpr auto Deg2Rad = al::numbers::pi / 180.0;
const auto coeffs = GenCoeffs(
- std::cos(spkr.mAzimuth) * std::cos(spkr.mElevation),
- std::sin(spkr.mAzimuth) * std::cos(spkr.mElevation),
- std::sin(spkr.mElevation));
+ std::cos(spkr.mAzimuth*Deg2Rad) * std::cos(spkr.mElevation*Deg2Rad),
+ std::sin(spkr.mAzimuth*Deg2Rad) * std::cos(spkr.mElevation*Deg2Rad),
+ std::sin(spkr.mElevation*Deg2Rad));
for(size_t c{0};c < 4;++c)
{
for(size_t i{0};i < got;++i)