gb-emu/lib/src/connect/mod.rs

59 lines
1.3 KiB
Rust

pub use crate::processor::memory::mmio::joypad::JoypadState;
use async_ringbuf::{AsyncHeapConsumer, AsyncHeapProducer, AsyncHeapRb};
use futures::executor;
pub enum EmulatorMessage {
Stop,
}
pub enum RomFile {
Path(String),
Raw(Vec<u8>),
}
pub trait Renderer: Send + Sync {
fn prepare(&mut self, width: usize, height: usize);
fn display(&mut self, buffer: &[u32]);
fn set_title(&mut self, _title: String) {}
fn latest_joypad_state(&mut self) -> JoypadState;
fn set_rumble(&mut self, _rumbling: bool) {}
}
pub struct AudioOutput {
pub sample_rate: f32,
pub send_rb: AsyncHeapProducer<[f32; 2]>,
}
impl AudioOutput {
pub fn new(sample_rate: f32) -> (Self, AsyncHeapConsumer<[f32; 2]>) {
let (mut output, rx) = Self::new_unfilled(sample_rate);
executor::block_on(
output
.send_rb
.push_iter(vec![[0.; 2]; output.send_rb.len() - 1].into_iter()),
)
.unwrap();
(output, rx)
}
pub fn new_unfilled(sample_rate: f32) -> (Self, AsyncHeapConsumer<[f32; 2]>) {
let rb_len = sample_rate as usize / (60 * 2);
let rb = AsyncHeapRb::<[f32; 2]>::new(rb_len);
let (send_rb, rx) = rb.split();
(
Self {
sample_rate,
send_rb,
},
rx,
)
}
}