Fix SrcBufferSize calculation when downsampling
This commit is contained in:
parent
88ad84edf6
commit
775187788a
@ -631,7 +631,10 @@ void Voice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesToD
|
||||
do {
|
||||
/* Figure out how many buffer samples will be needed */
|
||||
ALuint DstBufferSize{SamplesToDo - OutPos};
|
||||
ALuint SrcBufferSize;
|
||||
|
||||
if(increment <= FRACTIONONE)
|
||||
{
|
||||
/* Calculate the last written dst sample pos. */
|
||||
uint64_t DataSize64{DstBufferSize - 1};
|
||||
/* Calculate the last read src sample pos. */
|
||||
@ -639,25 +642,38 @@ void Voice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesToD
|
||||
/* +1 to get the src sample count, include padding. */
|
||||
DataSize64 += 1 + MAX_RESAMPLER_PADDING;
|
||||
|
||||
auto SrcBufferSize = static_cast<ALuint>(
|
||||
minu64(DataSize64, BUFFERSIZE + MAX_RESAMPLER_PADDING + 1));
|
||||
/* Result is guaranteed to be <= BUFFERSIZE+MAX_RESAMPLER_PADDING
|
||||
* since we won't use more src samples than dst samples+padding.
|
||||
*/
|
||||
SrcBufferSize = static_cast<ALuint>(DataSize64);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t DataSize64{DstBufferSize};
|
||||
/* Calculate the end src sample pos, include padding. */
|
||||
DataSize64 = (DataSize64*increment + DataPosFrac) >> FRACTIONBITS;
|
||||
DataSize64 += MAX_RESAMPLER_PADDING;
|
||||
|
||||
SrcBufferSize = static_cast<ALuint>(minu64(DataSize64,
|
||||
BUFFERSIZE + MAX_RESAMPLER_PADDING + 1));
|
||||
if(SrcBufferSize > BUFFERSIZE + MAX_RESAMPLER_PADDING)
|
||||
{
|
||||
SrcBufferSize = BUFFERSIZE + MAX_RESAMPLER_PADDING;
|
||||
/* If the source buffer got saturated, we can't fill the desired
|
||||
* dst size. Figure out how many samples we can actually mix from
|
||||
* this.
|
||||
/* If the source size got saturated, we can't fill the desired
|
||||
* dst size. Figure out how many samples we can actually mix
|
||||
* from this.
|
||||
*/
|
||||
DataSize64 = SrcBufferSize - MAX_RESAMPLER_PADDING;
|
||||
DataSize64 = ((DataSize64<<FRACTIONBITS) - DataPosFrac + increment-1) / increment;
|
||||
if(DataSize64 < DstBufferSize)
|
||||
{
|
||||
/* Some mixers require being 16-byte aligned, so also limit to
|
||||
* a multiple of 4 samples to maintain alignment.
|
||||
/* Some mixers require being 16-byte aligned, so also limit
|
||||
* to a multiple of 4 samples to maintain alignment.
|
||||
*/
|
||||
DstBufferSize = static_cast<ALuint>(DataSize64) & ~3u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((mFlags&(VOICE_IS_CALLBACK|VOICE_CALLBACK_STOPPED)) == VOICE_IS_CALLBACK
|
||||
&& BufferListItem)
|
||||
|
Loading…
x
Reference in New Issue
Block a user