diff options
Diffstat (limited to 'alc/converter.cpp')
-rw-r--r-- | alc/converter.cpp | 58 |
1 files changed, 30 insertions, 28 deletions
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))); } |