examples: improve wav_player.v by ensuring the sound buffer is always zeroed (silence) first, before writing potentially incomplete frames

This commit is contained in:
Delyan Angelov 2025-09-22 00:26:49 +03:00
parent fe8e5495ab
commit a5d7f36691
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -39,10 +39,11 @@ fn play_sounds(files []string) ! {
//
fn audio_player_callback(mut buffer &f32, num_frames int, num_channels int, mut p Player) {
ntotal := num_channels * num_frames
unsafe { vmemset(buffer, 0, ntotal * 4) }
if p.finished {
return
}
ntotal := num_channels * num_frames
nremaining := p.samples.len - p.pos
nsamples := if nremaining < ntotal { nremaining } else { ntotal }
if nsamples <= 0 {