Avoid AL types in the mixer
This commit is contained in:
+8
-9
@@ -1,8 +1,6 @@
|
||||
#ifndef MIXER_DEFS_H
|
||||
#define MIXER_DEFS_H
|
||||
|
||||
#include "AL/al.h"
|
||||
|
||||
#include "alcmain.h"
|
||||
#include "alspan.h"
|
||||
#include "alu.h"
|
||||
@@ -11,20 +9,22 @@
|
||||
union InterpState;
|
||||
struct MixHrtfFilter;
|
||||
|
||||
using uint = unsigned int;
|
||||
|
||||
|
||||
template<typename TypeTag, typename InstTag>
|
||||
const float *Resample_(const InterpState *state, const float *RESTRICT src, ALuint frac,
|
||||
ALuint increment, const al::span<float> dst);
|
||||
const float *Resample_(const InterpState *state, const float *RESTRICT src, uint frac,
|
||||
uint increment, const al::span<float> dst);
|
||||
|
||||
template<typename InstTag>
|
||||
void Mix_(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer,
|
||||
float *CurrentGains, const float *TargetGains, const size_t Counter, const size_t OutPos);
|
||||
|
||||
template<typename InstTag>
|
||||
void MixHrtf_(const float *InSamples, float2 *AccumSamples, const ALuint IrSize,
|
||||
void MixHrtf_(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
||||
const MixHrtfFilter *hrtfparams, const size_t BufferSize);
|
||||
template<typename InstTag>
|
||||
void MixHrtfBlend_(const float *InSamples, float2 *AccumSamples, const ALuint IrSize,
|
||||
void MixHrtfBlend_(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
||||
const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize);
|
||||
template<typename InstTag>
|
||||
void MixDirectHrtf_(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
|
||||
@@ -32,14 +32,13 @@ void MixDirectHrtf_(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
|
||||
const size_t BufferSize);
|
||||
|
||||
/* Vectorized resampler helpers */
|
||||
inline void InitPosArrays(ALuint frac, ALuint increment, ALuint *frac_arr, ALuint *pos_arr,
|
||||
size_t size)
|
||||
inline void InitPosArrays(uint frac, uint increment, uint *frac_arr, uint *pos_arr, size_t size)
|
||||
{
|
||||
pos_arr[0] = 0;
|
||||
frac_arr[0] = frac;
|
||||
for(size_t i{1};i < size;i++)
|
||||
{
|
||||
const ALuint frac_tmp{frac_arr[i-1] + increment};
|
||||
const uint frac_tmp{frac_arr[i-1] + increment};
|
||||
pos_arr[i] = pos_arr[i-1] + (frac_tmp>>MixerFracBits);
|
||||
frac_arr[i] = frac_tmp&MixerFracMask;
|
||||
}
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
#include "voice.h"
|
||||
|
||||
|
||||
using uint = unsigned int;
|
||||
|
||||
using ApplyCoeffsT = void(&)(float2 *RESTRICT Values, const uint_fast32_t irSize,
|
||||
const HrirArray &Coeffs, const float left, const float right);
|
||||
|
||||
template<ApplyCoeffsT ApplyCoeffs>
|
||||
inline void MixHrtfBase(const float *InSamples, float2 *RESTRICT AccumSamples, const ALuint IrSize,
|
||||
inline void MixHrtfBase(const float *InSamples, float2 *RESTRICT AccumSamples, const uint IrSize,
|
||||
const MixHrtfFilter *hrtfparams, const size_t BufferSize)
|
||||
{
|
||||
ASSUME(BufferSize > 0);
|
||||
@@ -38,7 +40,7 @@ inline void MixHrtfBase(const float *InSamples, float2 *RESTRICT AccumSamples, c
|
||||
|
||||
template<ApplyCoeffsT ApplyCoeffs>
|
||||
inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSamples,
|
||||
const ALuint IrSize, const HrtfFilter *oldparams, const MixHrtfFilter *newparams,
|
||||
const uint IrSize, const HrtfFilter *oldparams, const MixHrtfFilter *newparams,
|
||||
const size_t BufferSize)
|
||||
{
|
||||
ASSUME(BufferSize > 0);
|
||||
|
||||
+20
-20
@@ -21,21 +21,21 @@ struct FastBSincTag;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr ALuint FracPhaseBitDiff{MixerFracBits - BSincPhaseBits};
|
||||
constexpr ALuint FracPhaseDiffOne{1 << FracPhaseBitDiff};
|
||||
constexpr uint FracPhaseBitDiff{MixerFracBits - BSincPhaseBits};
|
||||
constexpr uint FracPhaseDiffOne{1 << FracPhaseBitDiff};
|
||||
|
||||
inline float do_point(const InterpState&, const float *RESTRICT vals, const ALuint)
|
||||
inline float do_point(const InterpState&, const float *RESTRICT vals, const uint)
|
||||
{ return vals[0]; }
|
||||
inline float do_lerp(const InterpState&, const float *RESTRICT vals, const ALuint frac)
|
||||
inline float do_lerp(const InterpState&, const float *RESTRICT vals, const uint frac)
|
||||
{ return lerp(vals[0], vals[1], static_cast<float>(frac)*(1.0f/MixerFracOne)); }
|
||||
inline float do_cubic(const InterpState&, const float *RESTRICT vals, const ALuint frac)
|
||||
inline float do_cubic(const InterpState&, const float *RESTRICT vals, const uint frac)
|
||||
{ return cubic(vals[0], vals[1], vals[2], vals[3], static_cast<float>(frac)*(1.0f/MixerFracOne)); }
|
||||
inline float do_bsinc(const InterpState &istate, const float *RESTRICT vals, const ALuint frac)
|
||||
inline float do_bsinc(const InterpState &istate, const float *RESTRICT vals, const uint frac)
|
||||
{
|
||||
const size_t m{istate.bsinc.m};
|
||||
|
||||
// Calculate the phase index and factor.
|
||||
const ALuint pi{frac >> FracPhaseBitDiff};
|
||||
const uint pi{frac >> FracPhaseBitDiff};
|
||||
const float pf{static_cast<float>(frac & (FracPhaseDiffOne-1)) * (1.0f/FracPhaseDiffOne)};
|
||||
|
||||
const float *fil{istate.bsinc.filter + m*pi*4};
|
||||
@@ -49,12 +49,12 @@ inline float do_bsinc(const InterpState &istate, const float *RESTRICT vals, con
|
||||
r += (fil[j_f] + istate.bsinc.sf*scd[j_f] + pf*(phd[j_f] + istate.bsinc.sf*spd[j_f])) * vals[j_f];
|
||||
return r;
|
||||
}
|
||||
inline float do_fastbsinc(const InterpState &istate, const float *RESTRICT vals, const ALuint frac)
|
||||
inline float do_fastbsinc(const InterpState &istate, const float *RESTRICT vals, const uint frac)
|
||||
{
|
||||
const size_t m{istate.bsinc.m};
|
||||
|
||||
// Calculate the phase index and factor.
|
||||
const ALuint pi{frac >> FracPhaseBitDiff};
|
||||
const uint pi{frac >> FracPhaseBitDiff};
|
||||
const float pf{static_cast<float>(frac & (FracPhaseDiffOne-1)) * (1.0f/FracPhaseDiffOne)};
|
||||
|
||||
const float *fil{istate.bsinc.filter + m*pi*4};
|
||||
@@ -67,10 +67,10 @@ inline float do_fastbsinc(const InterpState &istate, const float *RESTRICT vals,
|
||||
return r;
|
||||
}
|
||||
|
||||
using SamplerT = float(&)(const InterpState&, const float*RESTRICT, const ALuint);
|
||||
using SamplerT = float(&)(const InterpState&, const float*RESTRICT, const uint);
|
||||
template<SamplerT Sampler>
|
||||
const float *DoResample(const InterpState *state, const float *RESTRICT src, ALuint frac,
|
||||
ALuint increment, const al::span<float> dst)
|
||||
const float *DoResample(const InterpState *state, const float *RESTRICT src, uint frac,
|
||||
uint increment, const al::span<float> dst)
|
||||
{
|
||||
const InterpState istate{*state};
|
||||
for(float &out : dst)
|
||||
@@ -98,7 +98,7 @@ inline void ApplyCoeffs(float2 *RESTRICT Values, const uint_fast32_t IrSize,
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
const float *Resample_<CopyTag,CTag>(const InterpState*, const float *RESTRICT src, ALuint, ALuint,
|
||||
const float *Resample_<CopyTag,CTag>(const InterpState*, const float *RESTRICT src, uint, uint,
|
||||
const al::span<float> dst)
|
||||
{
|
||||
#if defined(HAVE_SSE) || defined(HAVE_NEON)
|
||||
@@ -112,37 +112,37 @@ const float *Resample_<CopyTag,CTag>(const InterpState*, const float *RESTRICT s
|
||||
|
||||
template<>
|
||||
const float *Resample_<PointTag,CTag>(const InterpState *state, const float *RESTRICT src,
|
||||
ALuint frac, ALuint increment, const al::span<float> dst)
|
||||
uint frac, uint increment, const al::span<float> dst)
|
||||
{ return DoResample<do_point>(state, src, frac, increment, dst); }
|
||||
|
||||
template<>
|
||||
const float *Resample_<LerpTag,CTag>(const InterpState *state, const float *RESTRICT src,
|
||||
ALuint frac, ALuint increment, const al::span<float> dst)
|
||||
uint frac, uint increment, const al::span<float> dst)
|
||||
{ return DoResample<do_lerp>(state, src, frac, increment, dst); }
|
||||
|
||||
template<>
|
||||
const float *Resample_<CubicTag,CTag>(const InterpState *state, const float *RESTRICT src,
|
||||
ALuint frac, ALuint increment, const al::span<float> dst)
|
||||
uint frac, uint increment, const al::span<float> dst)
|
||||
{ return DoResample<do_cubic>(state, src-1, frac, increment, dst); }
|
||||
|
||||
template<>
|
||||
const float *Resample_<BSincTag,CTag>(const InterpState *state, const float *RESTRICT src,
|
||||
ALuint frac, ALuint increment, const al::span<float> dst)
|
||||
uint frac, uint increment, const al::span<float> dst)
|
||||
{ return DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst); }
|
||||
|
||||
template<>
|
||||
const float *Resample_<FastBSincTag,CTag>(const InterpState *state, const float *RESTRICT src,
|
||||
ALuint frac, ALuint increment, const al::span<float> dst)
|
||||
uint frac, uint increment, const al::span<float> dst)
|
||||
{ return DoResample<do_fastbsinc>(state, src-state->bsinc.l, frac, increment, dst); }
|
||||
|
||||
|
||||
template<>
|
||||
void MixHrtf_<CTag>(const float *InSamples, float2 *AccumSamples, const ALuint IrSize,
|
||||
void MixHrtf_<CTag>(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
||||
const MixHrtfFilter *hrtfparams, const size_t BufferSize)
|
||||
{ MixHrtfBase<ApplyCoeffs>(InSamples, AccumSamples, IrSize, hrtfparams, BufferSize); }
|
||||
|
||||
template<>
|
||||
void MixHrtfBlend_<CTag>(const float *InSamples, float2 *AccumSamples, const ALuint IrSize,
|
||||
void MixHrtfBlend_<CTag>(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
||||
const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize)
|
||||
{
|
||||
MixHrtfBlendBase<ApplyCoeffs>(InSamples, AccumSamples, IrSize, oldparams, newparams,
|
||||
|
||||
+13
-13
@@ -31,8 +31,8 @@ inline float32x4_t set_f4(float l0, float l1, float l2, float l3)
|
||||
return ret;
|
||||
}
|
||||
|
||||
constexpr ALuint FracPhaseBitDiff{MixerFracBits - BSincPhaseBits};
|
||||
constexpr ALuint FracPhaseDiffOne{1 << FracPhaseBitDiff};
|
||||
constexpr uint FracPhaseBitDiff{MixerFracBits - BSincPhaseBits};
|
||||
constexpr uint FracPhaseDiffOne{1 << FracPhaseBitDiff};
|
||||
|
||||
inline void ApplyCoeffs(float2 *RESTRICT Values, const uint_fast32_t IrSize,
|
||||
const HrirArray &Coeffs, const float left, const float right)
|
||||
@@ -60,13 +60,13 @@ inline void ApplyCoeffs(float2 *RESTRICT Values, const uint_fast32_t IrSize,
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
const float *Resample_<LerpTag,NEONTag>(const InterpState*, const float *RESTRICT src, ALuint frac,
|
||||
ALuint increment, const al::span<float> dst)
|
||||
const float *Resample_<LerpTag,NEONTag>(const InterpState*, const float *RESTRICT src, uint frac,
|
||||
uint increment, const al::span<float> dst)
|
||||
{
|
||||
const int32x4_t increment4 = vdupq_n_s32(static_cast<int>(increment*4));
|
||||
const float32x4_t fracOne4 = vdupq_n_f32(1.0f/MixerFracOne);
|
||||
const int32x4_t fracMask4 = vdupq_n_s32(MixerFracMask);
|
||||
alignas(16) ALuint pos_[4], frac_[4];
|
||||
alignas(16) uint pos_[4], frac_[4];
|
||||
int32x4_t pos4, frac4;
|
||||
|
||||
InitPosArrays(frac, increment, frac_, pos_, 4);
|
||||
@@ -98,8 +98,8 @@ const float *Resample_<LerpTag,NEONTag>(const InterpState*, const float *RESTRIC
|
||||
|
||||
if(size_t todo{dst.size()&3})
|
||||
{
|
||||
src += static_cast<ALuint>(vgetq_lane_s32(pos4, 0));
|
||||
frac = static_cast<ALuint>(vgetq_lane_s32(frac4, 0));
|
||||
src += static_cast<uint>(vgetq_lane_s32(pos4, 0));
|
||||
frac = static_cast<uint>(vgetq_lane_s32(frac4, 0));
|
||||
|
||||
do {
|
||||
*(dst_iter++) = lerp(src[0], src[1], static_cast<float>(frac) * (1.0f/MixerFracOne));
|
||||
@@ -114,7 +114,7 @@ const float *Resample_<LerpTag,NEONTag>(const InterpState*, const float *RESTRIC
|
||||
|
||||
template<>
|
||||
const float *Resample_<BSincTag,NEONTag>(const InterpState *state, const float *RESTRICT src,
|
||||
ALuint frac, ALuint increment, const al::span<float> dst)
|
||||
uint frac, uint increment, const al::span<float> dst)
|
||||
{
|
||||
const float *const filter{state->bsinc.filter};
|
||||
const float32x4_t sf4{vdupq_n_f32(state->bsinc.sf)};
|
||||
@@ -124,7 +124,7 @@ const float *Resample_<BSincTag,NEONTag>(const InterpState *state, const float *
|
||||
for(float &out_sample : dst)
|
||||
{
|
||||
// Calculate the phase index and factor.
|
||||
const ALuint pi{frac >> FracPhaseBitDiff};
|
||||
const uint pi{frac >> FracPhaseBitDiff};
|
||||
const float pf{static_cast<float>(frac & (FracPhaseDiffOne-1)) * (1.0f/FracPhaseDiffOne)};
|
||||
|
||||
// Apply the scale and phase interpolated filter.
|
||||
@@ -160,7 +160,7 @@ const float *Resample_<BSincTag,NEONTag>(const InterpState *state, const float *
|
||||
|
||||
template<>
|
||||
const float *Resample_<FastBSincTag,NEONTag>(const InterpState *state,
|
||||
const float *RESTRICT src, ALuint frac, ALuint increment, const al::span<float> dst)
|
||||
const float *RESTRICT src, uint frac, uint increment, const al::span<float> dst)
|
||||
{
|
||||
const float *const filter{state->bsinc.filter};
|
||||
const size_t m{state->bsinc.m};
|
||||
@@ -169,7 +169,7 @@ const float *Resample_<FastBSincTag,NEONTag>(const InterpState *state,
|
||||
for(float &out_sample : dst)
|
||||
{
|
||||
// Calculate the phase index and factor.
|
||||
const ALuint pi{frac >> FracPhaseBitDiff};
|
||||
const uint pi{frac >> FracPhaseBitDiff};
|
||||
const float pf{static_cast<float>(frac & (FracPhaseDiffOne-1)) * (1.0f/FracPhaseDiffOne)};
|
||||
|
||||
// Apply the phase interpolated filter.
|
||||
@@ -201,12 +201,12 @@ const float *Resample_<FastBSincTag,NEONTag>(const InterpState *state,
|
||||
|
||||
|
||||
template<>
|
||||
void MixHrtf_<NEONTag>(const float *InSamples, float2 *AccumSamples, const ALuint IrSize,
|
||||
void MixHrtf_<NEONTag>(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
||||
const MixHrtfFilter *hrtfparams, const size_t BufferSize)
|
||||
{ MixHrtfBase<ApplyCoeffs>(InSamples, AccumSamples, IrSize, hrtfparams, BufferSize); }
|
||||
|
||||
template<>
|
||||
void MixHrtfBlend_<NEONTag>(const float *InSamples, float2 *AccumSamples, const ALuint IrSize,
|
||||
void MixHrtfBlend_<NEONTag>(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
||||
const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize)
|
||||
{
|
||||
MixHrtfBlendBase<ApplyCoeffs>(InSamples, AccumSamples, IrSize, oldparams, newparams,
|
||||
|
||||
@@ -20,8 +20,8 @@ struct FastBSincTag;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr ALuint FracPhaseBitDiff{MixerFracBits - BSincPhaseBits};
|
||||
constexpr ALuint FracPhaseDiffOne{1 << FracPhaseBitDiff};
|
||||
constexpr uint FracPhaseBitDiff{MixerFracBits - BSincPhaseBits};
|
||||
constexpr uint FracPhaseDiffOne{1 << FracPhaseBitDiff};
|
||||
|
||||
#define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z))
|
||||
|
||||
@@ -76,7 +76,7 @@ inline void ApplyCoeffs(float2 *RESTRICT Values, const uint_fast32_t IrSize,
|
||||
|
||||
template<>
|
||||
const float *Resample_<BSincTag,SSETag>(const InterpState *state, const float *RESTRICT src,
|
||||
ALuint frac, ALuint increment, const al::span<float> dst)
|
||||
uint frac, uint increment, const al::span<float> dst)
|
||||
{
|
||||
const float *const filter{state->bsinc.filter};
|
||||
const __m128 sf4{_mm_set1_ps(state->bsinc.sf)};
|
||||
@@ -86,7 +86,7 @@ const float *Resample_<BSincTag,SSETag>(const InterpState *state, const float *R
|
||||
for(float &out_sample : dst)
|
||||
{
|
||||
// Calculate the phase index and factor.
|
||||
const ALuint pi{frac >> FracPhaseBitDiff};
|
||||
const uint pi{frac >> FracPhaseBitDiff};
|
||||
const float pf{static_cast<float>(frac & (FracPhaseDiffOne-1)) * (1.0f/FracPhaseDiffOne)};
|
||||
|
||||
// Apply the scale and phase interpolated filter.
|
||||
@@ -123,7 +123,7 @@ const float *Resample_<BSincTag,SSETag>(const InterpState *state, const float *R
|
||||
|
||||
template<>
|
||||
const float *Resample_<FastBSincTag,SSETag>(const InterpState *state, const float *RESTRICT src,
|
||||
ALuint frac, ALuint increment, const al::span<float> dst)
|
||||
uint frac, uint increment, const al::span<float> dst)
|
||||
{
|
||||
const float *const filter{state->bsinc.filter};
|
||||
const size_t m{state->bsinc.m};
|
||||
@@ -132,7 +132,7 @@ const float *Resample_<FastBSincTag,SSETag>(const InterpState *state, const floa
|
||||
for(float &out_sample : dst)
|
||||
{
|
||||
// Calculate the phase index and factor.
|
||||
const ALuint pi{frac >> FracPhaseBitDiff};
|
||||
const uint pi{frac >> FracPhaseBitDiff};
|
||||
const float pf{static_cast<float>(frac & (FracPhaseDiffOne-1)) * (1.0f/FracPhaseDiffOne)};
|
||||
|
||||
// Apply the phase interpolated filter.
|
||||
@@ -165,12 +165,12 @@ const float *Resample_<FastBSincTag,SSETag>(const InterpState *state, const floa
|
||||
|
||||
|
||||
template<>
|
||||
void MixHrtf_<SSETag>(const float *InSamples, float2 *AccumSamples, const ALuint IrSize,
|
||||
void MixHrtf_<SSETag>(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
||||
const MixHrtfFilter *hrtfparams, const size_t BufferSize)
|
||||
{ MixHrtfBase<ApplyCoeffs>(InSamples, AccumSamples, IrSize, hrtfparams, BufferSize); }
|
||||
|
||||
template<>
|
||||
void MixHrtfBlend_<SSETag>(const float *InSamples, float2 *AccumSamples, const ALuint IrSize,
|
||||
void MixHrtfBlend_<SSETag>(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
||||
const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize)
|
||||
{
|
||||
MixHrtfBlendBase<ApplyCoeffs>(InSamples, AccumSamples, IrSize, oldparams, newparams,
|
||||
|
||||
@@ -31,14 +31,14 @@ struct LerpTag;
|
||||
|
||||
|
||||
template<>
|
||||
const float *Resample_<LerpTag,SSE2Tag>(const InterpState*, const float *RESTRICT src, ALuint frac,
|
||||
ALuint increment, const al::span<float> dst)
|
||||
const float *Resample_<LerpTag,SSE2Tag>(const InterpState*, const float *RESTRICT src, uint frac,
|
||||
uint increment, const al::span<float> dst)
|
||||
{
|
||||
const __m128i increment4{_mm_set1_epi32(static_cast<int>(increment*4))};
|
||||
const __m128 fracOne4{_mm_set1_ps(1.0f/MixerFracOne)};
|
||||
const __m128i fracMask4{_mm_set1_epi32(MixerFracMask)};
|
||||
|
||||
alignas(16) ALuint pos_[4], frac_[4];
|
||||
alignas(16) uint pos_[4], frac_[4];
|
||||
InitPosArrays(frac, increment, frac_, pos_, 4);
|
||||
__m128i frac4{_mm_setr_epi32(static_cast<int>(frac_[0]), static_cast<int>(frac_[1]),
|
||||
static_cast<int>(frac_[2]), static_cast<int>(frac_[3]))};
|
||||
@@ -70,8 +70,8 @@ const float *Resample_<LerpTag,SSE2Tag>(const InterpState*, const float *RESTRIC
|
||||
|
||||
if(size_t todo{dst.size()&3})
|
||||
{
|
||||
src += static_cast<ALuint>(_mm_cvtsi128_si32(pos4));
|
||||
frac = static_cast<ALuint>(_mm_cvtsi128_si32(frac4));
|
||||
src += static_cast<uint>(_mm_cvtsi128_si32(pos4));
|
||||
frac = static_cast<uint>(_mm_cvtsi128_si32(frac4));
|
||||
|
||||
do {
|
||||
*(dst_iter++) = lerp(src[0], src[1], static_cast<float>(frac) * (1.0f/MixerFracOne));
|
||||
|
||||
@@ -32,14 +32,14 @@ struct LerpTag;
|
||||
|
||||
|
||||
template<>
|
||||
const float *Resample_<LerpTag,SSE4Tag>(const InterpState*, const float *RESTRICT src, ALuint frac,
|
||||
ALuint increment, const al::span<float> dst)
|
||||
const float *Resample_<LerpTag,SSE4Tag>(const InterpState*, const float *RESTRICT src, uint frac,
|
||||
uint increment, const al::span<float> dst)
|
||||
{
|
||||
const __m128i increment4{_mm_set1_epi32(static_cast<int>(increment*4))};
|
||||
const __m128 fracOne4{_mm_set1_ps(1.0f/MixerFracOne)};
|
||||
const __m128i fracMask4{_mm_set1_epi32(MixerFracMask)};
|
||||
|
||||
alignas(16) ALuint pos_[4], frac_[4];
|
||||
alignas(16) uint pos_[4], frac_[4];
|
||||
InitPosArrays(frac, increment, frac_, pos_, 4);
|
||||
__m128i frac4{_mm_setr_epi32(static_cast<int>(frac_[0]), static_cast<int>(frac_[1]),
|
||||
static_cast<int>(frac_[2]), static_cast<int>(frac_[3]))};
|
||||
@@ -75,8 +75,8 @@ const float *Resample_<LerpTag,SSE4Tag>(const InterpState*, const float *RESTRIC
|
||||
* four samples, so the lowest element is the next position to
|
||||
* resample.
|
||||
*/
|
||||
src += static_cast<ALuint>(_mm_cvtsi128_si32(pos4));
|
||||
frac = static_cast<ALuint>(_mm_cvtsi128_si32(frac4));
|
||||
src += static_cast<uint>(_mm_cvtsi128_si32(pos4));
|
||||
frac = static_cast<uint>(_mm_cvtsi128_si32(frac4));
|
||||
|
||||
do {
|
||||
*(dst_iter++) = lerp(src[0], src[1], static_cast<float>(frac) * (1.0f/MixerFracOne));
|
||||
|
||||
+35
-38
@@ -34,9 +34,6 @@
|
||||
#include <new>
|
||||
#include <utility>
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "AL/alc.h"
|
||||
|
||||
#include "al/buffer.h"
|
||||
#include "al/event.h"
|
||||
#include "al/source.h"
|
||||
@@ -85,10 +82,10 @@ MixerFunc MixSamples{Mix_<CTag>};
|
||||
|
||||
namespace {
|
||||
|
||||
using HrtfMixerFunc = void(*)(const float *InSamples, float2 *AccumSamples, const ALuint IrSize,
|
||||
using HrtfMixerFunc = void(*)(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
||||
const MixHrtfFilter *hrtfparams, const size_t BufferSize);
|
||||
using HrtfMixerBlendFunc = void(*)(const float *InSamples, float2 *AccumSamples,
|
||||
const ALuint IrSize, const HrtfFilter *oldparams, const MixHrtfFilter *newparams,
|
||||
const uint IrSize, const HrtfFilter *oldparams, const MixHrtfFilter *newparams,
|
||||
const size_t BufferSize);
|
||||
|
||||
HrtfMixerFunc MixHrtfSamples{MixHrtf_<CTag>};
|
||||
@@ -246,8 +243,8 @@ float *LoadBufferStatic(BufferlistItem *BufferListItem, BufferlistItem *&BufferL
|
||||
al::span<float> SrcBuffer)
|
||||
{
|
||||
const BufferStorage &Buffer = *BufferListItem->mBuffer;
|
||||
const ALuint LoopStart{Buffer.mLoopStart};
|
||||
const ALuint LoopEnd{Buffer.mLoopEnd};
|
||||
const uint LoopStart{Buffer.mLoopStart};
|
||||
const uint LoopEnd{Buffer.mLoopEnd};
|
||||
ASSUME(LoopEnd > LoopStart);
|
||||
|
||||
/* If current pos is beyond the loop range, do not loop */
|
||||
@@ -341,8 +338,8 @@ float *LoadBufferQueue(BufferlistItem *BufferListItem, BufferlistItem *BufferLoo
|
||||
}
|
||||
|
||||
|
||||
void DoHrtfMix(const float *samples, const ALuint DstBufferSize, DirectParams &parms,
|
||||
const float TargetGain, const ALuint Counter, ALuint OutPos, const ALuint IrSize,
|
||||
void DoHrtfMix(const float *samples, const uint DstBufferSize, DirectParams &parms,
|
||||
const float TargetGain, const uint Counter, uint OutPos, const uint IrSize,
|
||||
ALCdevice *Device)
|
||||
{
|
||||
auto &HrtfSamples = Device->HrtfSourceData;
|
||||
@@ -360,7 +357,7 @@ void DoHrtfMix(const float *samples, const ALuint DstBufferSize, DirectParams &p
|
||||
parms.Hrtf.History.begin());
|
||||
|
||||
/* If fading and this is the first mixing pass, fade between the IRs. */
|
||||
ALuint fademix{0u};
|
||||
uint fademix{0u};
|
||||
if(Counter && OutPos == 0)
|
||||
{
|
||||
fademix = minu(DstBufferSize, Counter);
|
||||
@@ -393,7 +390,7 @@ void DoHrtfMix(const float *samples, const ALuint DstBufferSize, DirectParams &p
|
||||
|
||||
if(fademix < DstBufferSize)
|
||||
{
|
||||
const ALuint todo{DstBufferSize - fademix};
|
||||
const uint todo{DstBufferSize - fademix};
|
||||
float gain{TargetGain};
|
||||
|
||||
/* Interpolate the target gain if the gain fading lasts longer than
|
||||
@@ -417,7 +414,7 @@ void DoHrtfMix(const float *samples, const ALuint DstBufferSize, DirectParams &p
|
||||
}
|
||||
|
||||
void DoNfcMix(const al::span<const float> samples, FloatBufferLine *OutBuffer, DirectParams &parms,
|
||||
const float *TargetGains, const ALuint Counter, const ALuint OutPos, ALCdevice *Device)
|
||||
const float *TargetGains, const uint Counter, const uint OutPos, ALCdevice *Device)
|
||||
{
|
||||
using FilterProc = void (NfcFilter::*)(const al::span<const float>, float*);
|
||||
static constexpr FilterProc NfcProcess[MAX_AMBI_ORDER+1]{
|
||||
@@ -452,12 +449,12 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
ASSUME(SamplesToDo > 0);
|
||||
|
||||
/* Get voice info */
|
||||
ALuint DataPosInt{mPosition.load(std::memory_order_relaxed)};
|
||||
ALuint DataPosFrac{mPositionFrac.load(std::memory_order_relaxed)};
|
||||
uint DataPosInt{mPosition.load(std::memory_order_relaxed)};
|
||||
uint DataPosFrac{mPositionFrac.load(std::memory_order_relaxed)};
|
||||
BufferlistItem *BufferListItem{mCurrentBuffer.load(std::memory_order_relaxed)};
|
||||
BufferlistItem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)};
|
||||
const ALuint SampleSize{mSampleSize};
|
||||
const ALuint increment{mStep};
|
||||
const uint SampleSize{mSampleSize};
|
||||
const uint increment{mStep};
|
||||
if UNLIKELY(increment < 1)
|
||||
{
|
||||
/* If the voice is supposed to be stopping but can't be mixed, just
|
||||
@@ -474,13 +471,13 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
ASSUME(FrameSize > 0);
|
||||
|
||||
ALCdevice *Device{Context->mDevice.get()};
|
||||
const ALuint NumSends{Device->NumAuxSends};
|
||||
const ALuint IrSize{Device->mHrtf ? Device->mHrtf->irSize : 0};
|
||||
const uint NumSends{Device->NumAuxSends};
|
||||
const uint IrSize{Device->mHrtf ? Device->mHrtf->irSize : 0};
|
||||
|
||||
ResamplerFunc Resample{(increment == MixerFracOne && DataPosFrac == 0) ?
|
||||
Resample_<CopyTag,CTag> : mResampler};
|
||||
|
||||
ALuint Counter{(mFlags&VoiceIsFading) ? SamplesToDo : 0};
|
||||
uint Counter{(mFlags&VoiceIsFading) ? SamplesToDo : 0};
|
||||
if(!Counter)
|
||||
{
|
||||
/* No fading, just overwrite the old/current params. */
|
||||
@@ -493,7 +490,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
else
|
||||
parms.Hrtf.Old = parms.Hrtf.Target;
|
||||
}
|
||||
for(ALuint send{0};send < NumSends;++send)
|
||||
for(uint send{0};send < NumSends;++send)
|
||||
{
|
||||
if(mSend[send].Buffer.empty())
|
||||
continue;
|
||||
@@ -504,12 +501,12 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
}
|
||||
}
|
||||
|
||||
ALuint buffers_done{0u};
|
||||
ALuint OutPos{0u};
|
||||
uint buffers_done{0u};
|
||||
uint OutPos{0u};
|
||||
do {
|
||||
/* Figure out how many buffer samples will be needed */
|
||||
ALuint DstBufferSize{SamplesToDo - OutPos};
|
||||
ALuint SrcBufferSize;
|
||||
uint DstBufferSize{SamplesToDo - OutPos};
|
||||
uint SrcBufferSize;
|
||||
|
||||
if(increment <= MixerFracOne)
|
||||
{
|
||||
@@ -523,7 +520,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
/* Result is guaranteed to be <= BUFFERSIZE+MAX_RESAMPLER_PADDING
|
||||
* since we won't use more src samples than dst samples+padding.
|
||||
*/
|
||||
SrcBufferSize = static_cast<ALuint>(DataSize64);
|
||||
SrcBufferSize = static_cast<uint>(DataSize64);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -533,7 +530,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
DataSize64 += MAX_RESAMPLER_PADDING;
|
||||
|
||||
if(DataSize64 <= BUFFERSIZE + MAX_RESAMPLER_PADDING)
|
||||
SrcBufferSize = static_cast<ALuint>(DataSize64);
|
||||
SrcBufferSize = static_cast<uint>(DataSize64);
|
||||
else
|
||||
{
|
||||
/* If the source size got saturated, we can't fill the desired
|
||||
@@ -548,7 +545,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
/* Some mixers require being 16-byte aligned, so also limit
|
||||
* to a multiple of 4 samples to maintain alignment.
|
||||
*/
|
||||
DstBufferSize = static_cast<ALuint>(DataSize64) & ~3u;
|
||||
DstBufferSize = static_cast<uint>(DataSize64) & ~3u;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -558,20 +555,20 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
BufferStorage *buffer{BufferListItem->mBuffer};
|
||||
|
||||
/* Exclude resampler pre-padding from the needed size. */
|
||||
const ALuint toLoad{SrcBufferSize - (MAX_RESAMPLER_PADDING>>1)};
|
||||
const uint toLoad{SrcBufferSize - (MAX_RESAMPLER_PADDING>>1)};
|
||||
if(toLoad > mNumCallbackSamples)
|
||||
{
|
||||
const size_t byteOffset{mNumCallbackSamples*FrameSize};
|
||||
const size_t needBytes{toLoad*FrameSize - byteOffset};
|
||||
|
||||
const ALsizei gotBytes{buffer->mCallback(buffer->mUserData,
|
||||
&buffer->mData[byteOffset], static_cast<ALsizei>(needBytes))};
|
||||
const int gotBytes{buffer->mCallback(buffer->mUserData,
|
||||
&buffer->mData[byteOffset], static_cast<int>(needBytes))};
|
||||
if(gotBytes < 1)
|
||||
mFlags |= VoiceCallbackStopped;
|
||||
else if(static_cast<ALuint>(gotBytes) < needBytes)
|
||||
else if(static_cast<uint>(gotBytes) < needBytes)
|
||||
{
|
||||
mFlags |= VoiceCallbackStopped;
|
||||
mNumCallbackSamples += static_cast<ALuint>(static_cast<ALuint>(gotBytes) /
|
||||
mNumCallbackSamples += static_cast<uint>(static_cast<uint>(gotBytes) /
|
||||
FrameSize);
|
||||
}
|
||||
else
|
||||
@@ -668,7 +665,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
}
|
||||
}
|
||||
|
||||
for(ALuint send{0};send < NumSends;++send)
|
||||
for(uint send{0};send < NumSends;++send)
|
||||
{
|
||||
if(mSend[send].Buffer.empty())
|
||||
continue;
|
||||
@@ -685,7 +682,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
}
|
||||
/* Update positions */
|
||||
DataPosFrac += increment*DstBufferSize;
|
||||
const ALuint SrcSamplesDone{DataPosFrac>>MixerFracBits};
|
||||
const uint SrcSamplesDone{DataPosFrac>>MixerFracBits};
|
||||
DataPosInt += SrcSamplesDone;
|
||||
DataPosFrac &= MixerFracMask;
|
||||
|
||||
@@ -702,8 +699,8 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
{
|
||||
/* Handle looping static source */
|
||||
const BufferStorage &Buffer = *BufferListItem->mBuffer;
|
||||
const ALuint LoopStart{Buffer.mLoopStart};
|
||||
const ALuint LoopEnd{Buffer.mLoopEnd};
|
||||
const uint LoopStart{Buffer.mLoopStart};
|
||||
const uint LoopEnd{Buffer.mLoopEnd};
|
||||
if(DataPosInt >= LoopEnd)
|
||||
{
|
||||
assert(LoopEnd > LoopStart);
|
||||
@@ -763,7 +760,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
}
|
||||
|
||||
/* Capture the source ID in case it's reset for stopping. */
|
||||
const ALuint SourceID{mSourceID.load(std::memory_order_relaxed)};
|
||||
const uint SourceID{mSourceID.load(std::memory_order_relaxed)};
|
||||
|
||||
/* Update voice info */
|
||||
mPosition.store(DataPosInt, std::memory_order_relaxed);
|
||||
@@ -777,7 +774,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
std::atomic_thread_fence(std::memory_order_release);
|
||||
|
||||
/* Send any events now, after the position/buffer info was updated. */
|
||||
const ALbitfieldSOFT enabledevt{Context->mEnabledEvts.load(std::memory_order_acquire)};
|
||||
const uint enabledevt{Context->mEnabledEvts.load(std::memory_order_acquire)};
|
||||
if(buffers_done > 0 && (enabledevt&EventType_BufferCompleted))
|
||||
{
|
||||
RingBuffer *ring{Context->mAsyncEvents.get()};
|
||||
|
||||
Reference in New Issue
Block a user