48 static constexpr int_least32_t SCALE_FACTOR = 1 << 16;
50#ifdef __cpp_lib_math_constants
51 static constexpr double SQRT_2 = std::numbers::sqrt2;
52 static constexpr double SQRT_3 = std::numbers::sqrt3;
54 static constexpr double SQRT_2 = 1.41421356237;
55 static constexpr double SQRT_3 = 1.73205080757;
58 static constexpr int_least32_t SCALE[3] = {
60 static_cast<int_least32_t
>((1.0 / SQRT_2) * SCALE_FACTOR),
61 static_cast<int_least32_t
>((1.0 / SQRT_3) * SCALE_FACTOR)
65 using mixer_func_t = int_least32_t (
SimpleMixer::*)()
const;
68 std::vector<short*> m_buffers;
70 std::vector<int_least32_t> m_iSamples;
72 std::vector<mixer_func_t> m_mix;
95 int_least32_t mono()
const
97 int_least32_t res = 0;
98 for (
int i = 0; i < Chips; i++)
100 return res * SCALE[Chips-1] / SCALE_FACTOR;
104 int_least32_t stereo_OneChip()
const {
return m_iSamples[0]; }
106 int_least32_t stereo_ch1_TwoChips()
const
108 return (m_iSamples[0] + 0.5*m_iSamples[1]) * SCALE[1] / SCALE_FACTOR;
110 int_least32_t stereo_ch2_TwoChips()
const
112 return (0.5*m_iSamples[0] + m_iSamples[1]) * SCALE[1] / SCALE_FACTOR;
115 int_least32_t stereo_ch1_ThreeChips()
const
117 return (m_iSamples[0] + m_iSamples[1] + 0.5*m_iSamples[2]) * SCALE[2] / SCALE_FACTOR;
119 int_least32_t stereo_ch2_ThreeChips()
const
121 return (0.5*m_iSamples[0] + m_iSamples[1] + m_iSamples[2]) * SCALE[2] / SCALE_FACTOR;
132 SimpleMixer(
bool stereo,
short** buffers,
int chips);
137 unsigned int doMix(
short *buffer,
unsigned int samples);