mirror of
https://github.com/transistorfet/moa.git
synced 2024-05-28 13:41:30 +00:00
527f65c69b
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)
42 lines
850 B
Rust
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()
|
|
}
|
|
}
|
|
|