fix some weirdness in the Open Music code

This commit is contained in:
Stepland 2023-04-16 01:14:57 +02:00
parent 6242202519
commit 84c22a8795
2 changed files with 3 additions and 2 deletions

View File

@ -153,7 +153,7 @@ bool OpenMusic::onGetData(SoundStream::Chunk& data) {
data.samples = m_samples.data();
if (lead_in < 0) {
std::fill(m_samples.data(), m_samples.data() + to_fill, 0);
const auto to_read = std::max<std::int64_t>(to_fill - lead_in, 0);
const auto to_read = to_fill + lead_in;
if (to_read <= 0) {
data.sampleCount = to_fill;
} else {
@ -176,7 +176,7 @@ void OpenMusic::onSeek(sf::Time timeOffset) {
std::scoped_lock lock(m_mutex);
if (timeOffset < sf::Time::Zero) {
lead_in = timeToSamples(timeOffset);
m_file.seek(sf::Time::Zero);
m_file.seek(0);
} else {
m_file.seek(timeOffset);
}

View File

@ -34,6 +34,7 @@ struct Buffers {
// Format of the internal sound buffers
sf::Int32 m_format = 0;
// Number of samples processed since beginning of the stream
// May be negative to account for chart offsets
std::int64_t m_samplesProcessed = 0;
// If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation.
std::array<sf::Int64, BufferCount> m_bufferSeeks = {0, 0, 0};