moa/emulator/core/src/host/input.rs
transistor 527f65c69b Refactored audio to use ClockedQueue
It now actually checks the clock and tries to mix the audio in sync
relative to the clock, but the cpal output doesn't yet try to sync
to the StreamInstant time.  Sound seems a lot better on chrome in
wasm, but and kind of better on firefox despite frame skipping not
being supported yet, but it's way slower for some reason (12fps)
2023-05-07 10:03:25 -07:00

42 lines
850 B
Rust

use std::sync::{Arc, Mutex};
use std::collections::VecDeque;
pub fn event_queue<T>() -> (EventSender<T>, EventReceiver<T>) {
let sender = EventSender {
queue: Arc::new(Mutex::new(VecDeque::new())),
};
let receiver = EventReceiver {
queue: sender.queue.clone(),
};
(sender, receiver)
}
pub struct EventSender<T> {
queue: Arc<Mutex<VecDeque<T>>>,
}
impl<T> EventSender<T> {
pub fn send(&self, event: T) {
self.queue.lock().unwrap().push_back(event);
}
//pub fn send_at_instant(&self, instant: Instant, event: T) {
// self.queue.lock().unwrap().push_back((instant, event));
//}
}
pub struct EventReceiver<T> {
queue: Arc<Mutex<VecDeque<T>>>,
}
impl<T> EventReceiver<T> {
pub fn receive(&self) -> Option<T> {
self.queue.lock().unwrap().pop_front()
}
}