Skip to main content

YM2149

Struct YM2149 

Source
pub struct YM2149<C>
where C: CommandOutput,
{ pub channel_data: [AudioChannelData; 3], pub last_used_channel: Option<usize>, /* private fields */ }
Expand description

A YM2149 chip struct.

The master_clock_frequency value is used to convert a frequency into a tone period by .tone_hz()

Example code:

use ym2149_core::{
    command::{Command, CommandOutput},
    io::IoPortMixerSettings,
    chip::YM2149
};

struct DebugWriter;

impl CommandOutput for DebugWriter {
    fn execute(&mut self, command: Command) {
        print!("Register 0b{:08b} ({:?}), ", command.register, command.register);
        println!("0b{:08b} ({:?})", command.value, command.value);
    }
}

let mut chip = YM2149::new(
    DebugWriter{},
    2_000_000,
).expect("Error building chip");

chip.setup_io_and_mixer(
    IoPortMixerSettings {
        tone_ch_a: true,
        ..Default::default()
    }
);

Fields§

§channel_data: [AudioChannelData; 3]§last_used_channel: Option<usize>

Implementations§

Source§

impl<C> YM2149<C>
where C: CommandOutput,

Source

pub fn new( command_output: C, master_clock_frequency: u32, ) -> Result<Self, Error>

Create a new struct for the YM2149.

Source

pub fn command<R: ValidRegister + Copy>(&mut self, register: R, value: u8)

Send a Command.

Source

pub fn setup_io_and_mixer(&mut self, settings: IoPortMixerSettings)

Setup the IO ports and the internal mixer according to the IoPortMixerSettings specified.

Source

pub fn write_io(&mut self, port: IoPort, value: u8)

Write a value to one of the chip’s GPIO ports. Note: This is a simple helper function, equivalent to self.command(port as u8, value);

Source

pub fn set_envelope_frequency( &mut self, frequency: EnvelopeFrequency, ) -> Result<u16, Error>

Set the envelope generator’s frequency.

Source

pub fn set_envelope_shape(&mut self, envelope: &Envelope)

Set the envelope generator’s shape.

Source

pub fn tone(&mut self, channel: AudioChannel, period: u16) -> Result<(), Error>

Play a tone with a TP of period on an AudioChannel.

The formula for the frequency is f = fMaster / (16 * TP), where: - f: target frequency - fMaster: master clock frequency - TP: tone period

Source

pub fn tone_hz( &mut self, channel: AudioChannel, frequency: u32, ) -> Result<(), Error>

Play a tone of a given frequency in Hz on an AudioChannel.

Source

pub fn play_note( &mut self, channel: AudioChannel, note: &Note, ) -> Result<(), Error>

Play a Note on an AudioChannel.

Source

pub fn pitch_bend( &mut self, channel: AudioChannel, byte1: u8, byte2: u8, replay_last: bool, ) -> Result<f32, Error>

Set an AudioChannel’s pitch bend (takes a MIDI command).

Source

pub fn replay_last_note(&mut self, channel: AudioChannel) -> Result<(), Error>

Replay the last played note on a given channel.

Source

pub fn play_note_with_envelope( &mut self, channel: AudioChannel, note: &Note, with_envelope: &Envelope, ) -> Result<(), Error>

Play a Note on an AudioChannel with a given Envelope.

Source

pub fn set_noise_freq(&mut self, frequency: u8) -> Result<(), Error>

Set the frequency of the noise generator.

Mask: 0x1F

Source

pub fn level(&mut self, channel: AudioChannel, level: u8)

Set the volume of an AudioChannel.

Note: The channel level registers store 5 bits of data per channel.


From the datasheet:

  • Mode M selects whether the level is fixed (when M = 0) or variable (M = 1).
  • When M = 0, the level is determined from one of 16 by level selection signals L3, L2, L1, and L0 which compromise the lower four bits.
  • When M = 1, the level is determined by the 5 bit output of E4, E3, E2, E1, and E0 of the envelope generator of the SSG.
B7 (MSB)B6B5B4B3B2B1B0
N/AN/AN/AML3L2L1L0

Trait Implementations§

Source§

impl<C> Debug for YM2149<C>
where C: CommandOutput + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> Freeze for YM2149<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for YM2149<C>
where C: RefUnwindSafe,

§

impl<C> Send for YM2149<C>
where C: Send,

§

impl<C> Sync for YM2149<C>
where C: Sync,

§

impl<C> Unpin for YM2149<C>
where C: Unpin,

§

impl<C> UnwindSafe for YM2149<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.