#waveform #virtual #generate #real-time #fantasy #command #chip

lsynth

A virtual soundchip which generates primitive waveforms in real-time

2 stable releases

1.0.1 Aug 30, 2022

#863 in Audio

44 downloads per month

Custom license

2.5MB
424 lines

LSynth is a virtual soundchip designed to be the APU of the LIKO-12 fantasy console.

Here's the wiki.

Here's the docs.

Go nuts.


lib.rs:

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); }
    }
};
#

Dependencies