PCM reader: Avoid potential infinite loop if buffer already has more samples than what is needed
This commit is contained in:
parent
379e4069d1
commit
51818dc867
1 changed files with 5 additions and 1 deletions
|
@ -134,7 +134,11 @@ void PcmReader::ApplySamples(int16_t *buffer, size_t sampleCount, uint8_t volume
|
|||
return;
|
||||
}
|
||||
|
||||
LoadSamples((uint32_t)sampleCount * PcmReader::PcmSampleRate / _sampleRate + 1 - blip_samples_avail(_blipLeft));
|
||||
int32_t samplesNeeded = (int32_t)sampleCount - blip_samples_avail(_blipLeft);
|
||||
if(samplesNeeded > 0) {
|
||||
uint32_t samplesToLoad = samplesNeeded * PcmReader::PcmSampleRate / _sampleRate + 1;
|
||||
LoadSamples(samplesToLoad);
|
||||
}
|
||||
|
||||
int samplesRead = blip_read_samples(_blipLeft, _outputBuffer, (int)sampleCount, 1);
|
||||
blip_read_samples(_blipRight, _outputBuffer + 1, (int)sampleCount, 1);
|
||||
|
|
Loading…
Add table
Reference in a new issue