### Quick Start: Initialize YM2149 and Generate a Sample Source: https://docs.rs/ym2149/latest/ym2149/ Shows how to create a Ym2149 instance, write tone and volume registers, clock the chip, and retrieve an audio sample. This is the minimal usage example from the Quick start section. ```rust use ym2149::{Ym2149, Ym2149Backend}; let mut chip = Ym2149::new(); chip.write_register(0, 0x1C); // Tone A Lo chip.write_register(1, 0x01); // Tone A Hi chip.write_register(8, 0x0F); // Volume A chip.clock(); let sample = chip.get_sample(); ``` -------------------------------- ### Example: Using Ym2149Backend to play a note Source: https://docs.rs/ym2149/latest/ym2149/trait.Ym2149Backend.html Shows how to implement a generic function that writes YM2149 registers to configure a tone and retrieve a sample. The example uses write_register to set period, volume, and mixer, then calls clock and get_sample. ```rust use ym2149_common::Ym2149Backend; fn play_note(chip: &mut B) { chip.write_register(0x00, 0xF0); // Channel A period low chip.write_register(0x01, 0x01); // Channel A period high chip.write_register(0x08, 0x0F); // Channel A volume chip.write_register(0x07, 0x3E); // Mixer: enable tone A chip.clock(); let sample = chip.get_sample(); } ``` -------------------------------- ### sync_sample_cycle Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Synchronizes the sample start cycle with the CPU cycle. Call this at the start of emulation or after a reset to align sample timing with the CPU. ```APIDOC ## sync_sample_cycle ### Description Synchronizes the sample start cycle with the CPU cycle. Call this at the start of emulation or after a reset to align sample timing with the CPU. ### Method pub fn sync_sample_cycle(&mut self, cpu_cycle: u64) ### Parameters - **cpu_cycle** (u64) - Required - The CPU cycle to synchronize with. ### Return No return value. ``` -------------------------------- ### Create a PSG bank with uniform frequency using PsgBank::new Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Creates a bank of PSG chips all running at the same clock frequency. The example shows a PlayCity setup with 2 PSGs at 2 MHz, and asserts the resulting chip and channel counts. Panics if count is 0. ```rust use ym2149::PsgBank; // PlayCity setup: 2 PSGs at 2MHz let bank = PsgBank::new(2, 2_000_000); assert_eq!(bank.psg_count(), 2); assert_eq!(bank.channel_count(), 6); ``` -------------------------------- ### Create a 2-PSG bank and generate interleaved samples Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/index.html Shows how to create a PsgBank with 2 PSG chips, write registers to each chip, and generate interleaved samples into a buffer. The example uses a 2 MHz clock and writes to PSG 0 and PSG 1 channel A. ```rust use ym2149::{PsgBank, Ym2149}; // Create a 2-PSG bank (6 channels total) let mut bank = PsgBank::new(2, 2_000_000); // Write to PSG 0, Channel A bank.write_register(0, 0x00, 0x1C); // Period low bank.write_register(0, 0x08, 0x0F); // Volume // Write to PSG 1, Channel A bank.write_register(1, 0x00, 0x2A); // Different period bank.write_register(1, 0x08, 0x0F); // Volume // Generate interleaved samples let mut buffer = vec![0.0f32; 882]; bank.generate_samples_interleaved(&mut buffer); ``` -------------------------------- ### Generate interleaved samples (generate_samples_interleaved example) Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Example usage of PsgBank::generate_samples_interleaved to fill a buffer with mixed audio samples from all PSGs. The buffer size is 882 samples for a 50Hz frame at 44.1kHz. ```rust use ym2149::PsgBank; let mut bank = PsgBank::new(2, 2_000_000); let mut buffer = vec![0.0f32; 882]; // 50Hz frame at 44.1kHz bank.generate_samples_interleaved(&mut buffer); ``` -------------------------------- ### Write register to specific PSG (write_register example) Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Example usage of PsgBank::write_register to set volume on Channel A for two PSGs. Requires a PsgBank instance created with PsgBank::new(2, 2_000_000). Panics if psg_index is out of bounds. ```rust use ym2149::PsgBank; let mut bank = PsgBank::new(2, 2_000_000); // Set volume on PSG 0, Channel A bank.write_register(0, 0x08, 0x0F); // Set volume on PSG 1, Channel A bank.write_register(1, 0x08, 0x0F); ``` -------------------------------- ### get_sample(&self) -> f32 Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Gets the last generated audio sample. ```APIDOC ## get_sample(&self) -> f32 ### Description Gets the last generated audio sample. ### Method get_sample ### Signature `fn get_sample(&self) -> f32` ### Parameters - **self** (&Self) - Required - The backend instance. ### Returns - **f32** - The last generated audio sample. ``` -------------------------------- ### Create a PSG bank with mixed frequencies using PsgBank::new_with_frequencies Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Creates a bank where each PSG can have a different clock frequency, useful for mixed configurations like CPC + PlayCity. The example shows three PSGs with 1 MHz and 2 MHz frequencies, and asserts the resulting counts. Panics if the frequencies vector is empty. ```rust use ym2149::PsgBank; // CPC with PlayCity: mixed frequencies let bank = PsgBank::new_with_frequencies(vec![ 1_000_000, // CPC internal PSG 2_000_000, // PlayCity PSG 1 2_000_000, // PlayCity PSG 2 ]); assert_eq!(bank.psg_count(), 3); assert_eq!(bank.channel_count(), 9); ``` -------------------------------- ### get_chip Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Gets a reference to a specific PSG chip by index. Panics if the index is out of bounds. ```APIDOC ## get_chip ### Description Gets a reference to a specific PSG chip. ### Method pub fn get_chip(&self, psg_index: usize) -> &Ym2149 ### Arguments - `psg_index` (usize) - Index of the PSG (0..psg_count) ### Panics Panics if `psg_index` is out of bounds. ### Returns - `&Ym2149` - Reference to the specified PSG chip. ``` -------------------------------- ### get_chip_mut Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Gets a mutable reference to a specific PSG chip by index. Panics if the index is out of bounds. ```APIDOC ## get_chip_mut ### Description Gets a mutable reference to a specific PSG chip. ### Method pub fn get_chip_mut(&mut self, psg_index: usize) -> &mut Ym2149 ### Arguments - `psg_index` (usize) - Index of the PSG (0..psg_count) ### Panics Panics if `psg_index` is out of bounds. ### Returns - `&mut Ym2149` - Mutable reference to the specified PSG chip. ``` -------------------------------- ### PsgBank::get_frequency Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Gets the clock frequency for a specific PSG. Panics if psg_index is out of bounds. ```APIDOC ## PsgBank::get_frequency ### Description Gets the clock frequency for a specific PSG. ### Method `pub fn get_frequency(&self, psg_index: usize) -> u32` ### Parameters - `psg_index` (usize) - Required - Index of the PSG (0..psg_count) ### Panics Panics if `psg_index` is out of bounds. ### Returns - `u32` - Clock frequency in Hz for the specified PSG. ``` -------------------------------- ### new() Source: https://docs.rs/ym2149/latest/ym2149/trait.Ym2149Backend.html Creates a new backend instance with default clocks: master clock 2,000,000 Hz and sample rate 44,100 Hz. ```APIDOC ## new() ### Description Creates a new backend instance with default clocks. ### Method new ### Signature fn new() -> Self where Self: Sized ### Default Clocks - Master clock: 2,000,000 Hz (Atari ST frequency) - Sample rate: 44,100 Hz ### Returns A new backend instance. ``` -------------------------------- ### new() -> Self Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Creates a new backend instance with default clocks. ```APIDOC ## new() -> Self ### Description Creates a new backend instance with default clocks. ### Method new ### Signature `fn new() -> Self` ### Parameters None ### Returns - **Self** - A new backend instance. ``` -------------------------------- ### PsgBank::new Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/index.html Creates a new PsgBank instance with the specified number of PSG chips and clock frequency. ```APIDOC ## PsgBank::new ### Description Creates a new PsgBank instance with the specified number of PSG chips and clock frequency. ### Method Constructor ### Signature `pub fn new(num_psgs: usize, clock_hz: u32) -> PsgBank` ### Parameters - **num_psgs** (usize) - Required - Number of PSG chips in the bank. - **clock_hz** (u32) - Required - Clock frequency in Hz for the PSG chips. ### Returns - **PsgBank** - A new PsgBank instance. ### Example ```rust let mut bank = PsgBank::new(2, 2_000_000); ``` ``` -------------------------------- ### Basic usage of Ym2149 Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Shows how to create a Ym2149 instance, set up channel A with a low period and max volume, and generate a sample. ```rust use ym2149::{Ym2149, Ym2149Backend}; let mut chip = Ym2149::new(); // Set up channel A: low period, max volume chip.write_register(0, 0x00); // Period low chip.write_register(1, 0x01); // Period high chip.write_register(8, 0x0F); // Volume chip.write_register(7, 0x3E); // Mixer: tone A on // Generate audio chip.clock(); let sample = chip.get_sample(); ``` -------------------------------- ### PsgBank::new Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Creates a new PSG bank with all chips at the same frequency. Panics if count is 0. ```APIDOC ## PsgBank::new ### Description Creates a new PSG bank with all chips at the same frequency. ### Method `pub fn new(count: usize, frequency: u32) -> Self` ### Parameters - `count` (usize) - Required - Number of PSG chips (must be > 0) - `frequency` (u32) - Required - Clock frequency in Hz (e.g., 2_000_000 for Atari ST) ### Panics Panics if `count` is 0. ### Examples ```rust use ym2149::PsgBank; // PlayCity setup: 2 PSGs at 2MHz let bank = PsgBank::new(2, 2_000_000); assert_eq!(bank.psg_count(), 2); assert_eq!(bank.channel_count(), 6); ``` ``` -------------------------------- ### Generate separate audio buffers per PSG with generate_samples_separate Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Creates a PsgBank with 2 PSGs and two output buffers, then calls generate_samples_separate to fill each buffer with the corresponding PSG's output. Panics if the number of buffers doesn't match the PSG count. ```rust use ym2149::PsgBank; let mut bank = PsgBank::new(2, 2_000_000); let mut buffer0 = vec![0.0f32; 882]; let mut buffer1 = vec![0.0f32; 882]; let mut buffers = vec![&mut buffer0[..], &mut buffer1[..]]; bank.generate_samples_separate(&mut buffers); // Now buffer0 contains PSG 0 output, buffer1 contains PSG 1 output ``` -------------------------------- ### Ym2149::new Source: https://docs.rs/ym2149/latest/ym2149/ Creates a new instance of the YM2149 emulator. ```APIDOC ## Ym2149::new ### Description Creates a new instance of the YM2149 emulator. ### Method `Ym2149::new()` ### Parameters None ### Returns A new `Ym2149` instance. ### Example ```rust let mut chip = Ym2149::new(); ``` ``` -------------------------------- ### with_clocks(master_clock: u32, sample_rate: u32) -> Self Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Creates a backend with custom master clock and sample rate. ```APIDOC ## with_clocks(master_clock: u32, sample_rate: u32) -> Self ### Description Creates a backend with custom master clock and sample rate. ### Method with_clocks ### Signature `fn with_clocks(master_clock: u32, sample_rate: u32) -> Self` ### Parameters - **master_clock** (u32) - Required - The master clock frequency. - **sample_rate** (u32) - Required - The sample rate. ### Returns - **Self** - A new backend instance with the specified clocks. ``` -------------------------------- ### new() Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Creates a new YM2149 emulator with default Atari ST clocks (2 MHz master clock, 44.1 kHz sample rate). ```APIDOC ## new() ### Description Creates a new YM2149 emulator with default Atari ST clocks. ### Method new ### Signature `pub fn new() -> Self` ### Parameters None ### Returns - **Self** - A new Ym2149 instance with default configuration. ### Default Configuration - Master clock: 2 MHz - Sample rate: 44.1 kHz ``` -------------------------------- ### reset() Source: https://docs.rs/ym2149/latest/ym2149/trait.Ym2149Backend.html Resets the backend to its initial state, clearing all registers, resetting generators, and stopping audio output. ```APIDOC ## reset() ### Description Resets the backend to initial state. Clears all registers, resets generators, and stops all audio output. ### Method reset ### Signature fn reset(&mut self) ### Parameters None ``` -------------------------------- ### generate_samples_into Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Generates multiple audio samples into a caller-provided buffer. ```APIDOC ## generate_samples_into ### Description Generates multiple audio samples into a caller-provided buffer. ### Method fn generate_samples_into(&mut self, buffer: &mut [f32]) ### Parameters - **buffer** (&mut [f32]) - Required - The buffer to write the generated samples into. ``` -------------------------------- ### reset() Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Resets the chip to its initial state. ```APIDOC ## reset() ### Description Resets the chip to its initial state. ### Method reset ### Signature `pub fn reset(&mut self)` ### Parameters None ### Returns None ``` -------------------------------- ### compute_next_sample Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Generates the next audio sample with cycle-accurate write processing. Processes pending writes, runs the internal state machine at 250kHz, and averages the output to produce a sample at the host sample rate. ```APIDOC ## compute_next_sample ### Description Generates the next audio sample with cycle-accurate write processing. This method processes any pending register writes that fall within this sample period, runs the internal state machine at 250kHz, and averages the output to produce a sample at the host sample rate. ### Method compute_next_sample(&mut self) -> i16 ### Returns - **i16** - The next audio sample ### Notes For accurate timing, call `set_cpu_cycle()` before each `write_port()` call, and ensure `sample_start_cycle` is updated between samples. ``` -------------------------------- ### PsgBank::generate_samples_interleaved Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/index.html Generates interleaved audio samples from all PSG chips in the bank. ```APIDOC ## PsgBank::generate_samples_interleaved ### Description Generates interleaved audio samples from all PSG chips in the bank. ### Method Method ### Signature `pub fn generate_samples_interleaved(&mut self, buffer: &mut [f32])` ### Parameters - **buffer** (&mut [f32]) - Required - Output buffer to fill with interleaved samples. ### Example ```rust let mut buffer = vec![0.0f32; 882]; bank.generate_samples_interleaved(&mut buffer); ``` ``` -------------------------------- ### write_port_immediate Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Writes to a hardware port with immediate application, bypassing the write queue. Use this only when cycle-accurate timing is not required. ```APIDOC ## write_port_immediate ### Description Writes to a hardware port with immediate application (legacy behavior). This bypasses the write queue and applies the register immediately. ### Method write_port_immediate(&mut self, port: u8, value: u8) ### Parameters - **port** (u8) - Required - Port number (bit 1: 0 = address, 1 = data) - **value** (u8) - Required - Value to write ``` -------------------------------- ### generate_samples Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Generates multiple audio samples and returns them as a vector of f32 values. ```APIDOC ## generate_samples ### Description Generate multiple audio samples. ### Method fn generate_samples(&mut self, count: usize) -> Vec ### Parameters - **count** (usize) - Required - The number of samples to generate. ### Returns - Vec - A vector containing the generated audio samples. ``` -------------------------------- ### reset(&mut self) Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Resets the backend to its initial state. ```APIDOC ## reset(&mut self) ### Description Resets the backend to its initial state. ### Method reset ### Signature `fn reset(&mut self)` ### Parameters - **self** (&mut Self) - Required - The backend instance to reset. ### Returns None ``` -------------------------------- ### PsgBank Source: https://docs.rs/ym2149/latest/ym2149/ Multi-PSG Bank for Arkos Tracker and PlayCity support. ```APIDOC ## PsgBank ### Description Multi-PSG Bank for Arkos Tracker and PlayCity support. ### Methods Not specified in the source. ### Note This struct is re-exported from the `psg_bank` module. ``` -------------------------------- ### Ym2149::get_sample Source: https://docs.rs/ym2149/latest/ym2149/ Retrieves the current audio sample generated by the emulator. ```APIDOC ## Ym2149::get_sample ### Description Retrieves the current audio sample generated by the emulator. ### Method `get_sample()` ### Parameters None ### Returns The current audio sample value. ### Example ```rust let sample = chip.get_sample(); ``` ``` -------------------------------- ### with_clocks(master_clock, sample_rate) Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Creates a new YM2149 emulator with custom clock frequencies. The master clock is divided by 8 internally. ```APIDOC ## with_clocks(master_clock, sample_rate) ### Description Creates a new YM2149 emulator with custom clock frequencies. ### Method with_clocks ### Signature `pub fn with_clocks(master_clock: u32, sample_rate: u32) -> Self` ### Parameters - **master_clock** (u32) - Required - Master clock frequency in Hz (divided by 8 internally) - **sample_rate** (u32) - Required - Audio output sample rate in Hz ### Returns - **Self** - A new Ym2149 instance with the specified clocks. ``` -------------------------------- ### PsgBank::new_with_frequencies Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Creates a new PSG bank where each chip can have a different frequency. Useful for mixed configurations like CPC + PlayCity. Panics if frequencies is empty. ```APIDOC ## PsgBank::new_with_frequencies ### Description Creates a new PSG bank where each chip can have a different frequency. ### Method `pub fn new_with_frequencies(frequencies: Vec) -> Self` ### Parameters - `frequencies` (Vec) - Required - Clock frequencies in Hz for each PSG ### Panics Panics if `frequencies` is empty. ### Examples ```rust use ym2149::PsgBank; // CPC with PlayCity: mixed frequencies let bank = PsgBank::new_with_frequencies(vec![ 1_000_000, // CPC internal PSG 2_000_000, // PlayCity PSG 1 2_000_000, // PlayCity PSG 2 ]); assert_eq!(bank.psg_count(), 3); assert_eq!(bank.channel_count(), 9); ``` ``` -------------------------------- ### reset Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Resets all PSG chips to their initial state. ```APIDOC ## reset ### Description Resets all PSG chips to their initial state. ### Method pub fn reset(&mut self) ``` -------------------------------- ### generate_samples_separate Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Generates audio samples with each PSG output in a separate buffer. Useful for applying different effects or mixing to each PSG, or rendering to separate audio tracks. ```APIDOC ## generate_samples_separate ### Description Generates audio samples with each PSG output in a separate buffer. This is useful when you want to apply different effects or mixing to each PSG, or when rendering to separate audio tracks. ### Method pub fn generate_samples_separate(&mut self, buffers: &mut [&mut [f32]]) ### Parameters - **buffers** (slice of mutable slices of f32) - Required - Slice of output buffers, one per PSG ### Panics Panics if the number of buffers doesn't match the PSG count. ### Example ```rust use ym2149::PsgBank; let mut bank = PsgBank::new(2, 2_000_000); let mut buffer0 = vec![0.0f32; 882]; let mut buffer1 = vec![0.0f32; 882]; let mut buffers = vec![&mut buffer0[..], &mut buffer1[..]]; bank.generate_samples_separate(&mut buffers); // Now buffer0 contains PSG 0 output, buffer1 contains PSG 1 output ``` ``` -------------------------------- ### cpu_cycle() Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Returns the current CPU cycle. ```APIDOC ## cpu_cycle() ### Description Returns the current CPU cycle. ### Method cpu_cycle ### Signature `pub fn cpu_cycle(&self) -> u64` ### Parameters None ### Returns - **u64** - The current CPU cycle count. ``` -------------------------------- ### Ym2149Backend Source: https://docs.rs/ym2149/latest/ym2149/all.html Trait that defines the backend interface for audio output. ```APIDOC ## Ym2149Backend ### Description The `Ym2149Backend` trait defines the methods required for a custom audio backend to be used with the `Ym2149` struct. ### Required Methods Refer to the [trait documentation](https://docs.rs/ym2149/latest/ym2149/trait.Ym2149Backend.html) for the list of required methods. ``` -------------------------------- ### load_registers(&mut self, regs: &[u8; 16]) Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Loads all 16 YM2149 registers at once. ```APIDOC ## load_registers(&mut self, regs: &[u8; 16]) ### Description Loads all 16 YM2149 registers at once. ### Method load_registers ### Signature `fn load_registers(&mut self, regs: &[u8; 16])` ### Parameters - **regs** (&[u8; 16]) - Required - An array of 16 register values. ### Returns None ``` -------------------------------- ### generate_samples_with_channels Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Generates samples with synchronized per-sample channel outputs. ```APIDOC ## generate_samples_with_channels ### Description Generates samples with synchronized per-sample channel outputs. ### Method fn generate_samples_with_channels(&mut self, buffer: &mut [f32], channel_outputs: &mut [[f32; 3]]) ### Parameters - **buffer** (&mut [f32]) - Required - The buffer to write the generated samples into. - **channel_outputs** (&mut [[f32; 3]]) - Required - The buffer to write per-sample channel outputs into. ``` -------------------------------- ### Set CPU cycle for accurate write timing Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Shows how to call set_cpu_cycle before write_port in an emulator's memory write handler to enable hardware-accurate register write timing. ```rust // In your emulator's memory write handler: ym2149.set_cpu_cycle(cpu.total_cycles()); ym2149.write_port(port, value); ``` -------------------------------- ### impl TryInto for T where U: TryFrom Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Provides a blanket implementation of TryInto for any type T that can be converted into U via TryFrom. The associated Error type is the error type of the TryFrom implementation. ```APIDOC ## impl TryInto for T where U: TryFrom ### Description Provides a blanket implementation of TryInto for any type T that can be converted into U via TryFrom. The associated Error type is the error type of the TryFrom implementation. ### Associated Type - **Error** = `>::Error` - The type returned in the event of a conversion error. ### Method #### try_into(self) -> Result>::Error> Performs the conversion. ### Parameters - **self** (T) - The value to convert. ### Returns - **Result>::Error>** - The result of the conversion. ``` -------------------------------- ### TryInto::try_into Source: https://docs.rs/ym2149/latest/ym2149/enum.Ym2149Error.html Performs the conversion from self to U. This is part of the blanket TryInto implementation. ```APIDOC ## TryInto::try_into ### Description Performs the conversion from self to U. ### Method `fn try_into(self) -> Result` ### Parameters - `self` - The value to convert. ### Returns - `Result` - The result of the conversion, where `Error` is the associated type from `TryFrom for T`. ``` -------------------------------- ### clock(&mut self) Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Advances the chip by one clock cycle. ```APIDOC ## clock(&mut self) ### Description Advances the chip by one clock cycle. ### Method clock ### Signature `fn clock(&mut self)` ### Parameters - **self** (&mut Self) - Required - The backend instance. ### Returns None ``` -------------------------------- ### constants::get_volume Source: https://docs.rs/ym2149/latest/ym2149/ Returns the volume value from the hardware volume table. ```APIDOC ## constants::get_volume ### Description Returns the volume value from the hardware volume table. ### Method `get_volume(...)` ### Parameters Not specified in the source. ### Returns The volume value. ### Note This function is re-exported from the `constants` module. ``` -------------------------------- ### impl From for Ym2149Error Source: https://docs.rs/ym2149/latest/ym2149/enum.Ym2149Error.html Allows converting a String into a Ym2149Error. ```APIDOC ## impl From for Ym2149Error ### Description Allows converting a `String` into a `Ym2149Error`. ### Method #### fn from(msg: String) -> Self Converts a string into `Ym2149Error::Other`. ``` -------------------------------- ### set_cpu_cycle(cycle) Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Sets the current CPU cycle for accurate write timing. Call this before each write_port() to enable hardware-accurate register write timing. ```APIDOC ## set_cpu_cycle(cycle) ### Description Sets the current CPU cycle for accurate write timing. Call this before each `write_port()` to enable hardware-accurate register write timing. The CPU cycle is used to queue writes and apply them at the correct time during sample generation. ### Method set_cpu_cycle ### Signature `pub fn set_cpu_cycle(&mut self, cycle: u64)` ### Parameters - **cycle** (u64) - Required - Current CPU cycle count (e.g., from 68000 emulator) ### Returns None ### Example ```rust // In your emulator's memory write handler: ym2149.set_cpu_cycle(cpu.total_cycles()); ym2149.write_port(port, value); ``` ``` -------------------------------- ### generate_samples_interleaved Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Generates audio samples with all PSG outputs mixed together (interleaved). This is the most common use case - all PSGs mixed to a single mono output. ```APIDOC ## generate_samples_interleaved ### Description Generates audio samples with all PSG outputs mixed together (interleaved). This is the most common use case - all PSGs mixed to a single mono output. ### Method pub fn generate_samples_interleaved(&mut self, buffer: &mut [f32]) ### Arguments - `buffer` (&mut [f32]) - Output buffer to fill with samples ### Example ```rust use ym2149::PsgBank; let mut bank = PsgBank::new(2, 2_000_000); let mut buffer = vec![0.0f32; 882]; // 50Hz frame at 44.1kHz bank.generate_samples_interleaved(&mut buffer); ``` ``` -------------------------------- ### VOLUME_TABLE Source: https://docs.rs/ym2149/latest/ym2149/constants/index.html YM2149 hardware volume table (normalized to 0.0-1.0). ```APIDOC ## VOLUME_TABLE ### Description YM2149 hardware volume table (normalized to 0.0-1.0). ### Type `[f32; 16]` ``` -------------------------------- ### impl TryFrom for T where U: Into Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Provides a blanket implementation of TryFrom for any type T that can be converted from U via Into. The associated Error type is the never type (!), indicating that the conversion cannot fail. ```APIDOC ## impl TryFrom for T where U: Into ### Description Provides a blanket implementation of TryFrom for any type T that can be converted from U via Into. The associated Error type is the never type (!), indicating that the conversion cannot fail. ### Associated Type - **Error** = `!` - The type returned in the event of a conversion error. Since the conversion is infallible, this is the never type. ### Method #### try_from(value: U) -> Result Performs the conversion. Since the conversion is infallible, the Result always contains the converted value. ### Parameters - **value** (U) - The value to convert. ### Returns - **Result** - Always Ok with the converted value, as the conversion cannot fail. ``` -------------------------------- ### write_port Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Writes to a hardware port, mimicking real hardware bus access. Register writes are queued with CPU cycle timestamps and applied at the correct time during sample generation. ```APIDOC ## write_port ### Description Writes to a hardware port, mimicking real hardware bus access. Register writes are queued with their CPU cycle timestamp and applied at the correct time during sample generation. ### Method write_port(&mut self, port: u8, value: u8) ### Parameters - **port** (u8) - Required - Port number (bit 1: 0 = address, 1 = data) - **value** (u8) - Required - Value to write ### Timing - Port 0 ($FF8800): Register select - latches immediately - Port 2 ($FF8802): Data write - queued for cycle-accurate application Writes that occur too quickly after a register select (< 4 CPU cycles) are still queued but may not behave as expected on real hardware. ``` -------------------------------- ### get_channel_outputs Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Retrieves the individual output levels for the three audio channels as a tuple of f32 values. ```APIDOC ## get_channel_outputs ### Description Get individual channel outputs. ### Method fn get_channel_outputs(&self) -> (f32, f32, f32) ### Parameters None ### Returns - (f32, f32, f32) - A tuple of three f32 values representing the output of each channel. ``` -------------------------------- ### clock Source: https://docs.rs/ym2149/latest/ym2149/trait.Ym2149Backend.html Advances the chip by one clock cycle, updating all internal generators and producing a new audio sample. Call this at the backend's sample rate. ```APIDOC ## clock(&mut self) ### Description Advance the chip by one clock cycle. Updates all internal generators (tone, noise, envelope) and produces a new audio sample. Call this at the backend's sample rate. ### Method clock ### Signature fn clock(&mut self) ### Parameters None ### Returns None ### Source [Source](https://docs.rs/ym2149-common/0.9.1/x86_64-unknown-linux-gnu/src/ym2149_common/backend.rs.html#101) ``` -------------------------------- ### PsgBank::channel_count Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Returns the total number of channels (PSG count × 3). ```APIDOC ## PsgBank::channel_count ### Description Returns the total number of channels (PSG count × 3). ### Method `pub fn channel_count(&self) -> usize` ### Returns - `usize` - Total number of channels. ``` -------------------------------- ### write_register Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Writes a value to a register on a specific PSG. Panics if the PSG index is out of bounds. ```APIDOC ## write_register ### Description Writes a value to a register on a specific PSG. ### Method pub fn write_register(&mut self, psg_index: usize, register: u8, value: u8) ### Arguments - `psg_index` (usize) - Index of the PSG (0..psg_count) - `register` (u8) - Register number (0-15) - `value` (u8) - Value to write (0-255) ### Panics Panics if `psg_index` is out of bounds. ### Example ```rust use ym2149::PsgBank; let mut bank = PsgBank::new(2, 2_000_000); // Set volume on PSG 0, Channel A bank.write_register(0, 0x08, 0x0F); // Set volume on PSG 1, Channel A bank.write_register(1, 0x08, 0x0F); ``` ``` -------------------------------- ### dump_all_registers Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Dumps the register state of all PSGs for debugging. Returns a vector of register dumps, one per PSG. ```APIDOC ## dump_all_registers ### Description Dumps the register state of all PSGs for debugging. Returns a vector of register dumps, one per PSG. ### Method pub fn dump_all_registers(&self) -> Vec<[u8; 16]> ``` -------------------------------- ### impl From for Ym2149Error Source: https://docs.rs/ym2149/latest/ym2149/enum.Ym2149Error.html Allows converting an io::Error into a Ym2149Error. ```APIDOC ## impl From for Ym2149Error ### Description Allows converting an `io::Error` into a `Ym2149Error`. ### Method #### fn from(source: io::Error) -> Self Converts to this type from the input type. ``` -------------------------------- ### inside_timer_irq Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Alias for set_timer_irq_state (legacy compatibility). ```APIDOC ## inside_timer_irq ### Description Alias for set_timer_irq_state (legacy compatibility). ### Method pub fn inside_timer_irq(&mut self, inside: bool) ### Parameters - **inside** (bool) - Required - Indicates whether inside the timer IRQ handler. ### Return No return value. ``` -------------------------------- ### read_register Source: https://docs.rs/ym2149/latest/ym2149/psg_bank/struct.PsgBank.html Reads a register value from a specific PSG. Panics if the PSG index is out of bounds. ```APIDOC ## read_register ### Description Reads a register value from a specific PSG. ### Method pub fn read_register(&self, psg_index: usize, register: u8) -> u8 ### Arguments - `psg_index` (usize) - Index of the PSG (0..psg_count) - `register` (u8) - Register number (0-15) ### Panics Panics if `psg_index` is out of bounds. ### Returns - `u8` - The value read from the register. ``` -------------------------------- ### Ym2149 Source: https://docs.rs/ym2149/latest/ym2149/all.html The main struct representing the YM2149 sound chip emulator. ```APIDOC ## Ym2149 ### Description The `Ym2149` struct is the primary interface for emulating the YM2149 sound chip. It provides methods to control the chip's registers and generate audio samples. ### Usage Refer to the [struct documentation](https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html) for detailed methods and examples. ``` -------------------------------- ### Trait Ym2149Backend Source: https://docs.rs/ym2149/latest/ym2149/trait.Ym2149Backend.html Common interface for YM2149 chip backends. This trait allows different implementations to be used interchangeably, such as hardware-accurate emulation, experimental software synthesizers, and future implementations like FPGA cores. ```APIDOC ## Trait Ym2149Backend ### Description Common interface for YM2149 chip backends. This trait allows different implementations to be used interchangeably, such as hardware-accurate emulation, experimental software synthesizers, and future implementations like FPGA cores. ### Methods #### Required Methods ##### `fn new() -> Self` - **where** `Self: Sized` - Creates a new backend instance. ##### `fn with_clocks(master_clock: u32, sample_rate: u32) -> Self` - **where** `Self: Sized` - Creates a new backend instance with specified master clock and sample rate. ##### `fn reset(&mut self)` - Resets the backend to its initial state. ##### `fn write_register(&mut self, addr: u8, value: u8)` - Writes a value to a YM2149 register. - **Parameters:** - `addr` (u8) - Register address. - `value` (u8) - Value to write. ##### `fn read_register(&self, addr: u8) -> u8` - Reads a value from a YM2149 register. - **Parameters:** - `addr` (u8) - Register address. - **Returns:** u8 - The register value. ##### `fn load_registers(&mut self, regs: &[u8; 16])` - Loads all 16 registers at once. - **Parameters:** - `regs` (&[u8; 16]) - Array of register values. ##### `fn dump_registers(&self) -> [u8; 16]` - Dumps all 16 register values. - **Returns:** [u8; 16] - Array of register values. ##### `fn clock(&mut self)` - Advances the chip by one clock cycle. ##### `fn get_sample(&self) -> f32` - Returns the current audio sample. - **Returns:** f32 - The current sample value. ##### `fn get_channel_outputs(&self) -> (f32, f32, f32)` - Returns the current output for each of the three channels. - **Returns:** (f32, f32, f32) - Tuple of channel outputs. ##### `fn set_channel_mute(&mut self, channel: usize, mute: bool)` - Mutes or unmutes a specific channel. - **Parameters:** - `channel` (usize) - Channel index (0-2). - `mute` (bool) - Whether to mute the channel. ##### `fn is_channel_muted(&self, channel: usize) -> bool` - Checks if a specific channel is muted. - **Parameters:** - `channel` (usize) - Channel index (0-2). - **Returns:** bool - Whether the channel is muted. ##### `fn set_color_filter(&mut self, enabled: bool)` - Enables or disables a color filter. - **Parameters:** - `enabled` (bool) - Whether to enable the filter. #### Provided Methods ##### `fn generate_samples(&mut self, count: usize) -> Vec` - Generates a specified number of audio samples. - **Parameters:** - `count` (usize) - Number of samples to generate. - **Returns:** Vec - Vector of generated samples. ##### `fn generate_samples_into(&mut self, buffer: &mut [f32])` - Generates audio samples into a provided buffer. - **Parameters:** - `buffer` (&mut [f32]) - Buffer to fill with samples. ##### `fn generate_samples_with_channels(&mut self, buffer: &mut [f32], channel_outputs: &mut [[f32; 3]])` - Generates audio samples and channel outputs into provided buffers. - **Parameters:** - `buffer` (&mut [f32]) - Buffer to fill with samples. - `channel_outputs` (&mut [[f32; 3]]) - Buffer to fill with per-channel outputs. ##### `fn trigger_envelope(&mut self)` - Triggers the envelope generator. ##### `fn set_drum_sample_override(&mut self, _channel: usize, _sample: Option)` - Sets a drum sample override for a channel. - **Parameters:** - `_channel` (usize) - Channel index. - `_sample` (Option) - Optional sample override. ##### `fn set_mixer_overrides(&mut self, _force_tone: [bool; 3], _force_noise_mute: [bool; 3])` - Sets mixer overrides for tone and noise. - **Parameters:** - `_force_tone` ([bool; 3]) - Force tone on/off for each channel. - `_force_noise_mute` ([bool; 3]) - Force noise mute for each channel. ``` -------------------------------- ### Ym2149::clock Source: https://docs.rs/ym2149/latest/ym2149/ Advances the emulator by one clock cycle. ```APIDOC ## Ym2149::clock ### Description Advances the emulator by one clock cycle. ### Method `clock()` ### Parameters None ### Example ```rust chip.clock(); ``` ``` -------------------------------- ### write_register Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Writes a value to a register. ```APIDOC ## write_register ### Description Writes a value to a register. ### Method write_register(&mut self, register: u8, value: u8) ### Parameters - **register** (u8) - Required - Register number (0-13) - **value** (u8) - Required - Value to write ``` -------------------------------- ### impl From<&str> for Ym2149Error Source: https://docs.rs/ym2149/latest/ym2149/enum.Ym2149Error.html Allows converting a string slice into a Ym2149Error::Other variant. ```APIDOC ## impl From<&str> for Ym2149Error ### Description Allows converting a string slice into a `Ym2149Error::Other` variant. ### Method #### fn from(msg: &str) -> Self Converts a string slice into `Ym2149Error::Other`. ``` -------------------------------- ### write_register(&mut self, addr: u8, value: u8) Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Writes a value to a YM2149 register. ```APIDOC ## write_register(&mut self, addr: u8, value: u8) ### Description Writes a value to a YM2149 register. ### Method write_register ### Signature `fn write_register(&mut self, addr: u8, value: u8)` ### Parameters - **addr** (u8) - Required - The register address. - **value** (u8) - Required - The value to write. ### Returns None ``` -------------------------------- ### TryFrom::try_from Source: https://docs.rs/ym2149/latest/ym2149/enum.Ym2149Error.html Performs the conversion from a value of type U to T. This is part of the blanket TryFrom implementation. ```APIDOC ## TryFrom::try_from ### Description Performs the conversion from a value of type U to T. ### Method `fn try_from(value: U) -> Result` ### Parameters - `value` (U) - The value to convert. ### Returns - `Result` - The result of the conversion, where `Error` is the associated type `!` (never type). ``` -------------------------------- ### constants::VOLUME_TABLE Source: https://docs.rs/ym2149/latest/ym2149/all.html Constant representing the lookup table for volume levels. ```APIDOC ## constants::VOLUME_TABLE ### Description The `VOLUME_TABLE` constant is an array of volume values used for converting volume indices to actual amplitude levels. ### Usage Refer to the [constant documentation](https://docs.rs/ym2149/latest/ym2149/constants/constant.VOLUME_TABLE.html) for more details. ``` -------------------------------- ### flush_pending_writes Source: https://docs.rs/ym2149/latest/ym2149/struct.Ym2149.html Flushes all pending writes immediately. Use this at frame boundaries or when resetting to ensure all queued writes are applied. ```APIDOC ## flush_pending_writes ### Description Flushes all pending writes immediately. Use this at frame boundaries or when resetting to ensure all queued writes are applied. ### Method flush_pending_writes(&mut self) ```