sound: make sure m_samples_to_update is 0 when returning from update()

This commit is contained in:
hap 2025-04-29 17:49:22 +02:00
parent b5d39d98bd
commit e0268b35b2

View File

@ -190,7 +190,7 @@ template<typename S> void emu::detail::output_buffer_flat<S>::resample(u32 previ
return; return;
auto si = [](attotime time, u32 rate) -> s64 { auto si = [](attotime time, u32 rate) -> s64 {
return time.m_seconds * rate + ((time.m_attoseconds / 100000000) * rate) / 10000000000; return time.m_seconds * rate + ((time.m_attoseconds / 100'000'000) * rate) / 10'000'000'000LL;
}; };
auto cv = [](u32 source_rate, u32 dest_rate, s64 time) -> std::pair<s64, double> { auto cv = [](u32 source_rate, u32 dest_rate, s64 time) -> std::pair<s64, double> {
@ -492,7 +492,7 @@ void sound_stream::init()
u64 sound_stream::get_current_sample_index() const u64 sound_stream::get_current_sample_index() const
{ {
attotime now = m_device.machine().time(); attotime now = m_device.machine().time();
return now.m_seconds * m_sample_rate + ((now.m_attoseconds / 1000000000) * m_sample_rate) / 1000000000; return now.m_seconds * m_sample_rate + ((now.m_attoseconds / 1'000'000'000) * m_sample_rate) / 1'000'000'000;
} }
void sound_stream::update() void sound_stream::update()
@ -503,9 +503,8 @@ void sound_stream::update()
// Find out where we are and how much we have to do // Find out where we are and how much we have to do
u64 idx = get_current_sample_index(); u64 idx = get_current_sample_index();
m_samples_to_update = idx - m_output_buffer.write_sample(); m_samples_to_update = idx - m_output_buffer.write_sample();
if(m_samples_to_update <= 0)
return;
if(m_samples_to_update > 0) {
m_in_update = true; m_in_update = true;
// If there's anything to do, well, do it, starting with the dependencies // If there's anything to do, well, do it, starting with the dependencies
@ -513,9 +512,10 @@ void sound_stream::update()
stream->update_nodeps(); stream->update_nodeps();
do_update(); do_update();
m_samples_to_update = 0;
m_in_update = false; m_in_update = false;
} }
m_samples_to_update = 0;
}
void sound_stream::update_nodeps() void sound_stream::update_nodeps()
{ {
@ -525,16 +525,16 @@ void sound_stream::update_nodeps()
// Find out where we are and how much we have to do // Find out where we are and how much we have to do
u64 idx = get_current_sample_index(); u64 idx = get_current_sample_index();
m_samples_to_update = idx - m_output_buffer.write_sample(); m_samples_to_update = idx - m_output_buffer.write_sample();
if(m_samples_to_update <= 0)
return;
if(m_samples_to_update > 0) {
m_in_update = true; m_in_update = true;
// If there's anything to do, well, do it // If there's anything to do, well, do it
do_update(); do_update();
m_samples_to_update = 0;
m_in_update = false; m_in_update = false;
} }
m_samples_to_update = 0;
}
void sound_stream::create_resamplers() void sound_stream::create_resamplers()
{ {