#![no_std]
mod backends;
pub use backends::AymPrecise;
use core::fmt::Debug;
use num_traits::Num;
pub const AY_REGISTER_COUNT: usize = 14;
pub trait AySample: Num + Copy {
fn to_i8(self) -> i8;
fn to_i16(self) -> i16;
fn to_i32(self) -> i32;
fn to_f32(self) -> f32;
fn to_f64(self) -> f64;
}
impl AySample for f64 {
fn to_i8(self) -> i8 {
(i8::MAX as f64 * self).clamp(i8::MIN as f64, i8::MAX as f64) as i8
}
fn to_i16(self) -> i16 {
(i16::MAX as f64 * self).clamp(i16::MIN as f64, i16::MAX as f64) as i16
}
fn to_i32(self) -> i32 {
(i32::MAX as f64 * self).clamp(i32::MIN as f64, i32::MAX as f64) as i32
}
fn to_f32(self) -> f32 {
self as f32
}
fn to_f64(self) -> f64 {
self
}
}
#[derive(Debug)]
pub struct StereoSample<S>
where
S: AySample + Debug,
{
pub left: S,
pub right: S,
}
#[derive(Debug)]
pub enum SoundChip {
AY,
YM,
}
#[derive(Debug)]
#[allow(clippy::upper_case_acronyms)]
pub enum AyMode {
Mono,
ABC,
ACB,
BAC,
BCA,
CAB,
CBA,
}
pub trait AymBackend: Sized {
type SoundSample: AySample + Debug;
fn new(chip: SoundChip, mode: AyMode, frequency: usize, sample_rate: usize) -> Self;
fn write_register(&mut self, address: u8, value: u8);
fn next_sample(&mut self) -> StereoSample<Self::SoundSample>;
}