Skip to content
Permalink
Browse files

Eliminate startup/teardown audio clicks

Those were related to the fact that I was filling the buffer 0s when
I wanted silence, while it's supposed to be 128s (with the channel type
u8 that is). Since SDL provides us with the actual value that represents
silence in the given format let's just use it.

There are some clicks remaining when intro audio starts playing or
switches to the next one, but this may be data issue, I'll investigate.
  • Loading branch information
jstasiak committed Oct 23, 2019
1 parent 1e9c281 commit 840ed13c0376d745acf05f3003bfd181a0617d84
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/bin/openpol.rs
@@ -22,6 +22,7 @@ fn main() -> Result<(), String> {
struct Audio {
data: Vec<u8>,
position: usize,
silence: u8,
}

impl AudioCallback for Audio {
@@ -35,7 +36,7 @@ impl AudioCallback for Audio {
// for now.
if self.position == self.data.len() {
for x in out[to_buffer..].iter_mut() {
*x = 0;
*x = self.silence;
}
}
}
@@ -93,9 +94,10 @@ impl Game {
samples: None,
};

let mut audio_device = audio.open_playback(None, &desired_spec, |_spec| Audio {
let mut audio_device = audio.open_playback(None, &desired_spec, |spec| Audio {
data: Vec::new(),
position: 0,
silence: spec.silence,
})?;
audio_device.resume();

0 comments on commit 840ed13

Please sign in to comment.
You can’t perform that action at this time.