Expand description
This library is for generating L-Synth audio streams.
Here is an example of the basic setup of the LSynth chip. Whatever library you are using to play this audio should provide an audio buffer for L-Synth to populate, represented here by the buffer
parameter of audio_sample_request
use lsynth::*;
let mut chip = ChipState::new(4, ChipParameters::new(44_100, 0.5, 120.0));
chip.send_command(Command::SetAmplitude(0.5), 0);
chip.send_command(Command::SetFrequency(110.0), 0);
let mut frequency = 110.0;
let mut beat = 0;
let mut request_callback = move |chip: &mut ChipState| {
beat += 1;
while beat >= 4 {
frequency += 110.0;
chip.send_command(Command::SetFrequency(frequency), 0);
beat -= 4;
}
};
let mut audio_sample_request = move |buffer: &mut [f32]| {
let mut sample_index = 0;
while sample_index < buffer.len() {
let generated_data = chip.generate(&mut buffer[sample_index..]).unwrap();
sample_index += generated_data.generated;
assert!(generated_data.generated != 0);
if generated_data.remaining_samples == 0 { request_callback(&mut chip); }
}
};
Modules§
- c_
compatible - Provides C compatible functions for working with this library as a DLL.
- errors
- Contains the error types that LSynth could return
- waveform
- Contains the formulas for generating all the different types of waveforms. All generated samples are between -1 and 1, and the provided periods are expected to be between 0 and 1.
Structs§
- Chip
Generation Data - Data returned by the generate function of ChipState.
- Chip
Parameters - Parameters detailing how an LSynth chip is intended to operate.
- Chip
State - The current state of the LSynth chip.
Enums§
- Command
- The different types of commands that can be sent to channels.