audio fix

This commit is contained in:
Theron 2020-01-14 00:12:24 -06:00
parent 67f4c3671e
commit 4703dabe41
2 changed files with 2 additions and 8 deletions

View File

@ -40,12 +40,6 @@ impl AudioCallback for ApuSampler {
// if we didn't have enough, decrease the ratio so we take more samples from the APU
if l > target {
*b = b.split_off(target);
self.sample_ratio += 0.005;
// println!("raised ratio to {}", self.sample_ratio);
} else {
b.clear();
self.sample_ratio -= 0.05;
// println!("lowered ratio to {}", self.sample_ratio);
}
} else {
println!("buffer empty!"); // happens when the callback fires twice between video frames

View File

@ -79,11 +79,11 @@ fn main() -> Result<(), String> {
if end_of_frame {
fps += 1; // keep track of how many frames we've rendered this second
draw_to_window(&mut texture, &mut canvas, &screen_buffer)?; // draw the buffer to the window with SDL
let mut b = apu_buffer.lock().unwrap(); // unlock mutex to the real buffer
b.append(&mut temp_buffer); // send this frame's audio data, emptying the temp buffer
let now = Instant::now();
// if we're running faster than 60Hz, kill time
if now < timer + Duration::from_millis(1000/60) {
let mut b = apu_buffer.lock().unwrap(); // unlock mutex to the real buffer
b.append(&mut temp_buffer); // send this frame's audio data, emptying the temp buffer
std::thread::sleep(timer + Duration::from_millis(1000/60) - now);
}
timer = Instant::now();