Expand description

This library is for generating LSynth audio streams.

Here is an example of the basic setup of the LSynth chip.

use lsynth::*;
 
let mut chip = ChipState::new(4, ChipParameters::new(44_100, 0.5, 120.0));
 
chip.send_command(Command::SetAmplitude(0.0), 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

Provides C compatible functions for working with this library as a DLL.

Contains the error types that LSynth could return

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

Data returned by the generate function of ChipState.

Parameters detailing how an LSynth chip is intended to operate.

The current state of the LSynth chip.

Enums

The different types of commands that can be sent to channels.