diff options
author | Chris Robinson <[email protected]> | 2019-08-31 15:49:34 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-08-31 15:49:34 -0700 |
commit | 3973334a64f0aa428c9cbd06c89cfb60951810c8 (patch) | |
tree | 654595d4e772011a218e3405c81a8fe15d070f1b | |
parent | a546343148ad87786b1a199e9ca91ffc50da4e81 (diff) |
Store the voice fraction offset as unsigned
-rw-r--r-- | al/source.cpp | 22 | ||||
-rw-r--r-- | alc/alu.h | 4 | ||||
-rw-r--r-- | alc/mixer/defs.h | 2 | ||||
-rw-r--r-- | alc/mixer/mixer_c.cpp | 27 | ||||
-rw-r--r-- | alc/mixer/mixer_neon.cpp | 36 | ||||
-rw-r--r-- | alc/mixer/mixer_sse.cpp | 9 | ||||
-rw-r--r-- | alc/mixer/mixer_sse2.cpp | 9 | ||||
-rw-r--r-- | alc/mixer/mixer_sse41.cpp | 9 | ||||
-rw-r--r-- | alc/mixvoice.cpp | 3 |
9 files changed, 57 insertions, 64 deletions
diff --git a/al/source.cpp b/al/source.cpp index 49f2fb2a..d9a7cb87 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -195,7 +195,7 @@ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); readPos = uint64_t{voice->mPosition.load(std::memory_order_relaxed)} << 32; - readPos |= int64_t{voice->mPositionFrac.load(std::memory_order_relaxed)} << + readPos |= uint64_t{voice->mPositionFrac.load(std::memory_order_relaxed)} << (32-FRACTIONBITS); } std::atomic_thread_fence(std::memory_order_acquire); @@ -206,7 +206,7 @@ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono const ALbufferlistitem *BufferList{Source->queue}; while(BufferList && BufferList != Current) { - readPos += int64_t{BufferList->mSampleLen} << 32; + readPos += uint64_t{BufferList->mSampleLen} << 32; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } readPos = minu64(readPos, 0x7fffffffffffffff_u64); @@ -254,7 +254,7 @@ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono:: while(BufferList && BufferList != Current) { if(!BufferFmt) BufferFmt = BufferList->mBuffer; - readPos += int64_t{BufferList->mSampleLen} << FRACTIONBITS; + readPos += uint64_t{BufferList->mSampleLen} << FRACTIONBITS; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } @@ -265,7 +265,7 @@ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono:: } assert(BufferFmt != nullptr); - offset = static_cast<ALdouble>(readPos) / static_cast<ALdouble>FRACTIONONE / + offset = static_cast<ALdouble>(readPos) / ALdouble{FRACTIONONE} / static_cast<ALdouble>(BufferFmt->Frequency); } @@ -283,7 +283,7 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) ALCdevice *device{context->mDevice.get()}; const ALbufferlistitem *Current; ALuint readPos; - ALsizei readPosFrac; + ALuint readPosFrac; ALuint refcount; ALvoice *voice; @@ -382,7 +382,7 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) * or Second offset supplied by the application). This takes into account the * fact that the buffer format may have been modifed since. */ -ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALsizei *frac) +ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac) { const ALbuffer *BufferFmt{nullptr}; const ALbufferlistitem *BufferList; @@ -426,14 +426,14 @@ ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALsizei *frac) case AL_SAMPLE_OFFSET: dblfrac = modf(Source->Offset, &dbloff); - *offset = static_cast<ALuint>(mind(dbloff, std::numeric_limits<unsigned int>::max())); - *frac = static_cast<ALsizei>(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); + *offset = static_cast<ALuint>(mind(dbloff, std::numeric_limits<ALuint>::max())); + *frac = static_cast<ALuint>(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); break; case AL_SEC_OFFSET: dblfrac = modf(Source->Offset*BufferFmt->Frequency, &dbloff); - *offset = static_cast<ALuint>(mind(dbloff, std::numeric_limits<unsigned int>::max())); - *frac = static_cast<ALsizei>(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); + *offset = static_cast<ALuint>(mind(dbloff, std::numeric_limits<ALuint>::max())); + *frac = static_cast<ALuint>(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); break; } Source->OffsetType = AL_NONE; @@ -451,7 +451,7 @@ ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) { /* Get sample frame offset */ ALuint offset{0u}; - ALsizei frac{0}; + ALuint frac{0u}; if(!GetSampleOffset(Source, &offset, &frac)) return AL_FALSE; @@ -81,7 +81,7 @@ union InterpState { }; using ResamplerFunc = const ALfloat*(*)(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst); + ALuint frac, ALint increment, const al::span<float> dst); void BsincPrepare(const ALuint increment, BsincState *state, const BSincTable *table); @@ -219,7 +219,7 @@ struct ALvoice { */ std::atomic<ALuint> mPosition; /** Fractional (fixed-point) offset to the next sample. */ - std::atomic<ALsizei> mPositionFrac; + std::atomic<ALuint> mPositionFrac; /* Current buffer queue item being played. */ std::atomic<ALbufferlistitem*> mCurrentBuffer; diff --git a/alc/mixer/defs.h b/alc/mixer/defs.h index bb5ca56e..4aa3c6b6 100644 --- a/alc/mixer/defs.h +++ b/alc/mixer/defs.h @@ -27,7 +27,7 @@ enum ResampleType { }; template<ResampleType TypeTag, InstSetType InstTag> -const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, +const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, ALuint frac, ALint increment, const al::span<float> dst); template<InstSetType InstTag> diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp index dbdbf16d..7a79d1e2 100644 --- a/alc/mixer/mixer_c.cpp +++ b/alc/mixer/mixer_c.cpp @@ -13,23 +13,23 @@ namespace { -inline ALfloat do_point(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei) +inline ALfloat do_point(const InterpState&, const ALfloat *RESTRICT vals, const ALuint) { return vals[0]; } -inline ALfloat do_lerp(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei frac) +inline ALfloat do_lerp(const InterpState&, const ALfloat *RESTRICT vals, const ALuint frac) { return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); } -inline ALfloat do_cubic(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei frac) +inline ALfloat do_cubic(const InterpState&, const ALfloat *RESTRICT vals, const ALuint frac) { return cubic(vals[0], vals[1], vals[2], vals[3], frac * (1.0f/FRACTIONONE)); } -inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, const ALsizei frac) +inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, const ALuint frac) { ASSUME(istate.bsinc.m > 0); // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) - const ALsizei pi{frac >> FRAC_PHASE_BITDIFF}; + const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; const ALfloat pf{(frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF))}; #undef FRAC_PHASE_BITDIFF - const ALfloat *fil{istate.bsinc.filter + istate.bsinc.m*pi*4}; + const ALfloat *fil{istate.bsinc.filter + ptrdiff_t{istate.bsinc.m}*pi*4}; const ALfloat *scd{fil + istate.bsinc.m}; const ALfloat *phd{scd + istate.bsinc.m}; const ALfloat *spd{phd + istate.bsinc.m}; @@ -41,13 +41,12 @@ inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, return r; } -using SamplerT = ALfloat(const InterpState&, const ALfloat*RESTRICT, const ALsizei); +using SamplerT = ALfloat(const InterpState&, const ALfloat*RESTRICT, const ALuint); template<SamplerT &Sampler> const ALfloat *DoResample(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst) + ALuint frac, ALint increment, const al::span<float> dst) { ASSUME(increment > 0); - ASSUME(frac >= 0); const InterpState istate{*state}; auto proc_sample = [&src,&frac,istate,increment]() -> ALfloat @@ -68,7 +67,7 @@ const ALfloat *DoResample(const InterpState *state, const ALfloat *RESTRICT src, } // namespace template<> -const ALfloat *Resample_<CopyTag,CTag>(const InterpState*, const ALfloat *RESTRICT src, ALsizei, +const ALfloat *Resample_<CopyTag,CTag>(const InterpState*, const ALfloat *RESTRICT src, ALuint, ALint, const al::span<float> dst) { #if defined(HAVE_SSE) || defined(HAVE_NEON) @@ -82,22 +81,22 @@ const ALfloat *Resample_<CopyTag,CTag>(const InterpState*, const ALfloat *RESTRI template<> const ALfloat *Resample_<PointTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst) + ALuint frac, ALint increment, const al::span<float> dst) { return DoResample<do_point>(state, src, frac, increment, dst); } template<> const ALfloat *Resample_<LerpTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst) + ALuint frac, ALint increment, const al::span<float> dst) { return DoResample<do_lerp>(state, src, frac, increment, dst); } template<> const ALfloat *Resample_<CubicTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst) + ALuint frac, ALint increment, const al::span<float> dst) { return DoResample<do_cubic>(state, src-1, frac, increment, dst); } template<> const ALfloat *Resample_<BSincTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst) + ALuint frac, ALint increment, const al::span<float> dst) { return DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst); } diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp index 472eae1b..d3e89aec 100644 --- a/alc/mixer/mixer_neon.cpp +++ b/alc/mixer/mixer_neon.cpp @@ -16,7 +16,7 @@ template<> const ALfloat *Resample_<LerpTag,NEONTag>(const InterpState*, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst) + ALuint frac, ALint increment, const al::span<float> dst) { const int32x4_t increment4 = vdupq_n_s32(increment*4); const float32x4_t fracOne4 = vdupq_n_f32(1.0f/FRACTIONONE); @@ -24,7 +24,6 @@ const ALfloat *Resample_<LerpTag,NEONTag>(const InterpState*, const ALfloat *RES alignas(16) ALsizei pos_[4], frac_[4]; int32x4_t pos4, frac4; - ASSUME(frac >= 0); ASSUME(increment > 0); InitiatePositionArrays(frac, increment, frac_, pos_, 4); @@ -35,17 +34,17 @@ const ALfloat *Resample_<LerpTag,NEONTag>(const InterpState*, const ALfloat *RES const auto aligned_end = (dst.size()&~3) + dst_iter; while(dst_iter != aligned_end) { - const int pos0 = vgetq_lane_s32(pos4, 0); - const int pos1 = vgetq_lane_s32(pos4, 1); - const int pos2 = vgetq_lane_s32(pos4, 2); - const int pos3 = vgetq_lane_s32(pos4, 3); - const float32x4_t val1 = (float32x4_t){src[pos0], src[pos1], src[pos2], src[pos3]}; - const float32x4_t val2 = (float32x4_t){src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1]}; + const int pos0{vgetq_lane_s32(pos4, 0)}; + const int pos1{vgetq_lane_s32(pos4, 1)}; + const int pos2{vgetq_lane_s32(pos4, 2)}; + const int pos3{vgetq_lane_s32(pos4, 3)}; + const float32x4_t val1{src[pos0], src[pos1], src[pos2], src[pos3]}; + const float32x4_t val2{src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1]}; /* val1 + (val2-val1)*mu */ - const float32x4_t r0 = vsubq_f32(val2, val1); - const float32x4_t mu = vmulq_f32(vcvtq_f32_s32(frac4), fracOne4); - const float32x4_t out = vmlaq_f32(val1, mu, r0); + const float32x4_t r0{vsubq_f32(val2, val1)}; + const float32x4_t mu{vmulq_f32(vcvtq_f32_s32(frac4), fracOne4)}; + const float32x4_t out{vmlaq_f32(val1, mu, r0)}; vst1q_f32(dst_iter, out); dst_iter += 4; @@ -58,15 +57,15 @@ const ALfloat *Resample_<LerpTag,NEONTag>(const InterpState*, const ALfloat *RES /* NOTE: These four elements represent the position *after* the last four * samples, so the lowest element is the next position to resample. */ - ALsizei pos{vgetq_lane_s32(pos4, 0)}; + src += static_cast<ALuint>(vgetq_lane_s32(pos4, 0)); frac = vgetq_lane_s32(frac4, 0); while(dst_iter != dst.end()) { - *(dst_iter++) = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); frac += increment; - pos += frac>>FRACTIONBITS; + src += frac>>FRACTIONBITS; frac &= FRACTIONMASK; } return dst.begin(); @@ -74,22 +73,21 @@ const ALfloat *Resample_<LerpTag,NEONTag>(const InterpState*, const ALfloat *RES template<> const ALfloat *Resample_<BSincTag,NEONTag>(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst) + ALuint frac, ALint increment, const al::span<float> dst) { const ALfloat *const filter{state->bsinc.filter}; const float32x4_t sf4{vdupq_n_f32(state->bsinc.sf)}; - const ALsizei m{state->bsinc.m}; + const ptrdiff_t m{state->bsinc.m}; ASSUME(m > 0); ASSUME(increment > 0); - ASSUME(frac >= 0); src -= state->bsinc.l; for(float &out_sample : dst) { // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) - const ALsizei pi{frac >> FRAC_PHASE_BITDIFF}; + const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; const ALfloat pf{(frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF))}; #undef FRAC_PHASE_BITDIFF @@ -101,7 +99,7 @@ const ALfloat *Resample_<BSincTag,NEONTag>(const InterpState *state, const ALflo const float *scd{fil + m}; const float *phd{scd + m}; const float *spd{phd + m}; - ALsizei td{m >> 2}; + ptrdiff_t td{m >> 2}; size_t j{0u}; do { diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp index 8d2abc88..05ebe26f 100644 --- a/alc/mixer/mixer_sse.cpp +++ b/alc/mixer/mixer_sse.cpp @@ -15,22 +15,21 @@ template<> const ALfloat *Resample_<BSincTag,SSETag>(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst) + ALuint frac, ALint increment, const al::span<float> dst) { const ALfloat *const filter{state->bsinc.filter}; const __m128 sf4{_mm_set1_ps(state->bsinc.sf)}; - const ALsizei m{state->bsinc.m}; + const ptrdiff_t m{state->bsinc.m}; ASSUME(m > 0); ASSUME(increment > 0); - ASSUME(frac >= 0); src -= state->bsinc.l; for(float &out_sample : dst) { // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) - const ALsizei pi{frac >> FRAC_PHASE_BITDIFF}; + const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; const ALfloat pf{(frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF))}; #undef FRAC_PHASE_BITDIFF @@ -42,7 +41,7 @@ const ALfloat *Resample_<BSincTag,SSETag>(const InterpState *state, const ALfloa const float *scd{fil + m}; const float *phd{scd + m}; const float *spd{phd + m}; - ALsizei td{m >> 2}; + ptrdiff_t td{m >> 2}; size_t j{0u}; #define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z)) diff --git a/alc/mixer/mixer_sse2.cpp b/alc/mixer/mixer_sse2.cpp index e3443f4e..b126cd25 100644 --- a/alc/mixer/mixer_sse2.cpp +++ b/alc/mixer/mixer_sse2.cpp @@ -29,13 +29,12 @@ template<> const ALfloat *Resample_<LerpTag,SSE2Tag>(const InterpState*, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst) + ALuint frac, ALint increment, const al::span<float> dst) { const __m128i increment4{_mm_set1_epi32(increment*4)}; const __m128 fracOne4{_mm_set1_ps(1.0f/FRACTIONONE)}; const __m128i fracMask4{_mm_set1_epi32(FRACTIONMASK)}; - ASSUME(frac >= 0); ASSUME(increment > 0); alignas(16) ALsizei pos_[4], frac_[4]; @@ -70,15 +69,15 @@ const ALfloat *Resample_<LerpTag,SSE2Tag>(const InterpState*, const ALfloat *RES /* NOTE: These four elements represent the position *after* the last four * samples, so the lowest element is the next position to resample. */ - ALsizei pos{_mm_cvtsi128_si32(pos4)}; + src += static_cast<ALuint>(_mm_cvtsi128_si32(pos4)); frac = _mm_cvtsi128_si32(frac4); while(dst_iter != dst.end()) { - *(dst_iter++) = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); frac += increment; - pos += frac>>FRACTIONBITS; + src += frac>>FRACTIONBITS; frac &= FRACTIONMASK; } return dst.begin(); diff --git a/alc/mixer/mixer_sse41.cpp b/alc/mixer/mixer_sse41.cpp index 424b9b5f..06c51e6a 100644 --- a/alc/mixer/mixer_sse41.cpp +++ b/alc/mixer/mixer_sse41.cpp @@ -30,13 +30,12 @@ template<> const ALfloat *Resample_<LerpTag,SSE4Tag>(const InterpState*, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span<float> dst) + ALuint frac, ALint increment, const al::span<float> dst) { const __m128i increment4{_mm_set1_epi32(increment*4)}; const __m128 fracOne4{_mm_set1_ps(1.0f/FRACTIONONE)}; const __m128i fracMask4{_mm_set1_epi32(FRACTIONMASK)}; - ASSUME(frac >= 0); ASSUME(increment > 0); alignas(16) ALsizei pos_[4], frac_[4]; @@ -71,15 +70,15 @@ const ALfloat *Resample_<LerpTag,SSE4Tag>(const InterpState*, const ALfloat *RES /* NOTE: These four elements represent the position *after* the last four * samples, so the lowest element is the next position to resample. */ - ALsizei pos{_mm_cvtsi128_si32(pos4)}; + src += static_cast<ALuint>(_mm_cvtsi128_si32(pos4)); frac = _mm_cvtsi128_si32(frac4); while(dst_iter != dst.end()) { - *(dst_iter++) = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); frac += increment; - pos += frac>>FRACTIONBITS; + src += frac>>FRACTIONBITS; frac &= FRACTIONMASK; } return dst.begin(); diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 97583107..2d1a4655 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -482,7 +482,7 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) /* Get voice info */ const bool isstatic{(mFlags&VOICE_IS_STATIC) != 0}; ALuint DataPosInt{mPosition.load(std::memory_order_relaxed)}; - ALsizei DataPosFrac{mPositionFrac.load(std::memory_order_relaxed)}; + ALuint DataPosFrac{mPositionFrac.load(std::memory_order_relaxed)}; ALbufferlistitem *BufferListItem{mCurrentBuffer.load(std::memory_order_relaxed)}; ALbufferlistitem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)}; const ALsizei NumChannels{mNumChannels}; @@ -490,7 +490,6 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) const ALint increment{mStep}; if(increment < 1) return; - ASSUME(DataPosFrac >= 0); ASSUME(NumChannels > 0); ASSUME(SampleSize > 0); ASSUME(increment > 0); |