diff options
author | Chris Robinson <[email protected]> | 2019-10-05 20:00:22 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-10-05 20:00:22 -0700 |
commit | eb89faf9632048568c953c21a6b58e4c4664cc05 (patch) | |
tree | b4e3de1b1535c81ba9be75ce0558e35b5c9a88a0 /alc | |
parent | 267b79f337f2189542ce2582aeed84b84c6e987e (diff) |
Use a span instead of a reference-to-array
Diffstat (limited to 'alc')
-rw-r--r-- | alc/alu.h | 19 | ||||
-rw-r--r-- | alc/panning.cpp | 25 |
2 files changed, 24 insertions, 20 deletions
@@ -93,8 +93,8 @@ void aluInitEffectPanning(ALeffectslot *slot, ALCdevice *device); * The components are ordered such that OpenAL's X, Y, and Z are the first, * second, and third parameters respectively -- simply negate X and Z. */ -void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALfloat spread, - ALfloat (&coeffs)[MAX_AMBI_CHANNELS]); +void CalcAmbiCoeffs(const float y, const float z, const float x, const float spread, + const al::span<float,MAX_AMBI_CHANNELS> coeffs); /** * CalcDirectionCoeffs @@ -103,7 +103,8 @@ void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALf * vector must be normalized (unit length), and the spread is the angular width * of the sound (0...tau). */ -inline void CalcDirectionCoeffs(const ALfloat (&dir)[3], ALfloat spread, ALfloat (&coeffs)[MAX_AMBI_CHANNELS]) +inline void CalcDirectionCoeffs(const float (&dir)[3], const float spread, + const al::span<float,MAX_AMBI_CHANNELS> coeffs) { /* Convert from OpenAL coords to Ambisonics. */ CalcAmbiCoeffs(-dir[0], dir[1], -dir[2], spread, coeffs); @@ -116,11 +117,12 @@ inline void CalcDirectionCoeffs(const ALfloat (&dir)[3], ALfloat spread, ALfloat * azimuth and elevation parameters are in radians, going right and up * respectively. */ -inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat (&coeffs)[MAX_AMBI_CHANNELS]) +inline void CalcAngleCoeffs(const float azimuth, const float elevation, const float spread, + const al::span<float,MAX_AMBI_CHANNELS> coeffs) { - ALfloat x = -std::sin(azimuth) * std::cos(elevation); - ALfloat y = std::sin(elevation); - ALfloat z = std::cos(azimuth) * std::cos(elevation); + const float x{-std::sin(azimuth) * std::cos(elevation)}; + const float y{ std::sin(elevation)}; + const float z{ std::cos(azimuth) * std::cos(elevation)}; CalcAmbiCoeffs(x, y, z, spread, coeffs); } @@ -134,7 +136,8 @@ inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, * coeffs are a 'slice' of a transform matrix for the input channel, used to * scale and orient the sound samples. */ -void ComputePanGains(const MixParams *mix, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]); +void ComputePanGains(const MixParams *mix, const float*RESTRICT coeffs, const float ingain, + const al::span<float,MAX_OUTPUT_CHANNELS> gains); inline std::array<ALfloat,MAX_AMBI_CHANNELS> GetAmbiIdentityRow(size_t i) noexcept diff --git a/alc/panning.cpp b/alc/panning.cpp index c2bcf223..df0b870a 100644 --- a/alc/panning.cpp +++ b/alc/panning.cpp @@ -874,8 +874,8 @@ void aluInitEffectPanning(ALeffectslot *slot, ALCdevice *device) } -void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALfloat spread, - ALfloat (&coeffs)[MAX_AMBI_CHANNELS]) +void CalcAmbiCoeffs(const float y, const float z, const float x, const float spread, + const al::span<float,MAX_AMBI_CHANNELS> coeffs) { /* Zeroth-order */ coeffs[0] = 1.0f; /* ACN 0 = 1 */ @@ -934,14 +934,14 @@ void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALf * ZH4 = 0.125f * (ca+1.0f)*(7.0f*ca*ca - 3.0f)*ca; * ZH5 = 0.0625f * (ca+1.0f)*(21.0f*ca*ca*ca*ca - 14.0f*ca*ca + 1.0f); */ - ALfloat ca = std::cos(spread * 0.5f); + const float ca{std::cos(spread * 0.5f)}; /* Increase the source volume by up to +3dB for a full spread. */ - ALfloat scale = std::sqrt(1.0f + spread/al::MathDefs<float>::Tau()); + const float scale{std::sqrt(1.0f + spread/al::MathDefs<float>::Tau())}; - ALfloat ZH0_norm = scale; - ALfloat ZH1_norm = 0.5f * (ca+1.f) * scale; - ALfloat ZH2_norm = 0.5f * (ca+1.f)*ca * scale; - ALfloat ZH3_norm = 0.125f * (ca+1.f)*(5.f*ca*ca-1.f) * scale; + const float ZH0_norm{scale}; + const float ZH1_norm{scale * 0.5f * (ca+1.f)}; + const float ZH2_norm{scale * 0.5f * (ca+1.f)*ca}; + const float ZH3_norm{scale * 0.125f * (ca+1.f)*(5.f*ca*ca-1.f)}; /* Zeroth-order */ coeffs[0] *= ZH0_norm; @@ -966,13 +966,14 @@ void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALf } } -void ComputePanGains(const MixParams *mix, const ALfloat *RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS]) +void ComputePanGains(const MixParams *mix, const float*RESTRICT coeffs, const float ingain, + const al::span<float,MAX_OUTPUT_CHANNELS> gains) { auto ambimap = mix->AmbiMap.cbegin(); - auto iter = std::transform(ambimap, ambimap+mix->Buffer.size(), std::begin(gains), - [coeffs,ingain](const BFChannelConfig &chanmap) noexcept -> ALfloat + auto iter = std::transform(ambimap, ambimap+mix->Buffer.size(), gains.begin(), + [coeffs,ingain](const BFChannelConfig &chanmap) noexcept -> float { return chanmap.Scale * coeffs[chanmap.Index] * ingain; } ); - std::fill(iter, std::end(gains), 0.0f); + std::fill(iter, gains.end(), 0.0f); } |