From 4720b2c64d91facea24e8411c104770bd3763afa Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 23 Dec 2023 03:07:57 -0800 Subject: Fix implicit widening after multiplication --- alc/backends/oss.cpp | 2 +- alc/backends/pipewire.cpp | 2 +- alc/backends/sndio.cpp | 4 ++-- core/converter.cpp | 14 +++++++------- core/hrtf.cpp | 2 +- core/mastering.h | 3 ++- core/mixer/mixer_c.cpp | 6 +++--- core/mixer/mixer_neon.cpp | 6 +++--- core/mixer/mixer_sse.cpp | 6 +++--- core/voice.cpp | 10 +++++----- examples/alffplay.cpp | 16 ++++++++-------- examples/alstream.c | 12 ++++++------ utils/makemhr/loaddef.cpp | 21 +++++++++++---------- utils/makemhr/loadsofa.cpp | 19 ++++++++++--------- utils/makemhr/makemhr.cpp | 39 +++++++++++++++++++-------------------- utils/uhjdecoder.cpp | 6 +++--- utils/uhjencoder.cpp | 10 +++++----- 17 files changed, 90 insertions(+), 88 deletions(-) diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 9a4aa9a8..50bed5ee 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -409,7 +409,7 @@ bool OSSPlayback::reset() setDefaultChannelOrder(); - mMixData.resize(mDevice->UpdateSize * mDevice->frameSizeFromFmt()); + mMixData.resize(size_t{mDevice->UpdateSize} * mDevice->frameSizeFromFmt()); return true; } diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp index 7b206d2d..44b84296 100644 --- a/alc/backends/pipewire.cpp +++ b/alc/backends/pipewire.cpp @@ -1771,7 +1771,7 @@ void PipeWirePlayback::start() mDevice->UpdateSize = updatesize; mDevice->BufferSize = static_cast(ptime.buffered + delay + - totalbuffers*updatesize); + uint64_t{totalbuffers}*updatesize); break; } #else diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 2cb577fd..0e667874 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -228,7 +228,7 @@ retry_params: mDevice->UpdateSize = par.round; mDevice->BufferSize = par.bufsz + par.round; - mBuffer.resize(mDevice->UpdateSize * par.pchan*par.bps); + mBuffer.resize(size_t{mDevice->UpdateSize} * par.pchan*par.bps); if(par.sig == 1) std::fill(mBuffer.begin(), mBuffer.end(), std::byte{}); else if(par.bits == 8) @@ -458,7 +458,7 @@ void SndioCapture::open(std::string_view name) DevFmtTypeString(mDevice->FmtType), DevFmtChannelsString(mDevice->FmtChans), mDevice->Frequency, par.sig?'s':'u', par.bps*8, par.rchan, par.rate}; - mRing = RingBuffer::Create(mDevice->BufferSize, par.bps*par.rchan, false); + mRing = RingBuffer::Create(mDevice->BufferSize, size_t{par.bps}*par.rchan, false); mDevice->BufferSize = static_cast(mRing->writeSpace()); mDevice->UpdateSize = par.round; diff --git a/core/converter.cpp b/core/converter.cpp index b3ff5b0a..805b8548 100644 --- a/core/converter.cpp +++ b/core/converter.cpp @@ -213,8 +213,8 @@ uint SampleConverter::availableOut(uint srcframes) const uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint dstframes) { - const uint SrcFrameSize{static_cast(mChan.size()) * mSrcTypeSize}; - const uint DstFrameSize{static_cast(mChan.size()) * mDstTypeSize}; + const size_t SrcFrameSize{mChan.size() * mSrcTypeSize}; + const size_t DstFrameSize{mChan.size() * mDstTypeSize}; const uint increment{mIncrement}; auto SamplesIn = static_cast(*src); uint NumSrcSamples{*srcframes}; @@ -325,9 +325,9 @@ uint SampleConverter::convertPlanar(const void **src, uint *srcframes, void *con */ for(size_t chan{0u};chan < mChan.size();chan++) { - LoadSamples(&mChan[chan].PrevSamples[prepcount], - static_cast(src[chan]), 1, mSrcType, readable); - src[chan] = static_cast(src[chan]) + mSrcTypeSize*readable; + auto *samples = static_cast(src[chan]); + LoadSamples(&mChan[chan].PrevSamples[prepcount], samples, 1, mSrcType, readable); + src[chan] = samples + size_t{mSrcTypeSize}*readable; } mSrcPrepCount = prepcount + readable; @@ -374,7 +374,7 @@ uint SampleConverter::convertPlanar(const void **src, uint *srcframes, void *con mResample(&mState, SrcData+MaxResamplerEdge, DataPosFrac, increment, {DstData, DstSize}); - std::byte *DstSamples = static_cast(dst[chan]) + pos*mDstTypeSize; + auto *DstSamples = static_cast(dst[chan]) + pos*size_t{mDstTypeSize}; StoreSamples(DstSamples, DstData, 1, mDstType, DstSize); } @@ -387,7 +387,7 @@ uint SampleConverter::convertPlanar(const void **src, uint *srcframes, void *con /* Update the src and dst pointers in case there's still more to do. */ const uint srcread{minu(NumSrcSamples, SrcDataEnd + mSrcPrepCount - prepcount)}; for(size_t chan{0u};chan < mChan.size();chan++) - src[chan] = static_cast(src[chan]) + mSrcTypeSize*srcread; + src[chan] = static_cast(src[chan]) + size_t{mSrcTypeSize}*srcread; NumSrcSamples -= srcread; pos += DstSize; diff --git a/core/hrtf.cpp b/core/hrtf.cpp index a3faee49..8fc4030e 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -270,7 +270,7 @@ void HrtfStore::getCoeffs(float elevation, float azimuth, float distance, float const float mult{blend[c]}; auto blend_coeffs = [mult](const float src, const float coeff) noexcept -> float { return src*mult + coeff; }; - std::transform(srccoeffs, srccoeffs + HrirLength*2, coeffout, coeffout, blend_coeffs); + std::transform(srccoeffs, srccoeffs + HrirLength*2_uz, coeffout, coeffout, blend_coeffs); } } diff --git a/core/mastering.h b/core/mastering.h index 08f3678e..8baea601 100644 --- a/core/mastering.h +++ b/core/mastering.h @@ -5,6 +5,7 @@ #include #include "almalloc.h" +#include "alnumeric.h" #include "bufferline.h" struct SlidingHold; @@ -45,7 +46,7 @@ struct Compressor { float mAttack{0.0f}; float mRelease{0.0f}; - alignas(16) std::array mSideChain{}; + alignas(16) std::array mSideChain{}; alignas(16) std::array mCrestFactor{}; SlidingHold *mHold{nullptr}; diff --git a/core/mixer/mixer_c.cpp b/core/mixer/mixer_c.cpp index 971297a4..93306bba 100644 --- a/core/mixer/mixer_c.cpp +++ b/core/mixer/mixer_c.cpp @@ -54,9 +54,9 @@ inline float do_bsinc(const BsincState &istate, const float *RESTRICT vals, cons const uint pi{frac >> BsincPhaseDiffBits}; const float pf{static_cast(frac&BsincPhaseDiffMask) * (1.0f/BsincPhaseDiffOne)}; - const float *RESTRICT fil{istate.filter + m*pi*2}; + const float *RESTRICT fil{istate.filter + m*pi*2_uz}; const float *RESTRICT phd{fil + m}; - const float *RESTRICT scd{fil + BSincPhaseCount*2*m}; + const float *RESTRICT scd{fil + BSincPhaseCount*2_uz*m}; const float *RESTRICT spd{scd + m}; /* Apply the scale and phase interpolated filter. */ @@ -74,7 +74,7 @@ inline float do_fastbsinc(const BsincState &istate, const float *RESTRICT vals, const uint pi{frac >> BsincPhaseDiffBits}; const float pf{static_cast(frac&BsincPhaseDiffMask) * (1.0f/BsincPhaseDiffOne)}; - const float *RESTRICT fil{istate.filter + m*pi*2}; + const float *RESTRICT fil{istate.filter + m*pi*2_uz}; const float *RESTRICT phd{fil + m}; /* Apply the phase interpolated filter. */ diff --git a/core/mixer/mixer_neon.cpp b/core/mixer/mixer_neon.cpp index 59369215..9fa2425f 100644 --- a/core/mixer/mixer_neon.cpp +++ b/core/mixer/mixer_neon.cpp @@ -244,9 +244,9 @@ void Resample_(const InterpState *state, const float *RESTRICT float32x4_t r4{vdupq_n_f32(0.0f)}; { const float32x4_t pf4{vdupq_n_f32(pf)}; - const float *RESTRICT fil{filter + m*pi*2}; + const float *RESTRICT fil{filter + m*pi*2_uz}; const float *RESTRICT phd{fil + m}; - const float *RESTRICT scd{fil + BSincPhaseCount*2*m}; + const float *RESTRICT scd{fil + BSincPhaseCount*2_uz*m}; const float *RESTRICT spd{scd + m}; size_t td{m >> 2}; size_t j{0u}; @@ -291,7 +291,7 @@ void Resample_(const InterpState *state, const float *REST float32x4_t r4{vdupq_n_f32(0.0f)}; { const float32x4_t pf4{vdupq_n_f32(pf)}; - const float *RESTRICT fil{filter + m*pi*2}; + const float *RESTRICT fil{filter + m*pi*2_uz}; const float *RESTRICT phd{fil + m}; size_t td{m >> 2}; size_t j{0u}; diff --git a/core/mixer/mixer_sse.cpp b/core/mixer/mixer_sse.cpp index 731ed884..809d585d 100644 --- a/core/mixer/mixer_sse.cpp +++ b/core/mixer/mixer_sse.cpp @@ -208,9 +208,9 @@ void Resample_(const InterpState *state, const float *RESTRICT __m128 r4{_mm_setzero_ps()}; { const __m128 pf4{_mm_set1_ps(pf)}; - const float *RESTRICT fil{filter + m*pi*2}; + const float *RESTRICT fil{filter + m*pi*2_uz}; const float *RESTRICT phd{fil + m}; - const float *RESTRICT scd{fil + BSincPhaseCount*2*m}; + const float *RESTRICT scd{fil + BSincPhaseCount*2_uz*m}; const float *RESTRICT spd{scd + m}; size_t td{m >> 2}; size_t j{0u}; @@ -256,7 +256,7 @@ void Resample_(const InterpState *state, const float *RESTR __m128 r4{_mm_setzero_ps()}; { const __m128 pf4{_mm_set1_ps(pf)}; - const float *RESTRICT fil{filter + m*pi*2}; + const float *RESTRICT fil{filter + m*pi*2_uz}; const float *RESTRICT phd{fil + m}; size_t td{m >> 2}; size_t j{0u}; diff --git a/core/voice.cpp b/core/voice.cpp index 1272b202..4a30ee83 100644 --- a/core/voice.cpp +++ b/core/voice.cpp @@ -904,8 +904,8 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi const size_t needBlocks{(needSamples + mSamplesPerBlock-1) / mSamplesPerBlock}; if(!mFlags.test(VoiceCallbackStopped) && needBlocks > mNumCallbackBlocks) { - const size_t byteOffset{mNumCallbackBlocks*mBytesPerBlock}; - const size_t needBytes{(needBlocks-mNumCallbackBlocks)*mBytesPerBlock}; + const size_t byteOffset{mNumCallbackBlocks*size_t{mBytesPerBlock}}; + const size_t needBytes{(needBlocks-mNumCallbackBlocks)*size_t{mBytesPerBlock}}; const int gotBytes{BufferListItem->mCallback(BufferListItem->mUserData, &BufferListItem->mSamples[byteOffset], static_cast(needBytes))}; @@ -919,7 +919,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi else mNumCallbackBlocks = static_cast(needBlocks); } - const size_t numSamples{uint{mNumCallbackBlocks} * mSamplesPerBlock}; + const size_t numSamples{size_t{mNumCallbackBlocks} * mSamplesPerBlock}; LoadBufferCallback(BufferListItem, bufferOffset, numSamples, mFmtType, chan, mFrameStep, srcSampleDelay, srcBufferSize, al::to_address(resampleBuffer)); } @@ -1099,8 +1099,8 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi const uint blocksDone{currentBlock - mCallbackBlockBase}; if(blocksDone < mNumCallbackBlocks) { - const size_t byteOffset{blocksDone*mBytesPerBlock}; - const size_t byteEnd{mNumCallbackBlocks*mBytesPerBlock}; + const size_t byteOffset{blocksDone*size_t{mBytesPerBlock}}; + const size_t byteEnd{mNumCallbackBlocks*size_t{mBytesPerBlock}}; std::byte *data{BufferListItem->mSamples}; std::copy(data+byteOffset, data+byteEnd, data); mNumCallbackBlocks -= blocksDone; diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index 7a4b7aac..890ecedb 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -285,7 +285,7 @@ struct AudioState { AVStream *mStream{nullptr}; AVCodecCtxPtr mCodecCtx; - DataQueue<2*1024*1024> mQueue; + DataQueue mQueue; /* Used for clock difference average computation */ seconds_d64 mClockDiffAvg{0}; @@ -372,7 +372,7 @@ struct VideoState { AVStream *mStream{nullptr}; AVCodecCtxPtr mCodecCtx; - DataQueue<14*1024*1024> mQueue; + DataQueue mQueue; /* The pts of the currently displayed frame, and the time (av_gettime) it * was last updated - used to have running video pts @@ -738,8 +738,8 @@ bool AudioState::readAudio(uint8_t *samples, unsigned int length, int &sample_sk { const auto len = static_cast(mSamplesLen - mSamplesPos); if(rem > len) rem = len; - std::copy_n(mSamples + static_cast(mSamplesPos)*mFrameSize, - rem*mFrameSize, samples); + std::copy_n(mSamples + static_cast(mSamplesPos)*size_t{mFrameSize}, + rem*size_t{mFrameSize}, samples); } else { @@ -751,7 +751,7 @@ bool AudioState::readAudio(uint8_t *samples, unsigned int length, int &sample_sk mSamplesPos += static_cast(rem); mCurrentPts += nanoseconds{seconds{rem}} / mCodecCtx->sample_rate; - samples += rem*mFrameSize; + samples += rem*size_t{mFrameSize}; audio_size += rem; while(mSamplesPos >= mSamplesLen) @@ -1165,7 +1165,7 @@ int AudioState::handler() * ordering and normalization, so a custom matrix is needed to * scale and reorder the source from AmbiX. */ - std::vector mtx(64*64, 0.0); + std::vector mtx(size_t{64}*64, 0.0); mtx[0 + 0*64] = std::sqrt(0.5); mtx[3 + 1*64] = 1.0; mtx[1 + 2*64] = 1.0; @@ -1546,8 +1546,8 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer, bool re /* point pict at the queue */ std::array pict_data; pict_data[0] = static_cast(pixels); - pict_data[1] = pict_data[0] + w*h; - pict_data[2] = pict_data[1] + w*h/4; + pict_data[1] = pict_data[0] + ptrdiff_t{w}*h; + pict_data[2] = pict_data[1] + ptrdiff_t{w}*h/4; std::array pict_linesize{pitch, pitch/2, pitch/2}; diff --git a/examples/alstream.c b/examples/alstream.c index 5cbbc2a7..c781f3d7 100644 --- a/examples/alstream.c +++ b/examples/alstream.c @@ -338,21 +338,21 @@ static int StartPlayer(StreamPlayer *player) if(player->sample_type == Int16) { slen = sf_readf_short(player->sndfile, player->membuf, - player->block_count * player->sampleblockalign); + (sf_count_t)player->block_count * player->sampleblockalign); if(slen < 1) break; slen *= player->byteblockalign; } else if(player->sample_type == Float) { slen = sf_readf_float(player->sndfile, player->membuf, - player->block_count * player->sampleblockalign); + (sf_count_t)player->block_count * player->sampleblockalign); if(slen < 1) break; slen *= player->byteblockalign; } else { slen = sf_read_raw(player->sndfile, player->membuf, - player->block_count * player->byteblockalign); + (sf_count_t)player->block_count * player->byteblockalign); if(slen > 0) slen -= slen%player->byteblockalign; if(slen < 1) break; } @@ -409,19 +409,19 @@ static int UpdatePlayer(StreamPlayer *player) if(player->sample_type == Int16) { slen = sf_readf_short(player->sndfile, player->membuf, - player->block_count * player->sampleblockalign); + (sf_count_t)player->block_count * player->sampleblockalign); if(slen > 0) slen *= player->byteblockalign; } else if(player->sample_type == Float) { slen = sf_readf_float(player->sndfile, player->membuf, - player->block_count * player->sampleblockalign); + (sf_count_t)player->block_count * player->sampleblockalign); if(slen > 0) slen *= player->byteblockalign; } else { slen = sf_read_raw(player->sndfile, player->membuf, - player->block_count * player->byteblockalign); + (sf_count_t)player->block_count * player->byteblockalign); if(slen > 0) slen -= slen%player->byteblockalign; } diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index 04489173..b33dbc75 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -38,6 +38,7 @@ #include "albit.h" #include "alfstream.h" +#include "alnumeric.h" #include "alspan.h" #include "alstring.h" #include "makemhr.h" @@ -1153,7 +1154,7 @@ static int LoadSofaSource(SourceRefT *src, const uint hrirRate, const uint n, do return 0; } - al::span coords{&sofa->hrtf->SourcePosition.values[3 * nearest], 3}; + al::span coords{&sofa->hrtf->SourcePosition.values[3_z * nearest], 3}; if(std::abs(coords[0] - target[0]) > 0.001 || std::abs(coords[1] - target[1]) > 0.001 || std::abs(coords[2] - target[2]) > 0.001) { @@ -1745,12 +1746,12 @@ static void AverageHrirMagnitude(const uint points, const uint n, const double * static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate) { const uint channels{(hData->mChannelType == CT_STEREO) ? 2u : 1u}; - hData->mHrirsBase.resize(channels * hData->mIrCount * hData->mIrSize); + hData->mHrirsBase.resize(size_t{channels} * hData->mIrCount * hData->mIrSize); double *hrirs = hData->mHrirsBase.data(); auto hrir = std::vector(hData->mIrSize); uint line, col, fi, ei, ai; - std::vector onsetSamples(OnsetRateMultiple * hData->mIrPoints); + std::vector onsetSamples(size_t{OnsetRateMultiple} * hData->mIrPoints); PPhaseResampler onsetResampler; onsetResampler.init(hData->mIrRate, OnsetRateMultiple*hData->mIrRate); @@ -1828,9 +1829,9 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate fflush(stdout); std::array aer{ - sofa->hrtf->SourcePosition.values[3*si], - sofa->hrtf->SourcePosition.values[3*si + 1], - sofa->hrtf->SourcePosition.values[3*si + 2] + sofa->hrtf->SourcePosition.values[3_uz*si], + sofa->hrtf->SourcePosition.values[3_uz*si + 1], + sofa->hrtf->SourcePosition.values[3_uz*si + 2] }; mysofa_c2s(aer.data()); @@ -1869,7 +1870,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate } ExtractSofaHrir(sofa, si, 0, src.mOffset, hData->mIrPoints, hrir.data()); - azd->mIrs[0] = &hrirs[hData->mIrSize * azd->mIndex]; + azd->mIrs[0] = &hrirs[size_t{hData->mIrSize} * azd->mIndex]; azd->mDelays[0] = AverageHrirOnset(onsetResampler, onsetSamples, hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0, azd->mDelays[0]); if(resampler) @@ -1879,7 +1880,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate if(src.mChannel == 1) { ExtractSofaHrir(sofa, si, 1, src.mOffset, hData->mIrPoints, hrir.data()); - azd->mIrs[1] = &hrirs[hData->mIrSize * (hData->mIrCount + azd->mIndex)]; + azd->mIrs[1] = &hrirs[hData->mIrSize * (size_t{hData->mIrCount}+azd->mIndex)]; azd->mDelays[1] = AverageHrirOnset(onsetResampler, onsetSamples, hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0, azd->mDelays[1]); if(resampler) @@ -1940,7 +1941,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate return 0; } } - azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti * hData->mIrCount + azd->mIndex)]; + azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti*size_t{hData->mIrCount} + azd->mIndex)]; azd->mDelays[ti] = AverageHrirOnset(onsetResampler, onsetSamples, hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0 / factor[ti], azd->mDelays[ti]); if(resampler) @@ -2017,7 +2018,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate { HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti * hData->mIrCount + azd->mIndex)]; + azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti*size_t{hData->mIrCount} + azd->mIndex)]; } } } diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index eaddd31b..c29cb45c 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -39,6 +39,7 @@ #include #include "alspan.h" +#include "alnumeric.h" #include "makemhr.h" #include "polyphase_resampler.h" #include "sofa-support.h" @@ -261,7 +262,7 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData, const DelayTy auto load_proc = [sofaHrtf,hData,delayType,outRate,&loaded_count]() -> bool { const uint channels{(hData->mChannelType == CT_STEREO) ? 2u : 1u}; - hData->mHrirsBase.resize(channels * hData->mIrCount * hData->mIrSize, 0.0); + hData->mHrirsBase.resize(channels * size_t{hData->mIrCount} * hData->mIrSize, 0.0); double *hrirs = hData->mHrirsBase.data(); std::vector restmp; @@ -277,9 +278,9 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData, const DelayTy loaded_count.fetch_add(1u); std::array aer{ - sofaHrtf->SourcePosition.values[3*si], - sofaHrtf->SourcePosition.values[3*si + 1], - sofaHrtf->SourcePosition.values[3*si + 2] + sofaHrtf->SourcePosition.values[3_uz*si], + sofaHrtf->SourcePosition.values[3_uz*si + 1], + sofaHrtf->SourcePosition.values[3_uz*si + 2] }; mysofa_c2s(aer.data()); @@ -317,13 +318,13 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData, const DelayTy for(uint ti{0u};ti < channels;++ti) { - azd->mIrs[ti] = &hrirs[hData->mIrSize * (hData->mIrCount*ti + azd->mIndex)]; + azd->mIrs[ti] = &hrirs[(size_t{hData->mIrCount}*ti + azd->mIndex)*hData->mIrSize]; if(!resampler) - std::copy_n(&sofaHrtf->DataIR.values[(si*sofaHrtf->R + ti)*sofaHrtf->N], + std::copy_n(&sofaHrtf->DataIR.values[(size_t{si}*sofaHrtf->R + ti)*sofaHrtf->N], sofaHrtf->N, azd->mIrs[ti]); else { - std::copy_n(&sofaHrtf->DataIR.values[(si*sofaHrtf->R + ti)*sofaHrtf->N], + std::copy_n(&sofaHrtf->DataIR.values[(size_t{si}*sofaHrtf->R + ti)*sofaHrtf->N], sofaHrtf->N, restmp.data()); resampler->process(sofaHrtf->N, restmp.data(), hData->mIrSize, azd->mIrs[ti]); } @@ -520,7 +521,7 @@ bool LoadSofaFile(const char *filename, const uint numThreads, const uint fftSiz for(uint ai{0u};ai < hData->mFds[fi].mEvs[ei].mAzs.size();ai++) { HrirAzT &azd = hData->mFds[fi].mEvs[ei].mAzs[ai]; - for(uint ti{0u};ti < channels;ti++) + for(size_t ti{0u};ti < channels;ti++) azd.mIrs[ti] = &hrirs[hData->mIrSize * (hData->mIrCount*ti + azd.mIndex)]; } } @@ -533,7 +534,7 @@ bool LoadSofaFile(const char *filename, const uint numThreads, const uint fftSiz auto onset_proc = [hData,channels,&hrir_done]() -> bool { /* Temporary buffer used to calculate the IR's onset. */ - auto upsampled = std::vector(OnsetRateMultiple * hData->mIrPoints); + auto upsampled = std::vector(size_t{OnsetRateMultiple} * hData->mIrPoints); /* This resampler is used to help detect the response onset. */ PPhaseResampler rs; rs.init(hData->mIrRate, OnsetRateMultiple*hData->mIrRate); diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index 014b2967..2b6d04ce 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -91,6 +91,7 @@ #include "alcomplex.h" #include "alfstream.h" #include "alnumbers.h" +#include "alnumeric.h" #include "alspan.h" #include "alstring.h" #include "loaddef.h" @@ -383,7 +384,7 @@ static int StoreMhr(const HrirDataT *hData, const char *filename) for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzs.size();ai++) { HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - std::array out{}; + std::array out{}; TpdfDither(out.data(), azd->mIrs[0], scale, n, channels, &dither_seed); if(hData->mChannelType == CT_STEREO) @@ -532,7 +533,7 @@ static void CalculateDiffuseFieldAverage(const HrirDataT *hData, const uint chan const int weighted, const double limit, double *dfa) { std::vector weights(hData->mFds.size() * MAX_EV_COUNT); - uint count, ti, fi, ei, i, ai; + uint count; if(weighted) { @@ -546,41 +547,41 @@ static void CalculateDiffuseFieldAverage(const HrirDataT *hData, const uint chan // If coverage weighting is not used, the weights still need to be // averaged by the number of existing HRIRs. count = hData->mIrCount; - for(fi = 0;fi < hData->mFds.size();fi++) + for(size_t fi{0};fi < hData->mFds.size();++fi) { - for(ei = 0;ei < hData->mFds[fi].mEvStart;ei++) + for(size_t ei{0};ei < hData->mFds[fi].mEvStart;++ei) count -= static_cast(hData->mFds[fi].mEvs[ei].mAzs.size()); } weight = 1.0 / count; - for(fi = 0;fi < hData->mFds.size();fi++) + for(size_t fi{0};fi < hData->mFds.size();++fi) { - for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvs.size();ei++) + for(size_t ei{hData->mFds[fi].mEvStart};ei < hData->mFds[fi].mEvs.size();++ei) weights[(fi * MAX_EV_COUNT) + ei] = weight; } } - for(ti = 0;ti < channels;ti++) + for(size_t ti{0};ti < channels;++ti) { - for(i = 0;i < m;i++) + for(size_t i{0};i < m;++i) dfa[(ti * m) + i] = 0.0; - for(fi = 0;fi < hData->mFds.size();fi++) + for(size_t fi{0};fi < hData->mFds.size();++fi) { - for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvs.size();ei++) + for(size_t ei{hData->mFds[fi].mEvStart};ei < hData->mFds[fi].mEvs.size();++ei) { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzs.size();ai++) + for(size_t ai{0};ai < hData->mFds[fi].mEvs[ei].mAzs.size();++ai) { HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; // Get the weight for this HRIR's contribution. double weight = weights[(fi * MAX_EV_COUNT) + ei]; // Add this HRIR's weighted power average to the total. - for(i = 0;i < m;i++) + for(size_t i{0};i < m;++i) dfa[(ti * m) + i] += weight * azd->mIrs[ti][i] * azd->mIrs[ti][i]; } } } // Finish the average calculation and keep it from being too small. - for(i = 0;i < m;i++) + for(size_t i{0};i < m;++i) dfa[(ti * m) + i] = std::max(sqrt(dfa[(ti * m) + i]), Epsilon); // Apply a limit to the magnitude range of the diffuse-field average // if desired. @@ -593,17 +594,15 @@ static void CalculateDiffuseFieldAverage(const HrirDataT *hData, const uint chan // set using the given average response. static void DiffuseFieldEqualize(const uint channels, const uint m, const double *dfa, const HrirDataT *hData) { - uint ti, fi, ei, i; - - for(fi = 0;fi < hData->mFds.size();fi++) + for(size_t fi{0};fi < hData->mFds.size();++fi) { - for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvs.size();ei++) + for(size_t ei{hData->mFds[fi].mEvStart};ei < hData->mFds[fi].mEvs.size();++ei) { for(auto &azd : hData->mFds[fi].mEvs[ei].mAzs) { - for(ti = 0;ti < channels;ti++) + for(size_t ti{0};ti < channels;++ti) { - for(i = 0;i < m;i++) + for(size_t i{0};i < m;++i) azd.mIrs[ti][i] /= dfa[(ti * m) + i]; } } @@ -1224,7 +1223,7 @@ static int ProcessDefinition(const char *inName, const uint outRate, const Chann { uint c{(hData.mChannelType == CT_STEREO) ? 2u : 1u}; uint m{hData.mFftSize/2u + 1u}; - auto dfa = std::vector(c * m); + auto dfa = std::vector(size_t{c} * m); if(hData.mFds.size() > 1) { diff --git a/utils/uhjdecoder.cpp b/utils/uhjdecoder.cpp index 801425e0..8f0d2006 100644 --- a/utils/uhjdecoder.cpp +++ b/utils/uhjdecoder.cpp @@ -435,7 +435,7 @@ int main(int argc, char **argv) // 32-bit val, frequency fwrite32le(static_cast(ininfo.samplerate), outfile.get()); // 32-bit val, bytes per second - fwrite32le(static_cast(ininfo.samplerate)*outchans*sizeof(float), outfile.get()); + fwrite32le(static_cast(ininfo.samplerate)*outchans*uint{sizeof(float)}, outfile.get()); // 16-bit val, frame size fwrite16le(static_cast(sizeof(float)*outchans), outfile.get()); // 16-bit val, bits per sample @@ -460,9 +460,9 @@ int main(int argc, char **argv) auto DataStart = ftell(outfile.get()); auto decoder = std::make_unique(); - auto inmem = std::vector(BufferLineSize*static_cast(ininfo.channels)); + auto inmem = std::vector(size_t{BufferLineSize}*static_cast(ininfo.channels)); auto decmem = al::vector, 16>(outchans); - auto outmem = std::vector(BufferLineSize*outchans); + auto outmem = std::vector(size_t{BufferLineSize}*outchans); /* A number of initial samples need to be skipped to cut the lead-in * from the all-pass filter delay. The same number of samples need to diff --git a/utils/uhjencoder.cpp b/utils/uhjencoder.cpp index 6a7b1fa9..02836181 100644 --- a/utils/uhjencoder.cpp +++ b/utils/uhjencoder.cpp @@ -415,11 +415,11 @@ int main(int argc, char **argv) } auto encoder = std::make_unique(); - auto splbuf = al::vector(static_cast(9+ininfo.channels)+uhjchans); - auto ambmem = al::span{splbuf.data(), 4}; - auto encmem = al::span{&splbuf[4], 4}; - auto srcmem = al::span{splbuf[8].data(), BufferLineSize}; - auto outmem = al::span{splbuf[9].data(), BufferLineSize*uhjchans}; + auto splbuf = al::vector(static_cast(ininfo.channels)+9+size_t{uhjchans}); + auto ambmem = al::span{splbuf}.subspan<0,4>(); + auto encmem = al::span{splbuf}.subspan<4,4>(); + auto srcmem = al::span{splbuf[8]}; + auto outmem = al::span{splbuf[9].data(), size_t{BufferLineSize}*uhjchans}; /* A number of initial samples need to be skipped to cut the lead-in * from the all-pass filter delay. The same number of samples need to -- cgit v1.2.3