Skip to content

Commit

Permalink
Fix implicit widening after multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Dec 23, 2023
1 parent d7304c4 commit 4720b2c
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 88 deletions.
2 changes: 1 addition & 1 deletion alc/backends/oss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ bool OSSPlayback::reset()

setDefaultChannelOrder();

mMixData.resize(mDevice->UpdateSize * mDevice->frameSizeFromFmt());
mMixData.resize(size_t{mDevice->UpdateSize} * mDevice->frameSizeFromFmt());

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion alc/backends/pipewire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ void PipeWirePlayback::start()

mDevice->UpdateSize = updatesize;
mDevice->BufferSize = static_cast<uint>(ptime.buffered + delay +
totalbuffers*updatesize);
uint64_t{totalbuffers}*updatesize);
break;
}
#else
Expand Down
4 changes: 2 additions & 2 deletions alc/backends/sndio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ bool SndioPlayback::reset()
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)
Expand Down Expand Up @@ -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<uint>(mRing->writeSpace());
mDevice->UpdateSize = par.round;

Expand Down
14 changes: 7 additions & 7 deletions core/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint>(mChan.size()) * mSrcTypeSize};
const uint DstFrameSize{static_cast<uint>(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<const std::byte*>(*src);
uint NumSrcSamples{*srcframes};
Expand Down Expand Up @@ -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<const std::byte*>(src[chan]), 1, mSrcType, readable);
src[chan] = static_cast<const std::byte*>(src[chan]) + mSrcTypeSize*readable;
auto *samples = static_cast<const std::byte*>(src[chan]);
LoadSamples(&mChan[chan].PrevSamples[prepcount], samples, 1, mSrcType, readable);
src[chan] = samples + size_t{mSrcTypeSize}*readable;
}

mSrcPrepCount = prepcount + readable;
Expand Down Expand Up @@ -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<std::byte*>(dst[chan]) + pos*mDstTypeSize;
auto *DstSamples = static_cast<std::byte*>(dst[chan]) + pos*size_t{mDstTypeSize};
StoreSamples(DstSamples, DstData, 1, mDstType, DstSize);
}

Expand All @@ -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<const std::byte*>(src[chan]) + mSrcTypeSize*srcread;
src[chan] = static_cast<const std::byte*>(src[chan]) + size_t{mSrcTypeSize}*srcread;
NumSrcSamples -= srcread;

pos += DstSize;
Expand Down
2 changes: 1 addition & 1 deletion core/hrtf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/mastering.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <memory>

#include "almalloc.h"
#include "alnumeric.h"
#include "bufferline.h"

struct SlidingHold;
Expand Down Expand Up @@ -45,7 +46,7 @@ struct Compressor {
float mAttack{0.0f};
float mRelease{0.0f};

alignas(16) std::array<float,2*BufferLineSize> mSideChain{};
alignas(16) std::array<float,BufferLineSize*2_uz> mSideChain{};
alignas(16) std::array<float,BufferLineSize> mCrestFactor{};

SlidingHold *mHold{nullptr};
Expand Down
6 changes: 3 additions & 3 deletions core/mixer/mixer_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(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. */
Expand All @@ -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<float>(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. */
Expand Down
6 changes: 3 additions & 3 deletions core/mixer/mixer_neon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ void Resample_<BSincTag,NEONTag>(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};
Expand Down Expand Up @@ -291,7 +291,7 @@ void Resample_<FastBSincTag,NEONTag>(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};
Expand Down
6 changes: 3 additions & 3 deletions core/mixer/mixer_sse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ void Resample_<BSincTag,SSETag>(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};
Expand Down Expand Up @@ -256,7 +256,7 @@ void Resample_<FastBSincTag,SSETag>(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};
Expand Down
10 changes: 5 additions & 5 deletions core/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(needBytes))};
Expand All @@ -919,7 +919,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi
else
mNumCallbackBlocks = static_cast<uint>(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));
}
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions examples/alffplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ struct AudioState {
AVStream *mStream{nullptr};
AVCodecCtxPtr mCodecCtx;

DataQueue<2*1024*1024> mQueue;
DataQueue<size_t{2}*1024*1024> mQueue;

/* Used for clock difference average computation */
seconds_d64 mClockDiffAvg{0};
Expand Down Expand Up @@ -372,7 +372,7 @@ struct VideoState {
AVStream *mStream{nullptr};
AVCodecCtxPtr mCodecCtx;

DataQueue<14*1024*1024> mQueue;
DataQueue<size_t{14}*1024*1024> mQueue;

/* The pts of the currently displayed frame, and the time (av_gettime) it
* was last updated - used to have running video pts
Expand Down Expand Up @@ -738,8 +738,8 @@ bool AudioState::readAudio(uint8_t *samples, unsigned int length, int &sample_sk
{
const auto len = static_cast<unsigned int>(mSamplesLen - mSamplesPos);
if(rem > len) rem = len;
std::copy_n(mSamples + static_cast<unsigned int>(mSamplesPos)*mFrameSize,
rem*mFrameSize, samples);
std::copy_n(mSamples + static_cast<unsigned int>(mSamplesPos)*size_t{mFrameSize},
rem*size_t{mFrameSize}, samples);
}
else
{
Expand All @@ -751,7 +751,7 @@ bool AudioState::readAudio(uint8_t *samples, unsigned int length, int &sample_sk

mSamplesPos += static_cast<int>(rem);
mCurrentPts += nanoseconds{seconds{rem}} / mCodecCtx->sample_rate;
samples += rem*mFrameSize;
samples += rem*size_t{mFrameSize};
audio_size += rem;

while(mSamplesPos >= mSamplesLen)
Expand Down Expand Up @@ -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<double> mtx(64*64, 0.0);
std::vector<double> 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;
Expand Down Expand Up @@ -1546,8 +1546,8 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer, bool re
/* point pict at the queue */
std::array<uint8_t*,3> pict_data;
pict_data[0] = static_cast<uint8_t*>(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};

Expand Down
12 changes: 6 additions & 6 deletions examples/alstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
21 changes: 11 additions & 10 deletions utils/makemhr/loaddef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include "albit.h"
#include "alfstream.h"
#include "alnumeric.h"
#include "alspan.h"
#include "alstring.h"
#include "makemhr.h"
Expand Down Expand Up @@ -1153,7 +1154,7 @@ static int LoadSofaSource(SourceRefT *src, const uint hrirRate, const uint n, do
return 0;
}

al::span<float,3> coords{&sofa->hrtf->SourcePosition.values[3 * nearest], 3};
al::span<float,3> 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)
{
Expand Down Expand Up @@ -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<double>(hData->mIrSize);
uint line, col, fi, ei, ai;

std::vector<double> onsetSamples(OnsetRateMultiple * hData->mIrPoints);
std::vector<double> onsetSamples(size_t{OnsetRateMultiple} * hData->mIrPoints);
PPhaseResampler onsetResampler;
onsetResampler.init(hData->mIrRate, OnsetRateMultiple*hData->mIrRate);

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)];
}
}
}
Expand Down
Loading

0 comments on commit 4720b2c

Please sign in to comment.