Skip to main content

Crate rustysynth_ext

Crate rustysynth_ext 

Source
Expand description

A SoundFont (.sf2 and, behind the sf3 feature, .sf3) MIDI synthesizer written in pure Rust.

A SoundFont is loaded once and shared behind an Arc, and a Synthesizer built from it renders the waveform into a pair of f32 buffers, either played directly with Synthesizer::note_on and friends or driven by a MidiFile through a MidiFileSequencer.

use std::fs::File;
use std::sync::Arc;

use rustysynth_ext::{SoundFont, Synthesizer, SynthesizerSettings};

let mut sf2 = File::open("TimGM6mb.sf2").unwrap();
let sound_font = Arc::new(SoundFont::new(&mut sf2).unwrap());

let settings = SynthesizerSettings::new(44100);
let mut synthesizer = Synthesizer::new(&sound_font, &settings).unwrap();

synthesizer.note_on(0, 60, 100);

let mut left = vec![0.0_f32; 44100];
let mut right = vec![0.0_f32; 44100];
synthesizer.render(&mut left, &mut right);

Structs§

Instrument
Represents an instrument in the SoundFont.
InstrumentRegion
Represents an instrument region. An instrument region contains all the parameters necessary to synthesize a note.
MidiFile
Represents a standard MIDI file.
MidiFileSequencer
An instance of the MIDI file sequencer.
Preset
Represents a preset in the SoundFont.
PresetRegion
Represents a preset region. A preset region indicates how the parameters of the instrument should be modified in the preset.
SampleHeader
Represents a sample in the SoundFont.
SoundFont
Represents a SoundFont.
SoundFontInfo
The information of a SoundFont.
SoundFontVersion
Represents the version of a SoundFont.
Synthesizer
An instance of the SoundFont synthesizer.
SynthesizerSettings
Specifies a set of parameters for synthesis.

Enums§

LoopMode
Specifies how the sample loops during playback.
MidiFileError
Represents an error when loading a MIDI file.
MidiFileLoopType
Specifies the type of the loop extension to use when playing back a MIDI file.
MidiMessage
A single event of a merged MIDI file.
SoundFontError
Represents an error when loading a SoundFont.
SynthesizerError
Represents an error when initializing a synthesizer.