Remove an unnecessary struct member

This commit is contained in:
Chris Robinson 2019-05-24 06:25:18 -07:00
parent 9c63bbd6ce
commit e90a6beaa2
2 changed files with 9 additions and 12 deletions

View File

@ -95,7 +95,6 @@ struct ALbuffer {
FmtChannels mFmtChannels{}; FmtChannels mFmtChannels{};
FmtType mFmtType{}; FmtType mFmtType{};
ALsizei BytesAlloc{0};
UserFmtType OriginalType{}; UserFmtType OriginalType{};
ALsizei OriginalSize{0}; ALsizei OriginalSize{0};

View File

@ -235,8 +235,8 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U
NameFromUserFmtType(SrcType)); NameFromUserFmtType(SrcType));
} }
ALsizei unpackalign{ALBuf->UnpackAlign.load()}; const ALsizei unpackalign{ALBuf->UnpackAlign.load()};
ALsizei align{SanitizeAlignment(SrcType, unpackalign)}; const ALsizei align{SanitizeAlignment(SrcType, unpackalign)};
if(UNLIKELY(align < 1)) if(UNLIKELY(align < 1))
SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid unpack alignment %d for %s samples", SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid unpack alignment %d for %s samples",
unpackalign, NameFromUserFmtType(SrcType)); unpackalign, NameFromUserFmtType(SrcType));
@ -253,7 +253,7 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U
/* Convert the input/source size in bytes to sample frames using the unpack /* Convert the input/source size in bytes to sample frames using the unpack
* block alignment. * block alignment.
*/ */
ALsizei SrcByteAlign{ const ALsizei SrcByteAlign{
(SrcType == UserFmtIMA4) ? ((align-1)/2 + 4) * ChannelsFromUserFmt(SrcChannels) : (SrcType == UserFmtIMA4) ? ((align-1)/2 + 4) * ChannelsFromUserFmt(SrcChannels) :
(SrcType == UserFmtMSADPCM) ? ((align-2)/2 + 7) * ChannelsFromUserFmt(SrcChannels) : (SrcType == UserFmtMSADPCM) ? ((align-2)/2 + 7) * ChannelsFromUserFmt(SrcChannels) :
(align * FrameSizeFromUserFmt(SrcChannels, SrcType)) (align * FrameSizeFromUserFmt(SrcChannels, SrcType))
@ -266,7 +266,7 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U
if(UNLIKELY(size/SrcByteAlign > std::numeric_limits<ALsizei>::max()/align)) if(UNLIKELY(size/SrcByteAlign > std::numeric_limits<ALsizei>::max()/align))
SETERR_RETURN(context, AL_OUT_OF_MEMORY,, SETERR_RETURN(context, AL_OUT_OF_MEMORY,,
"Buffer size overflow, %d blocks x %d samples per block", size/SrcByteAlign, align); "Buffer size overflow, %d blocks x %d samples per block", size/SrcByteAlign, align);
ALsizei frames{size / SrcByteAlign * align}; const ALsizei frames{size / SrcByteAlign * align};
/* Convert the sample frames to the number of bytes needed for internal /* Convert the sample frames to the number of bytes needed for internal
* storage. * storage.
@ -276,7 +276,7 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U
if(UNLIKELY(frames > std::numeric_limits<ALsizei>::max()/FrameSize)) if(UNLIKELY(frames > std::numeric_limits<ALsizei>::max()/FrameSize))
SETERR_RETURN(context, AL_OUT_OF_MEMORY,, SETERR_RETURN(context, AL_OUT_OF_MEMORY,,
"Buffer size overflow, %d frames x %d bytes per frame", frames, FrameSize); "Buffer size overflow, %d frames x %d bytes per frame", frames, FrameSize);
ALsizei newsize{frames*FrameSize}; size_t newsize{static_cast<size_t>(frames) * FrameSize};
/* Round up to the next 16-byte multiple. This could reallocate only when /* Round up to the next 16-byte multiple. This could reallocate only when
* increasing or the new size is less than half the current, but then the * increasing or the new size is less than half the current, but then the
@ -284,18 +284,16 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U
* usage, and reporting the real size could cause problems for apps that * usage, and reporting the real size could cause problems for apps that
* use AL_SIZE to try to get the buffer's play length. * use AL_SIZE to try to get the buffer's play length.
*/ */
if(LIKELY(newsize <= std::numeric_limits<ALsizei>::max()-15)) newsize = RoundUp(newsize, 16);
newsize = (newsize+15) & ~0xf; if(newsize != ALBuf->mData.size())
if(newsize != ALBuf->BytesAlloc)
{ {
al::vector<al::byte,16> newdata(newsize); auto newdata = al::vector<al::byte,16>(newsize);
if((access&AL_PRESERVE_DATA_BIT_SOFT)) if((access&AL_PRESERVE_DATA_BIT_SOFT))
{ {
ALsizei tocopy{std::min(newsize, ALBuf->BytesAlloc)}; const size_t tocopy{minz(newdata.size(), ALBuf->mData.size())};
std::copy_n(ALBuf->mData.begin(), tocopy, newdata.begin()); std::copy_n(ALBuf->mData.begin(), tocopy, newdata.begin());
} }
ALBuf->mData = std::move(newdata); ALBuf->mData = std::move(newdata);
ALBuf->BytesAlloc = newsize;
} }
if(SrcType == UserFmtIMA4) if(SrcType == UserFmtIMA4)