diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/device.h | 36 | ||||
-rw-r--r-- | core/mixer.h | 18 |
2 files changed, 33 insertions, 21 deletions
diff --git a/core/device.h b/core/device.h index 6317067e..7d50c54d 100644 --- a/core/device.h +++ b/core/device.h @@ -95,6 +95,8 @@ struct DistanceComp { }; +#define INVALID_CHANNEL_INDEX ~0u + struct BFChannelConfig { float Scale; uint Index; @@ -105,6 +107,37 @@ struct MixParams { std::array<BFChannelConfig,MaxAmbiChannels> AmbiMap{}; al::span<FloatBufferLine> Buffer; + + /** + * Helper to set an identity/pass-through panning for ambisonic mixing. The + * source is expected to be a 3D ACN/N3D ambisonic buffer, and for each + * channel [0...count), the given functor is called with the source channel + * index, destination channel index, and the gain for that channel. If the + * destination channel is INVALID_CHANNEL_INDEX, the given source channel + * is not used for output. + */ + template<typename F> + void setAmbiMixParams(const MixParams &inmix, const float gainbase, F func) const + { + const size_t numIn{inmix.Buffer.size()}; + const size_t numOut{Buffer.size()}; + for(size_t i{0};i < numIn;++i) + { + auto idx = INVALID_CHANNEL_INDEX; + auto gain = 0.0f; + + for(size_t j{0};j < numOut;++j) + { + if(AmbiMap[j].Index == inmix.AmbiMap[i].Index) + { + idx = static_cast<uint>(j); + gain = AmbiMap[j].Scale * gainbase; + break; + } + } + func(i, idx, gain); + } + } }; struct RealMixParams { @@ -303,13 +336,10 @@ private: uint renderSamples(const uint numSamples); }; - /* Must be less than 15 characters (16 including terminating null) for * compatibility with pthread_setname_np limitations. */ #define MIXER_THREAD_NAME "alsoft-mixer" #define RECORD_THREAD_NAME "alsoft-record" -#define INVALID_CHANNEL_INDEX ~0u - #endif /* CORE_DEVICE_H */ diff --git a/core/mixer.h b/core/mixer.h index 8624996f..66bcb170 100644 --- a/core/mixer.h +++ b/core/mixer.h @@ -92,22 +92,4 @@ inline std::array<float,MaxAmbiChannels> CalcAngleCoeffs(const float azimuth, void ComputePanGains(const MixParams *mix, const float*RESTRICT coeffs, const float ingain, const al::span<float,MaxAmbiChannels> gains); - -/** Helper to set an identity/pass-through panning for ambisonic mixing (3D input). */ -template<typename T, typename I, typename F> -auto SetAmbiPanIdentity(T iter, I count, F func) -> std::enable_if_t<std::is_integral<I>::value> -{ - if(count < 1) return; - - std::array<float,MaxAmbiChannels> 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); - } -} - #endif /* CORE_MIXER_H */ |