11 #include "mixer/defs.h"
16 MixerOutFunc MixSamplesOut{Mix_<CTag>};
17 MixerOneFunc MixSamplesOne{Mix_<CTag>};
20 std::array<float,MaxAmbiChannels> CalcAmbiCoeffs(const float y, const float z, const float x,
23 std::array<float,MaxAmbiChannels> coeffs{CalcAmbiCoeffs(y, z, x)};
27 /* Implement the spread by using a spherical source that subtends the
29 * http://www.ppsloan.org/publications/StupidSH36.pdf - Appendix A3
31 * When adjusted for N3D normalization instead of SN3D, these
34 * ZH0 = -sqrt(pi) * (-1+ca);
35 * ZH1 = 0.5*sqrt(pi) * sa*sa;
36 * ZH2 = -0.5*sqrt(pi) * ca*(-1+ca)*(ca+1);
37 * ZH3 = -0.125*sqrt(pi) * (-1+ca)*(ca+1)*(5*ca*ca - 1);
38 * ZH4 = -0.125*sqrt(pi) * ca*(-1+ca)*(ca+1)*(7*ca*ca - 3);
39 * ZH5 = -0.0625*sqrt(pi) * (-1+ca)*(ca+1)*(21*ca*ca*ca*ca - 14*ca*ca + 1);
41 * The gain of the source is compensated for size, so that the
42 * loudness doesn't depend on the spread. Thus:
45 * ZH1 = 0.5f * (ca+1.0f);
46 * ZH2 = 0.5f * (ca+1.0f)*ca;
47 * ZH3 = 0.125f * (ca+1.0f)*(5.0f*ca*ca - 1.0f);
48 * ZH4 = 0.125f * (ca+1.0f)*(7.0f*ca*ca - 3.0f)*ca;
49 * ZH5 = 0.0625f * (ca+1.0f)*(21.0f*ca*ca*ca*ca - 14.0f*ca*ca + 1.0f);
51 const float ca{std::cos(spread * 0.5f)};
52 /* Increase the source volume by up to +3dB for a full spread. */
53 const float scale{std::sqrt(1.0f + al::numbers::inv_pi_v<float>/2.0f*spread)};
55 const float ZH0_norm{scale};
56 const float ZH1_norm{scale * 0.5f * (ca+1.f)};
57 const float ZH2_norm{scale * 0.5f * (ca+1.f)*ca};
58 const float ZH3_norm{scale * 0.125f * (ca+1.f)*(5.f*ca*ca-1.f)};
61 coeffs[0] *= ZH0_norm;
63 coeffs[1] *= ZH1_norm;
64 coeffs[2] *= ZH1_norm;
65 coeffs[3] *= ZH1_norm;
67 coeffs[4] *= ZH2_norm;
68 coeffs[5] *= ZH2_norm;
69 coeffs[6] *= ZH2_norm;
70 coeffs[7] *= ZH2_norm;
71 coeffs[8] *= ZH2_norm;
73 coeffs[9] *= ZH3_norm;
74 coeffs[10] *= ZH3_norm;
75 coeffs[11] *= ZH3_norm;
76 coeffs[12] *= ZH3_norm;
77 coeffs[13] *= ZH3_norm;
78 coeffs[14] *= ZH3_norm;
79 coeffs[15] *= ZH3_norm;
85 void ComputePanGains(const MixParams *mix, const float*RESTRICT coeffs, const float ingain,
86 const al::span<float,MaxAmbiChannels> gains)
88 auto ambimap = mix->AmbiMap.cbegin();
90 auto iter = std::transform(ambimap, ambimap+mix->Buffer.size(), gains.begin(),
91 [coeffs,ingain](const BFChannelConfig &chanmap) noexcept -> float
92 { return chanmap.Scale * coeffs[chanmap.Index] * ingain; }
94 std::fill(iter, gains.end(), 0.0f);