Skip to content

Commit 1c0d796

Browse files
committed
Fillup the audio mixer in chunks
1 parent 35075bd commit 1c0d796

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/hardware/mixer.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,9 +1800,19 @@ void MixerChannel::FillUp()
18001800
if (!is_enabled || frames_done < mixer.frames_done)
18011801
return;
18021802
const auto index = PIC_TickIndex();
1803-
MIXER_LockAudioDevice();
1804-
Mix(check_cast<uint16_t>(static_cast<int64_t>(index * mixer.frames_needed)));
1805-
MIXER_UnlockAudioDevice();
1803+
1804+
auto frames_remaining = static_cast<int>(index * mixer.frames_needed);
1805+
while (frames_remaining > 0) {
1806+
const auto frames_to_mix = std::clamp(
1807+
frames_remaining, 0, static_cast<int>(MixerBufferLength));
1808+
1809+
MIXER_LockAudioDevice();
1810+
Mix(check_cast<work_index_t>(frames_to_mix));
1811+
MIXER_UnlockAudioDevice();
1812+
// Let SDL fetch frames after each chunk
1813+
1814+
frames_remaining = -frames_to_mix;
1815+
}
18061816
}
18071817

18081818
std::string MixerChannel::DescribeLineout() const

0 commit comments

Comments
 (0)