audio fix
This commit is contained in:
parent
67f4c3671e
commit
4703dabe41
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue