Merge branch 'master' of ssh://ssh.paoda.moe:31059/paoda/chip8

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-01-27 22:33:21 -06:00
commit a4428c2fe5
1 changed files with 7 additions and 17 deletions

View File

@ -1,4 +1,4 @@
use rodio::{source::SineWave, Sink};
use rodio::{source::SineWave, Sink, Source};
use std::sync::atomic::{AtomicU8, Ordering};
use std::thread;
use std::time::{Duration, Instant};
@ -68,23 +68,13 @@ impl Timer {
}
fn beep() {
let maybe_device = rodio::default_output_device();
let beep = SineWave::new(440);
const BEEP_FREQ: u32 = 440; // Hz (Middle A)
const BEEP_LENGTH: u64 = 150; // ms
let beep = SineWave::new(BEEP_FREQ)
.take_duration(Duration::from_millis(BEEP_LENGTH));
// TODO: Fix Pop when sound ends?
if let Some(device) = maybe_device {
std::thread::spawn(move || {
let sink = Sink::new(&device);
let duration = Duration::from_millis(100);
let start = Instant::now();
sink.append(beep);
loop {
if Instant::now().duration_since(start) > duration {
break;
}
}
});
if let Some(device) = rodio::default_output_device() {
rodio::play_raw(&device, beep);
}
}
}