From 7e798df7b87dc4ca4821e3b16e337d7106c7e1cf Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 27 Nov 2020 21:40:02 -0800 Subject: Avoid AL types in the converter --- alc/converter.cpp | 82 +++++++++++++++++++++++++++---------------------------- alc/converter.h | 22 ++++++++------- 2 files changed, 52 insertions(+), 52 deletions(-) (limited to 'alc') diff --git a/alc/converter.cpp b/alc/converter.cpp index 1eab59bb..2b881645 100644 --- a/alc/converter.cpp +++ b/alc/converter.cpp @@ -7,8 +7,6 @@ #include #include -#include "AL/al.h" - #include "albyte.h" #include "alu.h" #include "fpu_ctrl.h" @@ -36,11 +34,11 @@ template<> inline float LoadSample(DevFmtTypeTraits::T { return val; } template<> inline float LoadSample(DevFmtTypeTraits::Type val) noexcept -{ return LoadSample(static_cast(val - 128)); } +{ return LoadSample(static_cast(val - 128)); } template<> inline float LoadSample(DevFmtTypeTraits::Type val) noexcept -{ return LoadSample(static_cast(val - 32768)); } +{ return LoadSample(static_cast(val - 32768)); } template<> inline float LoadSample(DevFmtTypeTraits::Type val) noexcept -{ return LoadSample(static_cast(val - 2147483648u)); } +{ return LoadSample(static_cast(val - 2147483648u)); } template @@ -76,22 +74,22 @@ void LoadSamples(float *dst, const void *src, const size_t srcstep, const DevFmt template inline typename DevFmtTypeTraits::Type StoreSample(float) noexcept; -template<> inline ALfloat StoreSample(float val) noexcept +template<> inline float StoreSample(float val) noexcept { return val; } -template<> inline ALint StoreSample(float val) noexcept +template<> inline int32_t StoreSample(float val) noexcept { return fastf2i(clampf(val*2147483648.0f, -2147483648.0f, 2147483520.0f)); } -template<> inline ALshort StoreSample(float val) noexcept -{ return static_cast(fastf2i(clampf(val*32768.0f, -32768.0f, 32767.0f))); } -template<> inline ALbyte StoreSample(float val) noexcept -{ return static_cast(fastf2i(clampf(val*128.0f, -128.0f, 127.0f))); } +template<> inline int16_t StoreSample(float val) noexcept +{ return static_cast(fastf2i(clampf(val*32768.0f, -32768.0f, 32767.0f))); } +template<> inline int8_t StoreSample(float val) noexcept +{ return static_cast(fastf2i(clampf(val*128.0f, -128.0f, 127.0f))); } /* Define unsigned output variations. */ -template<> inline ALuint StoreSample(float val) noexcept -{ return static_cast(StoreSample(val)) + 2147483648u; } -template<> inline ALushort StoreSample(float val) noexcept -{ return static_cast(StoreSample(val) + 32768); } -template<> inline ALubyte StoreSample(float val) noexcept -{ return static_cast(StoreSample(val) + 128); } +template<> inline uint32_t StoreSample(float val) noexcept +{ return static_cast(StoreSample(val)) + 2147483648u; } +template<> inline uint16_t StoreSample(float val) noexcept +{ return static_cast(StoreSample(val) + 32768); } +template<> inline uint8_t StoreSample(float val) noexcept +{ return static_cast(StoreSample(val) + 128); } template inline void StoreSampleArray(void *dst, const float *RESTRICT src, const size_t dststep, @@ -135,7 +133,7 @@ void Mono2Stereo(float *RESTRICT dst, const void *src, const size_t frames) noex } template -void Multi2Mono(ALuint chanmask, const size_t step, const float scale, float *RESTRICT dst, +void Multi2Mono(uint chanmask, const size_t step, const float scale, float *RESTRICT dst, const void *src, const size_t frames) noexcept { using SampleType = typename DevFmtTypeTraits::Type; @@ -158,7 +156,7 @@ void Multi2Mono(ALuint chanmask, const size_t step, const float scale, float *RE } // namespace SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, size_t numchans, - ALuint srcRate, ALuint dstRate, Resampler resampler) + uint srcRate, uint dstRate, Resampler resampler) { if(numchans < 1 || srcRate < 1 || dstRate < 1) return nullptr; @@ -174,7 +172,7 @@ SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, /* Have to set the mixer FPU mode since that's what the resampler code expects. */ FPUCtl mixer_mode{}; - auto step = static_cast( + auto step = static_cast( mind(srcRate*double{MixerFracOne}/dstRate + 0.5, MAX_PITCH*MixerFracOne)); converter->mIncrement = maxu(step, 1); if(converter->mIncrement == MixerFracOne) @@ -186,15 +184,15 @@ SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, return converter; } -ALuint SampleConverter::availableOut(ALuint srcframes) const +uint SampleConverter::availableOut(uint srcframes) const { int prepcount{mSrcPrepCount}; if(prepcount < 0) { /* Negative prepcount means we need to skip that many input samples. */ - if(static_cast(-prepcount) >= srcframes) + if(static_cast(-prepcount) >= srcframes) return 0; - srcframes -= static_cast(-prepcount); + srcframes -= static_cast(-prepcount); prepcount = 0; } @@ -205,7 +203,7 @@ ALuint SampleConverter::availableOut(ALuint srcframes) const } if(prepcount < MAX_RESAMPLER_PADDING - && static_cast(MAX_RESAMPLER_PADDING - prepcount) >= srcframes) + && static_cast(MAX_RESAMPLER_PADDING - prepcount) >= srcframes) { /* Not enough input samples to generate an output sample. */ return 0; @@ -218,41 +216,41 @@ ALuint SampleConverter::availableOut(ALuint srcframes) const DataSize64 -= mFracOffset; /* If we have a full prep, we can generate at least one sample. */ - return static_cast(clampu64((DataSize64 + mIncrement-1)/mIncrement, 1, + return static_cast(clampu64((DataSize64 + mIncrement-1)/mIncrement, 1, std::numeric_limits::max())); } -ALuint SampleConverter::convert(const void **src, ALuint *srcframes, void *dst, ALuint dstframes) +uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint dstframes) { - const ALuint SrcFrameSize{static_cast(mChan.size()) * mSrcTypeSize}; - const ALuint DstFrameSize{static_cast(mChan.size()) * mDstTypeSize}; - const ALuint increment{mIncrement}; + const uint SrcFrameSize{static_cast(mChan.size()) * mSrcTypeSize}; + const uint DstFrameSize{static_cast(mChan.size()) * mDstTypeSize}; + const uint increment{mIncrement}; auto SamplesIn = static_cast(*src); - ALuint NumSrcSamples{*srcframes}; + uint NumSrcSamples{*srcframes}; FPUCtl mixer_mode{}; - ALuint pos{0}; + uint pos{0}; while(pos < dstframes && NumSrcSamples > 0) { int prepcount{mSrcPrepCount}; if(prepcount < 0) { /* Negative prepcount means we need to skip that many input samples. */ - if(static_cast(-prepcount) >= NumSrcSamples) + if(static_cast(-prepcount) >= NumSrcSamples) { mSrcPrepCount = static_cast(NumSrcSamples) + prepcount; NumSrcSamples = 0; break; } - SamplesIn += SrcFrameSize*static_cast(-prepcount); - NumSrcSamples -= static_cast(-prepcount); + SamplesIn += SrcFrameSize*static_cast(-prepcount); + NumSrcSamples -= static_cast(-prepcount); mSrcPrepCount = 0; continue; } - ALuint toread{minu(NumSrcSamples, BUFFERSIZE - MAX_RESAMPLER_PADDING)}; + uint toread{minu(NumSrcSamples, BUFFERSIZE - MAX_RESAMPLER_PADDING)}; if(prepcount < MAX_RESAMPLER_PADDING - && static_cast(MAX_RESAMPLER_PADDING - prepcount) >= toread) + && static_cast(MAX_RESAMPLER_PADDING - prepcount) >= toread) { /* Not enough input samples to generate an output sample. Store * what we're given for later. @@ -268,7 +266,7 @@ ALuint SampleConverter::convert(const void **src, ALuint *srcframes, void *dst, float *RESTRICT SrcData{mSrcSamples}; float *RESTRICT DstData{mDstSamples}; - ALuint DataPosFrac{mFracOffset}; + uint DataPosFrac{mFracOffset}; auto DataSize64 = static_cast(prepcount); DataSize64 += toread; DataSize64 -= MAX_RESAMPLER_PADDING; @@ -276,7 +274,7 @@ ALuint SampleConverter::convert(const void **src, ALuint *srcframes, void *dst, DataSize64 -= DataPosFrac; /* If we have a full prep, we can generate at least one sample. */ - auto DstSize = static_cast( + auto DstSize = static_cast( clampu64((DataSize64 + increment-1)/increment, 1, BUFFERSIZE)); DstSize = minu(DstSize, dstframes-pos); @@ -294,14 +292,14 @@ ALuint SampleConverter::convert(const void **src, ALuint *srcframes, void *dst, /* Store as many prep samples for next time as possible, given the * number of output samples being generated. */ - ALuint SrcDataEnd{(DstSize*increment + DataPosFrac)>>MixerFracBits}; - if(SrcDataEnd >= static_cast(prepcount)+toread) + uint SrcDataEnd{(DstSize*increment + DataPosFrac)>>MixerFracBits}; + if(SrcDataEnd >= static_cast(prepcount)+toread) std::fill(std::begin(mChan[chan].PrevSamples), std::end(mChan[chan].PrevSamples), 0.0f); else { const size_t len{minz(al::size(mChan[chan].PrevSamples), - static_cast(prepcount)+toread-SrcDataEnd)}; + static_cast(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); @@ -337,7 +335,7 @@ ALuint SampleConverter::convert(const void **src, ALuint *srcframes, void *dst, } -void ChannelConverter::convert(const void *src, float *dst, ALuint frames) const +void ChannelConverter::convert(const void *src, float *dst, uint frames) const { if(mDstChans == DevFmtMono) { diff --git a/alc/converter.h b/alc/converter.h index a97d1ea5..392c95e5 100644 --- a/alc/converter.h +++ b/alc/converter.h @@ -13,17 +13,19 @@ #include "core/devformat.h" #include "voice.h" +using uint = unsigned int; + struct SampleConverter { DevFmtType mSrcType{}; DevFmtType mDstType{}; - ALuint mSrcTypeSize{}; - ALuint mDstTypeSize{}; + uint mSrcTypeSize{}; + uint mDstTypeSize{}; int mSrcPrepCount{}; - ALuint mFracOffset{}; - ALuint mIncrement{}; + uint mFracOffset{}; + uint mIncrement{}; InterpState mState{}; ResamplerFunc mResample{}; @@ -37,26 +39,26 @@ struct SampleConverter { SampleConverter(size_t numchans) : mChan{numchans} { } - ALuint convert(const void **src, ALuint *srcframes, void *dst, ALuint dstframes); - ALuint availableOut(ALuint srcframes) const; + uint convert(const void **src, uint *srcframes, void *dst, uint dstframes); + uint availableOut(uint srcframes) const; DEF_FAM_NEWDEL(SampleConverter, mChan) }; using SampleConverterPtr = std::unique_ptr; SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, size_t numchans, - ALuint srcRate, ALuint dstRate, Resampler resampler); + uint srcRate, uint dstRate, Resampler resampler); struct ChannelConverter { DevFmtType mSrcType{}; - ALuint mSrcStep{}; - ALuint mChanMask{}; + uint mSrcStep{}; + uint mChanMask{}; DevFmtChannels mDstChans{}; bool is_active() const noexcept { return mChanMask != 0; } - void convert(const void *src, float *dst, ALuint frames) const; + void convert(const void *src, float *dst, uint frames) const; }; #endif /* CONVERTER_H */ -- cgit v1.2.3