diff options
author | Chris Robinson <[email protected]> | 2019-09-12 17:45:06 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-09-12 17:45:06 -0700 |
commit | 5f862a5b49412ef2690a271ed240d5a6fc881b37 (patch) | |
tree | 6d71d22a3a31775ab554494cbb47bfff7598b540 /alc | |
parent | 5ca8796d6ab804841be2724ecb3daa134eb23c39 (diff) |
Clean up sample converter implicit conversions
Diffstat (limited to 'alc')
-rw-r--r-- | alc/alu.cpp | 4 | ||||
-rw-r--r-- | alc/alu.h | 2 | ||||
-rw-r--r-- | alc/converter.cpp | 58 | ||||
-rw-r--r-- | alc/converter.h | 8 | ||||
-rw-r--r-- | alc/mixvoice.cpp | 2 |
5 files changed, 38 insertions, 36 deletions
diff --git a/alc/alu.cpp b/alc/alu.cpp index a1c6ab7a..8fab0b06 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -951,7 +951,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons if(Pitch > static_cast<ALfloat>(MAX_PITCH)) voice->mStep = MAX_PITCH<<FRACTIONBITS; else - voice->mStep = maxi(fastf2i(Pitch * FRACTIONONE), 1); + voice->mStep = maxu(fastf2u(Pitch * FRACTIONONE), 1); if(props->mResampler == BSinc24Resampler) BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc24); else if(props->mResampler == BSinc12Resampler) @@ -1281,7 +1281,7 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A if(Pitch > static_cast<ALfloat>(MAX_PITCH)) voice->mStep = MAX_PITCH<<FRACTIONBITS; else - voice->mStep = maxi(fastf2i(Pitch * FRACTIONONE), 1); + voice->mStep = maxu(fastf2u(Pitch * FRACTIONONE), 1); if(props->mResampler == BSinc24Resampler) BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc24); else if(props->mResampler == BSinc12Resampler) @@ -236,7 +236,7 @@ struct ALvoice { ALuint mSampleSize; /** Current target parameters used for mixing. */ - ALint mStep; + ALuint mStep; ResamplerFunc mResampler; diff --git a/alc/converter.cpp b/alc/converter.cpp index faf24948..d7a57c12 100644 --- a/alc/converter.cpp +++ b/alc/converter.cpp @@ -32,11 +32,11 @@ template<> inline ALfloat LoadSample<DevFmtFloat>(DevFmtTypeTraits<DevFmtFloat>: { return val; } template<> inline ALfloat LoadSample<DevFmtUByte>(DevFmtTypeTraits<DevFmtUByte>::Type val) noexcept -{ return LoadSample<DevFmtByte>(val - 128); } +{ return LoadSample<DevFmtByte>(static_cast<ALbyte>(val - 128)); } template<> inline ALfloat LoadSample<DevFmtUShort>(DevFmtTypeTraits<DevFmtUShort>::Type val) noexcept -{ return LoadSample<DevFmtShort>(val - 32768); } +{ return LoadSample<DevFmtShort>(static_cast<ALshort>(val - 32768)); } template<> inline ALfloat LoadSample<DevFmtUInt>(DevFmtTypeTraits<DevFmtUInt>::Type val) noexcept -{ return LoadSample<DevFmtInt>(val - 2147483648u); } +{ return LoadSample<DevFmtInt>(static_cast<ALint>(val - 2147483648u)); } template<DevFmtType T> @@ -77,17 +77,17 @@ template<> inline ALfloat StoreSample<DevFmtFloat>(ALfloat val) noexcept template<> inline ALint StoreSample<DevFmtInt>(ALfloat val) noexcept { return fastf2i(clampf(val*2147483648.0f, -2147483648.0f, 2147483520.0f)); } template<> inline ALshort StoreSample<DevFmtShort>(ALfloat val) noexcept -{ return fastf2i(clampf(val*32768.0f, -32768.0f, 32767.0f)); } +{ return static_cast<ALshort>(fastf2i(clampf(val*32768.0f, -32768.0f, 32767.0f))); } template<> inline ALbyte StoreSample<DevFmtByte>(ALfloat val) noexcept -{ return fastf2i(clampf(val*128.0f, -128.0f, 127.0f)); } +{ return static_cast<ALbyte>(fastf2i(clampf(val*128.0f, -128.0f, 127.0f))); } /* Define unsigned output variations. */ template<> inline ALuint StoreSample<DevFmtUInt>(ALfloat val) noexcept -{ return StoreSample<DevFmtInt>(val) + 2147483648u; } +{ return static_cast<ALuint>(StoreSample<DevFmtInt>(val)) + 2147483648u; } template<> inline ALushort StoreSample<DevFmtUShort>(ALfloat val) noexcept -{ return StoreSample<DevFmtShort>(val) + 32768; } +{ return static_cast<ALushort>(StoreSample<DevFmtShort>(val) + 32768); } template<> inline ALubyte StoreSample<DevFmtUByte>(ALfloat val) noexcept -{ return StoreSample<DevFmtByte>(val) + 128; } +{ return static_cast<ALubyte>(StoreSample<DevFmtByte>(val) + 128); } template<DevFmtType T> inline void StoreSampleArray(void *dst, const ALfloat *RESTRICT src, const size_t dststep, @@ -152,17 +152,17 @@ SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, SampleConverterPtr converter{new (FamCount{numchans}) SampleConverter{numchans}}; converter->mSrcType = srcType; converter->mDstType = dstType; - converter->mSrcTypeSize = BytesFromDevFmt(srcType); - converter->mDstTypeSize = BytesFromDevFmt(dstType); + converter->mSrcTypeSize = static_cast<ALuint>(BytesFromDevFmt(srcType)); + converter->mDstTypeSize = static_cast<ALuint>(BytesFromDevFmt(dstType)); converter->mSrcPrepCount = 0; converter->mFracOffset = 0; /* Have to set the mixer FPU mode since that's what the resampler code expects. */ FPUCtl mixer_mode{}; - auto step = static_cast<ALsizei>( + auto step = static_cast<ALuint>( mind(srcRate*ALdouble{FRACTIONONE}/dstRate + 0.5, MAX_PITCH*FRACTIONONE)); - converter->mIncrement = maxi(step, 1); + converter->mIncrement = maxu(step, 1); if(converter->mIncrement == FRACTIONONE) converter->mResample = Resample_<CopyTag,CTag>; else @@ -185,7 +185,7 @@ ALuint SampleConverter::availableOut(ALuint srcframes) const /* Negative prepcount means we need to skip that many input samples. */ if(static_cast<ALuint>(-prepcount) >= srcframes) return 0; - srcframes += prepcount; + srcframes -= static_cast<ALuint>(-prepcount); prepcount = 0; } @@ -214,9 +214,9 @@ ALuint SampleConverter::availableOut(ALuint srcframes) const ALuint SampleConverter::convert(const ALvoid **src, ALuint *srcframes, ALvoid *dst, ALuint dstframes) { - const ALsizei SrcFrameSize{static_cast<ALsizei>(mChan.size()) * mSrcTypeSize}; - const ALsizei DstFrameSize{static_cast<ALsizei>(mChan.size()) * mDstTypeSize}; - const ALsizei increment{mIncrement}; + const ALuint SrcFrameSize{static_cast<ALuint>(mChan.size()) * mSrcTypeSize}; + const ALuint DstFrameSize{static_cast<ALuint>(mChan.size()) * mDstTypeSize}; + const ALuint increment{mIncrement}; auto SamplesIn = static_cast<const al::byte*>(*src); ALuint NumSrcSamples{*srcframes}; @@ -230,12 +230,12 @@ ALuint SampleConverter::convert(const ALvoid **src, ALuint *srcframes, ALvoid *d /* Negative prepcount means we need to skip that many input samples. */ if(static_cast<ALuint>(-prepcount) >= NumSrcSamples) { - mSrcPrepCount = prepcount + NumSrcSamples; + mSrcPrepCount = static_cast<ALint>(NumSrcSamples) + prepcount; NumSrcSamples = 0; break; } - SamplesIn += SrcFrameSize*-prepcount; - NumSrcSamples += prepcount; + SamplesIn += SrcFrameSize*static_cast<ALuint>(-prepcount); + NumSrcSamples -= static_cast<ALuint>(-prepcount); mSrcPrepCount = 0; continue; } @@ -251,14 +251,14 @@ ALuint SampleConverter::convert(const ALvoid **src, ALuint *srcframes, ALvoid *d LoadSamples(&mChan[chan].PrevSamples[prepcount], SamplesIn + mSrcTypeSize*chan, mChan.size(), mSrcType, toread); - mSrcPrepCount = prepcount + toread; + mSrcPrepCount = prepcount + static_cast<ALint>(toread); NumSrcSamples = 0; break; } ALfloat *RESTRICT SrcData{mSrcSamples}; ALfloat *RESTRICT DstData{mDstSamples}; - ALsizei DataPosFrac{mFracOffset}; + ALuint DataPosFrac{mFracOffset}; auto DataSize64 = static_cast<uint64_t>(prepcount); DataSize64 += toread; DataSize64 -= MAX_RESAMPLE_PADDING*2; @@ -285,20 +285,21 @@ ALuint SampleConverter::convert(const ALvoid **src, ALuint *srcframes, ALvoid *d * number of output samples being generated. */ ALuint SrcDataEnd{(DstSize*increment + DataPosFrac)>>FRACTIONBITS}; - if(SrcDataEnd >= prepcount+toread) + if(SrcDataEnd >= static_cast<ALuint>(prepcount)+toread) std::fill(std::begin(mChan[chan].PrevSamples), - std::end(mChan[chan].PrevSamples), 0.0f); + std::end(mChan[chan].PrevSamples), 0.0f); else { - size_t len{minu(MAX_RESAMPLE_PADDING*2, prepcount+toread-SrcDataEnd)}; + const size_t len{minz(al::size(mChan[chan].PrevSamples), + static_cast<ALuint>(prepcount)+toread-SrcDataEnd)}; std::copy_n(SrcData+SrcDataEnd, len, mChan[chan].PrevSamples); std::fill(std::begin(mChan[chan].PrevSamples)+len, - std::end(mChan[chan].PrevSamples), 0.0f); + std::end(mChan[chan].PrevSamples), 0.0f); } /* Now resample, and store the result in the output buffer. */ const ALfloat *ResampledData{mResample(&mState, SrcData+MAX_RESAMPLE_PADDING, - DataPosFrac, increment, {DstData, DstSize})}; + DataPosFrac, static_cast<ALint>(increment), {DstData, DstSize})}; StoreSamples(DstSamples, ResampledData, mChan.size(), mDstType, DstSize); } @@ -307,7 +308,7 @@ ALuint SampleConverter::convert(const ALvoid **src, ALuint *srcframes, ALvoid *d * fractional offset. */ DataPosFrac += increment*DstSize; - mSrcPrepCount = mini(prepcount + toread - (DataPosFrac>>FRACTIONBITS), + mSrcPrepCount = mini(prepcount + static_cast<ALint>(toread - (DataPosFrac>>FRACTIONBITS)), MAX_RESAMPLE_PADDING*2); mFracOffset = DataPosFrac & FRACTIONMASK; @@ -359,5 +360,6 @@ void ChannelConverter::convert(const ALvoid *src, ALfloat *dst, ALuint frames) c } } else - LoadSamples(dst, src, 1u, mSrcType, frames*ChannelsFromDevFmt(mSrcChans, 0)); + LoadSamples(dst, src, 1u, mSrcType, + frames*static_cast<ALuint>(ChannelsFromDevFmt(mSrcChans, 0))); } diff --git a/alc/converter.h b/alc/converter.h index 8a7b6f5f..8390eae3 100644 --- a/alc/converter.h +++ b/alc/converter.h @@ -16,13 +16,13 @@ struct SampleConverter { DevFmtType mSrcType{}; DevFmtType mDstType{}; - ALsizei mSrcTypeSize{}; - ALsizei mDstTypeSize{}; + ALuint mSrcTypeSize{}; + ALuint mDstTypeSize{}; ALint mSrcPrepCount{}; - ALsizei mFracOffset{}; - ALsizei mIncrement{}; + ALuint mFracOffset{}; + ALuint mIncrement{}; InterpState mState{}; ResamplerFunc mResample{}; diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index acc3af1d..c5eae591 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -487,7 +487,7 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) ALbufferlistitem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)}; const ALuint NumChannels{mNumChannels}; const ALuint SampleSize{mSampleSize}; - const auto increment = static_cast<ALuint>(mStep); + const ALuint increment{mStep}; if(increment < 1) return; ASSUME(NumChannels > 0); |