AWavLoader: Fixed incorrect computation of m_loaded_samples

m_loaded_samples was incremented with the value of the processed
buffer. This causes m_loaded_samples to be bigger at some point
than m_total_samples when downsampling, as the buffer would contain
more samples than actually loaded.
This commit is contained in:
Till Mayer 2019-11-05 18:34:39 +01:00 committed by Andreas Kling
parent 173ae370db
commit 94a9649945
Notes: sideshowbarker 2024-07-19 11:22:00 +09:00

View file

@ -27,7 +27,9 @@ RefPtr<ABuffer> AWavLoader::get_more_samples(size_t max_bytes_to_read_from_input
return nullptr;
auto buffer = ABuffer::from_pcm_data(raw_samples, *m_resampler, m_num_channels, m_bits_per_sample);
m_loaded_samples += buffer->sample_count();
//Buffer contains normalized samples, but m_loaded_samples should containt the ammount of actually loaded samples
m_loaded_samples += static_cast<int>(max_bytes_to_read_from_input) / (m_num_channels * (m_bits_per_sample / 8));
m_loaded_samples = min(m_total_samples, m_loaded_samples);
return buffer;
}