fbd_sequencer_cli 0.1.0

A command-line tool for playing music using PSG or AY-3-8910 sound sources. It supports playing .fbd sequence files and can output directly to audio devices or generate .wav files.
use crate::{OutputMode, PsgTrait};
use psg_lite::{Output, SoundGenerator};

pub struct PsgWrapper {
    sg: SoundGenerator,
}

impl PsgWrapper {
    pub fn new(clock_rate: u32, sample_rate: u32) -> Self {
        Self {
            sg: SoundGenerator::new(clock_rate, sample_rate),
        }
    }
}

impl PsgTrait for PsgWrapper {
    fn sample_rate(&self) -> u32 {
        self.sg.sample_rate()
    }

    fn clock_rate(&self) -> u32 {
        self.sg.sample_rate()
    }

    fn set_tone_period(&mut self, channel: usize, period: u16) {
        self.sg.set_period(channel, period)
    }

    fn set_volume(&mut self, channel: usize, volume: u8) {
        self.sg.set_volume(channel, volume)
    }

    fn set_output_mode(&mut self, channel: usize, mode: OutputMode) {
        self.sg.set_mode(
            channel,
            match mode {
                OutputMode::Tone => Output::TONE,
                OutputMode::Noise => Output::NOISE,
                OutputMode::ToneNoise => Output::TONE | Output::NOISE,
                _ => todo!(),
            },
        )
    }

    fn set_noise_period(&mut self, period: u8) {
        self.sg.set_noise_period(period)
    }

    fn next_sample_i16(&mut self) -> i16 {
        self.sg.next_sample()
    }

    #[cfg(feature = "float")]
    fn next_sample_f32(&mut self) -> f32 {
        self.sg.next_sample()
    }
}