diff options
Diffstat (limited to 'alc/mixer')
-rw-r--r-- | alc/mixer/defs.h | 5 | ||||
-rw-r--r-- | alc/mixer/mixer_c.cpp | 24 | ||||
-rw-r--r-- | alc/mixer/mixer_neon.cpp | 54 | ||||
-rw-r--r-- | alc/mixer/mixer_sse.cpp | 51 |
4 files changed, 62 insertions, 72 deletions
diff --git a/alc/mixer/defs.h b/alc/mixer/defs.h index 1e5e68bb..9d4fd063 100644 --- a/alc/mixer/defs.h +++ b/alc/mixer/defs.h @@ -30,9 +30,8 @@ template<ResampleType TypeTag, InstSetType InstTag> const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); template<InstSetType InstTag> -void Mix_(const float *InSamples, const al::span<FloatBufferLine> OutBuffer, float *CurrentGains, - const float *TargetGains, const ALsizei Counter, const ALsizei OutPos, - const ALsizei BufferSize); +void Mix_(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer, + float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos); template<InstSetType InstTag> void MixRow_(const al::span<float> OutBuffer, const al::span<const float> Gains, const float *InSamples, const size_t InStride); diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp index 8b5c0f41..e7ca23d5 100644 --- a/alc/mixer/mixer_c.cpp +++ b/alc/mixer/mixer_c.cpp @@ -142,31 +142,29 @@ void MixDirectHrtf_<CTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, template<> -void Mix_<CTag>(const float *InSamples, const al::span<FloatBufferLine> OutBuffer, - float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos, - const ALsizei BufferSize) +void Mix_<CTag>(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer, + float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos) { - ASSUME(BufferSize > 0); - const ALfloat delta{(Counter > 0) ? 1.0f / static_cast<ALfloat>(Counter) : 0.0f}; + const bool reached_target{InSamples.size() >= static_cast<size_t>(Counter)}; + const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end(); for(FloatBufferLine &output : OutBuffer) { - ALfloat *RESTRICT dst{output.data()+OutPos}; + ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)}; ALfloat gain{*CurrentGains}; const ALfloat diff{*TargetGains - gain}; - ALsizei pos{0}; + auto in_iter = InSamples.begin(); if(std::fabs(diff) > std::numeric_limits<float>::epsilon()) { - ALsizei minsize{mini(BufferSize, Counter)}; const ALfloat step{diff * delta}; ALfloat step_count{0.0f}; - for(;pos < minsize;pos++) + while(in_iter != min_end) { - dst[pos] += InSamples[pos] * (gain + step*step_count); + *(dst++) += *(in_iter++) * (gain + step*step_count); step_count += 1.0f; } - if(pos == Counter) + if(reached_target) gain = *TargetGains; else gain += step*step_count; @@ -177,8 +175,8 @@ void Mix_<CTag>(const float *InSamples, const al::span<FloatBufferLine> OutBuffe if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; - for(;pos < BufferSize;pos++) - dst[pos] += InSamples[pos]*gain; + while(in_iter != InSamples.end()) + *(dst++) += *(in_iter++) * gain; } } diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp index b80f8cf8..1c4466c2 100644 --- a/alc/mixer/mixer_neon.cpp +++ b/alc/mixer/mixer_neon.cpp @@ -189,27 +189,27 @@ void MixDirectHrtf_<NEONTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut template<> -void Mix_<NEONTag>(const float *InSamples, const al::span<FloatBufferLine> OutBuffer, - float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos, - const ALsizei BufferSize) +void Mix_<NEONTag>(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer, + float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos) { - ASSUME(BufferSize > 0); - - const ALfloat delta{(Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f}; + const ALfloat delta{(Counter > 0) ? 1.0f / static_cast<ALfloat>(Counter) : 0.0f}; + const bool reached_target{InSamples.size() >= static_cast<size_t>(Counter)}; + const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end(); + const auto aligned_end = minz(InSamples.size(), (min_end-InSamples.begin()+3) & ~3) + + InSamples.begin(); for(FloatBufferLine &output : OutBuffer) { ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)}; ALfloat gain{*CurrentGains}; const ALfloat diff{*TargetGains - gain}; - ALsizei pos{0}; + auto in_iter = InSamples.begin(); if(std::fabs(diff) > std::numeric_limits<float>::epsilon()) { - ALsizei minsize{mini(BufferSize, Counter)}; const ALfloat step{diff * delta}; ALfloat step_count{0.0f}; /* Mix with applying gain steps in aligned multiples of 4. */ - if LIKELY(minsize > 3) + if(ptrdiff_t todo{(min_end-in_iter) >> 2}) { const float32x4_t four4{vdupq_n_f32(4.0f)}; const float32x4_t step4{vdupq_n_f32(step)}; @@ -220,15 +220,13 @@ void Mix_<NEONTag>(const float *InSamples, const al::span<FloatBufferLine> OutBu vsetq_lane_f32(3.0f, vdupq_n_f32(0.0f), 3), 2), 1), 0 )}; - ALsizei todo{minsize >> 2}; - do { - const float32x4_t val4 = vld1q_f32(&InSamples[pos]); - float32x4_t dry4 = vld1q_f32(&dst[pos]); + const float32x4_t val4 = vld1q_f32(in_iter); + float32x4_t dry4 = vld1q_f32(dst); dry4 = vmlaq_f32(dry4, val4, vmlaq_f32(gain4, step4, step_count4)); step_count4 = vaddq_f32(step_count4, four4); - vst1q_f32(&dst[pos], dry4); - pos += 4; + vst1q_f32(dst, dry4); + in_iter += 4; dst += 4; } while(--todo); /* NOTE: step_count4 now represents the next four counts after * the last four mixed samples, so the lowest element @@ -237,41 +235,39 @@ void Mix_<NEONTag>(const float *InSamples, const al::span<FloatBufferLine> OutBu step_count = vgetq_lane_f32(step_count4, 0); } /* Mix with applying left over gain steps that aren't aligned multiples of 4. */ - for(;pos < minsize;pos++) + while(in_iter != min_end) { - dst[pos] += InSamples[pos]*(gain + step*step_count); + *(dst++) += *(in_iter++) * (gain + step*step_count); step_count += 1.0f; } - if(pos == Counter) + if(reached_target) gain = *TargetGains; else gain += step*step_count; *CurrentGains = gain; /* Mix until pos is aligned with 4 or the mix is done. */ - minsize = mini(BufferSize, (pos+3)&~3); - for(;pos < minsize;pos++) - dst[pos] += InSamples[pos]*gain; + while(in_iter != aligned_end) + *(dst++) += *(in_iter++) * gain; } ++CurrentGains; ++TargetGains; if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; - if LIKELY(BufferSize-pos > 3) + if(ptrdiff_t todo{(InSamples.end()-in_iter) >> 2}) { - ALsizei todo{(BufferSize-pos) >> 2}; const float32x4_t gain4 = vdupq_n_f32(gain); do { - const float32x4_t val4 = vld1q_f32(&InSamples[pos]); - float32x4_t dry4 = vld1q_f32(&dst[pos]); + const float32x4_t val4 = vld1q_f32(in_iter); + float32x4_t dry4 = vld1q_f32(dst); dry4 = vmlaq_f32(dry4, val4, gain4); - vst1q_f32(&dst[pos], dry4); - pos += 4; + vst1q_f32(dst, dry4); + in_iter += 4; dst += 4; } while(--todo); } - for(;pos < BufferSize;pos++) - dst[pos] += InSamples[pos]*gain; + while(in_iter != InSamples.end()) + *(dst++) += *(in_iter++) * gain; } } diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp index bd0042a1..3c8204d2 100644 --- a/alc/mixer/mixer_sse.cpp +++ b/alc/mixer/mixer_sse.cpp @@ -145,43 +145,42 @@ void MixDirectHrtf_<SSETag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, template<> -void Mix_<SSETag>(const float *InSamples, const al::span<FloatBufferLine> OutBuffer, - float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos, - const ALsizei BufferSize) +void Mix_<SSETag>(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer, + float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos) { - ASSUME(BufferSize > 0); - const ALfloat delta{(Counter > 0) ? 1.0f / static_cast<ALfloat>(Counter) : 0.0f}; + const bool reached_target{InSamples.size() >= static_cast<size_t>(Counter)}; + const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end(); + const auto aligned_end = minz(InSamples.size(), (min_end-InSamples.begin()+3) & ~3) + + InSamples.begin(); for(FloatBufferLine &output : OutBuffer) { ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)}; ALfloat gain{*CurrentGains}; const ALfloat diff{*TargetGains - gain}; - ALsizei pos{0}; + auto in_iter = InSamples.begin(); if(std::fabs(diff) > std::numeric_limits<float>::epsilon()) { - ALsizei minsize{mini(BufferSize, Counter)}; const ALfloat step{diff * delta}; ALfloat step_count{0.0f}; /* Mix with applying gain steps in aligned multiples of 4. */ - if LIKELY(minsize > 3) + if(ptrdiff_t todo{(min_end-in_iter) >> 2}) { const __m128 four4{_mm_set1_ps(4.0f)}; const __m128 step4{_mm_set1_ps(step)}; const __m128 gain4{_mm_set1_ps(gain)}; __m128 step_count4{_mm_setr_ps(0.0f, 1.0f, 2.0f, 3.0f)}; - ALsizei todo{minsize >> 2}; do { - const __m128 val4{_mm_load_ps(&InSamples[pos])}; - __m128 dry4{_mm_load_ps(&dst[pos])}; + const __m128 val4{_mm_load_ps(in_iter)}; + __m128 dry4{_mm_load_ps(dst)}; #define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z)) /* dry += val * (gain + step*step_count) */ dry4 = MLA4(dry4, val4, MLA4(gain4, step4, step_count4)); #undef MLA4 - _mm_store_ps(&dst[pos], dry4); + _mm_store_ps(dst, dry4); step_count4 = _mm_add_ps(step_count4, four4); - pos += 4; + in_iter += 4; dst += 4; } while(--todo); /* NOTE: step_count4 now represents the next four counts after * the last four mixed samples, so the lowest element @@ -190,41 +189,39 @@ void Mix_<SSETag>(const float *InSamples, const al::span<FloatBufferLine> OutBuf step_count = _mm_cvtss_f32(step_count4); } /* Mix with applying left over gain steps that aren't aligned multiples of 4. */ - for(;pos < minsize;pos++) + while(in_iter != min_end) { - dst[pos] += InSamples[pos]*(gain + step*step_count); + *(dst++) += *(in_iter++) * (gain + step*step_count); step_count += 1.0f; } - if(pos == Counter) + if(reached_target) gain = *TargetGains; else gain += step*step_count; *CurrentGains = gain; /* Mix until pos is aligned with 4 or the mix is done. */ - minsize = mini(BufferSize, (pos+3)&~3); - for(;pos < minsize;pos++) - dst[pos] += InSamples[pos]*gain; + while(in_iter != aligned_end) + *(dst++) += *(in_iter++) * gain; } ++CurrentGains; ++TargetGains; if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; - if LIKELY(BufferSize-pos > 3) + if(ptrdiff_t todo{(InSamples.end()-in_iter) >> 2}) { - ALsizei todo{(BufferSize-pos) >> 2}; const __m128 gain4{_mm_set1_ps(gain)}; do { - const __m128 val4{_mm_load_ps(&InSamples[pos])}; - __m128 dry4{_mm_load_ps(&dst[pos])}; + const __m128 val4{_mm_load_ps(in_iter)}; + __m128 dry4{_mm_load_ps(dst)}; dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4)); - _mm_store_ps(&dst[pos], dry4); - pos += 4; + _mm_store_ps(dst, dry4); + in_iter += 4; dst += 4; } while(--todo); } - for(;pos < BufferSize;pos++) - dst[pos] += InSamples[pos]*gain; + while(in_iter != InSamples.end()) + *(dst++) += *(in_iter++) * gain; } } |