#ifndef ALU_H #define ALU_H #include #include #include #include #include "AL/al.h" #include "alcmain.h" #include "alspan.h" struct ALbufferlistitem; struct ALeffectslot; #define MAX_PITCH 10 #define MAX_SENDS 6 using MixerFunc = void(*)(const al::span InSamples, const al::span OutBuffer, float *CurrentGains, const float *TargetGains, const size_t Counter, const size_t OutPos); extern MixerFunc MixSamples; #define GAIN_MIX_MAX 1000.0f /* +60dB */ #define GAIN_SILENCE_THRESHOLD 0.00001f /* -100dB */ #define SPEEDOFSOUNDMETRESPERSEC 343.3f #define AIRABSORBGAINHF 0.99426f /* -0.05dB */ /* Target gain for the reverb decay feedback reaching the decay time. */ #define REVERB_DECAY_GAIN 0.001f /* -60 dB */ #define FRACTIONBITS 12 #define FRACTIONONE (1< CalcAmbiCoeffs(const float y, const float z, const float x, const float spread); /** * CalcDirectionCoeffs * * Calculates ambisonic coefficients based on an OpenAL direction vector. The * vector must be normalized (unit length), and the spread is the angular width * of the sound (0...tau). */ inline std::array CalcDirectionCoeffs(const float (&dir)[3], const float spread) { /* Convert from OpenAL coords to Ambisonics. */ return CalcAmbiCoeffs(-dir[0], dir[1], -dir[2], spread); } /** * CalcAngleCoeffs * * Calculates ambisonic coefficients based on azimuth and elevation. The * azimuth and elevation parameters are in radians, going right and up * respectively. */ inline std::array CalcAngleCoeffs(const float azimuth, const float elevation, const float spread) { const float x{-std::sin(azimuth) * std::cos(elevation)}; const float y{ std::sin(elevation)}; const float z{ std::cos(azimuth) * std::cos(elevation)}; return CalcAmbiCoeffs(x, y, z, spread); } /** * ComputePanGains * * Computes panning gains using the given channel decoder coefficients and the * pre-calculated direction or angle coefficients. For B-Format sources, the * 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 float*RESTRICT coeffs, const float ingain, const al::span gains); /** Helper to set an identity/pass-through panning for ambisonic mixing (3D input). */ template auto SetAmbiPanIdentity(T iter, I count, F func) -> std::enable_if_t::value> { if(count < 1) return; std::array coeffs{{1.0f}}; func(*iter, coeffs); ++iter; for(I i{1};i < count;++i,++iter) { coeffs[i-1] = 0.0f; coeffs[i ] = 1.0f; func(*iter, coeffs); } } extern const float ConeScale; extern const float ZScale; #endif