gb-emu/lib/src/connect/mod.rs
2023-03-09 14:12:28 +11:00

76 lines
1.8 KiB
Rust

use crate::processor::memory::mmio::gpu::Colour;
pub use crate::processor::memory::mmio::joypad::{JoypadButtons, JoypadState};
pub use crate::{HEIGHT, WIDTH};
use async_ringbuf::{AsyncHeapConsumer, AsyncHeapProducer, AsyncHeapRb};
pub enum EmulatorMessage {
Stop,
}
#[derive(Clone, Copy)]
pub enum DownsampleType {
Linear,
ZeroOrderHold,
}
pub enum RomFile {
Path(String),
Raw(Vec<u8>),
}
#[cfg(feature = "async")]
pub trait Renderer<Format: From<Colour>>: Send {
fn prepare(&mut self, width: usize, height: usize);
fn display(&mut self, buffer: &[Format]);
fn set_title(&mut self, _title: String) {}
fn latest_joypad_state(&mut self) -> JoypadState;
fn set_rumble(&mut self, _rumbling: bool) {}
}
#[cfg(not(feature = "async"))]
pub trait Renderer<Format: From<Colour>> {
fn prepare(&mut self, width: usize, height: usize);
fn display(&mut self, buffer: &[Format]);
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]>,
pub wait_for_output: bool,
pub downsample_type: DownsampleType,
}
impl AudioOutput {
pub fn new(
sample_rate: f32,
wait_for_output: bool,
frames_to_buffer: usize,
downsample_type: DownsampleType,
) -> (Self, AsyncHeapConsumer<[f32; 2]>) {
let rb_len = (sample_rate as usize / 60) * frames_to_buffer;
let rb = AsyncHeapRb::<[f32; 2]>::new(rb_len);
let (send_rb, rx) = rb.split();
(
Self {
sample_rate,
send_rb,
wait_for_output,
downsample_type,
},
rx,
)
}
}