44 static constexpr int_least32_t SCALE_FACTOR = 1 << 16;
46#ifdef __cpp_lib_math_constants
47 static constexpr double SQRT_2 = std::numbers::sqrt2;
48 static constexpr double SQRT_3 = std::numbers::sqrt3;
50 static constexpr double SQRT_2 = 1.41421356237;
51 static constexpr double SQRT_3 = 1.73205080757;
54 static constexpr int_least32_t SCALE[3] = {
56 static_cast<int_least32_t
>((1.0 / SQRT_2) * SCALE_FACTOR),
57 static_cast<int_least32_t
>((1.0 / SQRT_3) * SCALE_FACTOR)
61 using mixer_func_t = int_least32_t (
SimpleMixer::*)()
const;
64 std::vector<short*> m_buffers;
66 std::vector<int_least32_t> m_iSamples;
68 std::vector<mixer_func_t> m_mix;
91 int_least32_t mono()
const
93 int_least32_t res = 0;
94 for (
int i = 0; i < Chips; i++)
96 return res * SCALE[Chips-1] / SCALE_FACTOR;
100 int_least32_t stereo_OneChip()
const {
return m_iSamples[0]; }
102 int_least32_t stereo_ch1_TwoChips()
const
104 return (m_iSamples[0] + 0.5*m_iSamples[1]) * SCALE[1] / SCALE_FACTOR;
106 int_least32_t stereo_ch2_TwoChips()
const
108 return (0.5*m_iSamples[0] + m_iSamples[1]) * SCALE[1] / SCALE_FACTOR;
111 int_least32_t stereo_ch1_ThreeChips()
const
113 return (m_iSamples[0] + m_iSamples[1] + 0.5*m_iSamples[2]) * SCALE[2] / SCALE_FACTOR;
115 int_least32_t stereo_ch2_ThreeChips()
const
117 return (0.5*m_iSamples[0] + m_iSamples[1] + m_iSamples[2]) * SCALE[2] / SCALE_FACTOR;
128 SimpleMixer(
bool stereo,
short** buffers,
int chips);
133 unsigned int doMix(
short *buffer,
unsigned int samples);