2026-08-04 03:33:53 +01:00
|
|
|
#include "Mixer.hpp"
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
|
|
template <uint32_t NumInputs>
|
2026-08-05 13:46:38 +01:00
|
|
|
Mixer<NumInputs>::Mixer(float initGain) : normalise_(false) {
|
2026-08-04 03:33:53 +01:00
|
|
|
for (uint32_t i = 0; i < NumInputs; ++i) {
|
2026-08-05 13:46:38 +01:00
|
|
|
gains_[i] = initGain;
|
2026-08-04 03:33:53 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <uint32_t NumInputs>
|
|
|
|
|
void Mixer<NumInputs>::process(const float **inputs, float *out,
|
|
|
|
|
uint32_t frames) {
|
|
|
|
|
mixChannels(inputs, out, frames);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <uint32_t NumInputs>
|
|
|
|
|
void Mixer<NumInputs>::processStereo(const float **inputsL,
|
|
|
|
|
const float **inputsR, float *outL,
|
|
|
|
|
float *outR, uint32_t frames) {
|
|
|
|
|
mixChannels(inputsL, outL, frames);
|
|
|
|
|
mixChannels(inputsR, outR, frames);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <uint32_t NumInputs>
|
|
|
|
|
void Mixer<NumInputs>::mixChannels(const float **inputs, float *out,
|
|
|
|
|
uint32_t frames) {
|
|
|
|
|
float scale = normalise_ ? (1.0f / NumInputs) : 1.0f;
|
|
|
|
|
for (uint32_t i = 0; i < frames; ++i) {
|
|
|
|
|
float sum = 0.0f;
|
|
|
|
|
for (uint32_t j = 0; j < NumInputs; ++j) {
|
|
|
|
|
sum += inputs[j][i] * (gains_[j] * scale);
|
|
|
|
|
}
|
|
|
|
|
out[i] = sum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <uint32_t NumInputs>
|
|
|
|
|
void Mixer<NumInputs>::setInputGain(uint32_t index, float gain) {
|
|
|
|
|
gains_[index] = gain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <uint32_t NumInputs>
|
|
|
|
|
float Mixer<NumInputs>::getInputGain(uint32_t index) const {
|
|
|
|
|
return isValidInputIndex(index) ? gains_[index] : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <uint32_t NumInputs> void Mixer<NumInputs>::setNormalise(bool norm) {
|
|
|
|
|
normalise_ = norm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <uint32_t NumInputs> bool Mixer<NumInputs>::getNormalise() const {
|
|
|
|
|
return normalise_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <uint32_t NumInputs>
|
|
|
|
|
bool Mixer<NumInputs>::isValidInputIndex(float index) const {
|
|
|
|
|
return index >= 0 && index < NumInputs;
|
|
|
|
|
}
|