pub struct Opl3Chip { /* private fields */ }Expand description
The Opl3Chip struct provides a safe interface for interacting with the Nuked-OPL3 library.
Implementations§
Source§impl Opl3Chip
impl Opl3Chip
Sourcepub fn new(sample_rate: u32) -> Self
pub fn new(sample_rate: u32) -> Self
Creates a new OPL3 chip instance. The chip is initialized with the given sample rate. The internal chip device is Pinned to ensure that it is not moved in memory. The Nuked-OPL3 instance contains many self-referencing pointers, which would be invalidated if moved.
§Arguments
sample_rate- The sample rate to initialize the OPL3 chip with.
§Returns
The new Opl3Chip instance.
§Example
use opl3_rs::Opl3Chip;
let mut chip = Opl3Chip::new(44100);Sourcepub fn reset(&mut self, sample_rate: u32)
pub fn reset(&mut self, sample_rate: u32)
Reinitialize the OPL3 chip instance.
§Arguments
sample_rate- The sample rate to initialize the OPL3 chip with. I have not tested the effects of reinitializing the chip with a different sample rate than the one initially used.
§Example
use opl3_rs::Opl3Chip;
let mut chip = Opl3Chip::new(44100);
chip.reset(44100);Sourcepub fn generate(&mut self, sample: &mut [i16]) -> Result<(), OplError>
pub fn generate(&mut self, sample: &mut [i16]) -> Result<(), OplError>
Generate an audio sample.
Internally, this calls Opl3Generate4Ch and returns samples for the first 2 channels.
§Arguments
sample- A mutable slice of 2 elements that will receive the sample.
§Returns
A Result containing either () on success or an OplError on failure.
§Example
use opl3_rs::Opl3Chip;
let mut chip = Opl3Chip::new(44100);
let mut buffer = [0i16; 2];
_ = chip.generate(&mut buffer);Sourcepub fn generate_resampled(&mut self, sample: &mut [i16]) -> Result<(), OplError>
pub fn generate_resampled(&mut self, sample: &mut [i16]) -> Result<(), OplError>
Generate a resampled audio sample.
§Arguments
sample- A mutable slice of 2 elements that will receive the sample.
§Returns
A Result containing either () on success or an OplError on failure.
§Example
use opl3_rs::Opl3Chip;
let mut chip = Opl3Chip::new(44100);
let mut buffer = [0i16; 2];
_ = chip.generate_resampled(&mut buffer);Sourcepub fn write_register(&mut self, reg: u16, value: u8)
pub fn write_register(&mut self, reg: u16, value: u8)
Sourcepub fn write_register_buffered(&mut self, reg: u16, value: u8)
pub fn write_register_buffered(&mut self, reg: u16, value: u8)
Write a value to an OPL register, in buffered mode.
The OPL3 normally requires a delay between register writes. This function will queue the write operation and execute it after any necessary delay.
§Arguments
reg- The register to write to.value- The value to write to the register.
§Example
use opl3_rs::Opl3Chip;
let mut chip = Opl3Chip::new(44100);
chip.write_register_buffered(0x20, 0x01);Sourcepub fn generate_stream(&mut self, buffer: &mut [i16]) -> Result<(), OplError>
pub fn generate_stream(&mut self, buffer: &mut [i16]) -> Result<(), OplError>
Generates a stream of resampled audio samples.
The number of samples generated is determined by the size of the buffer provided.
§Arguments
buffer- A mutable reference to a slice of i16 that will be filled with resampled audio samples.
§Returns
A Result containing either () on success or an OplError on failure.
§Example
use opl3_rs::Opl3Chip;
let mut chip = Opl3Chip::new(44100);
let mut buffer = [0i16; 1024 * 2];
_ = chip.generate_stream(&mut buffer);Sourcepub fn generate_4ch(&mut self, sample: &mut [i16]) -> Result<(), OplError>
pub fn generate_4ch(&mut self, sample: &mut [i16]) -> Result<(), OplError>
Generate a 4 channel audio sample.
§Arguments
sample- A mutable, 4-element slice of i16 that will receive the sample.
§Returns
A Result containing either () on success or an OplError on failure.
§Example
use opl3_rs::Opl3Chip;
let mut chip = Opl3Chip::new(44100);
let mut buffer = [0i16; 4];
_ = chip.generate_4ch(&mut buffer);Sourcepub fn generate_4ch_resampled(
&mut self,
sample: &mut [i16],
) -> Result<(), OplError>
pub fn generate_4ch_resampled( &mut self, sample: &mut [i16], ) -> Result<(), OplError>
Generate a 4-channel resampled audio sample.
§Arguments
sample- A mutable, 4-element slice of i16 that will receive the sample.
§Returns
A Result containing either () on success or an OplError on failure.
§Example
use opl3_rs::Opl3Chip;
let mut chip = Opl3Chip::new(44100);
let mut buffer = [0i16; 4];
_ = chip.generate_4ch_resampled(&mut buffer);Sourcepub fn generate_4ch_stream(
&mut self,
buffer1: &mut [i16],
buffer2: &mut [i16],
) -> Result<(), OplError>
pub fn generate_4ch_stream( &mut self, buffer1: &mut [i16], buffer2: &mut [i16], ) -> Result<(), OplError>
Generates a stream of 4-channel audio samples, resampled to the configured sample rate. The OPL3 was capable of 4-channel output, although this feature was not widely used. Most cards simply didn’t provide 4-channel outputs, although there now exist modern reproduction cards that do.
The number of samples is determined by the size of the input buffers.
§Arguments
buffer1- A mutable reference to a slice that will be filled with the first stereo audio samples, interleaved between left and right channels.buffer2- A mutable reference to a slice that will be filled with audio samples for the channels 2 and 3. The length of buffer1 should equal the length of buffer2.
§Returns
A Result containing either () on success or an OplError on failure.
§Example
use opl3_rs::Opl3Chip;
let mut chip = Opl3Chip::new(44100);
let mut buffer1 = [0i16; 1024 * 2];
let mut buffer2 = [0i16; 1024 * 2];
_ = chip.generate_4ch_stream(&mut buffer1, &mut buffer2);