class Haematite::Synthesizer

Overview

A SoundFont synthesizer.

Note that this class does not provide thread safety. If you wish to send notes and render the waveform in separate threads, you must ensure that the related methods/functions will not be called simultaneously.

Included Modules

Defined in:

haematite/synthesizer.cr

Constant Summary

CHANNEL_COUNT = 16

The number of MIDI channels.

PERCUSSION_CHANNEL = 9

The default channel for percussion.

Constructors

Instance Method Summary

Instance methods inherited from module Haematite::AudioRenderer

render(dest : Array(Float64) | Slice(Float64), pool : RemiLib::ArrayPool(Float64)) : Bool
render(dest : Array(Float32) | Slice(Float32), pool : RemiLib::ArrayPool(Float64)) : Bool
render(left : Slice(Float64), right : Slice(Float64)) : Bool
render(dest : Array(Float64) | Slice(Float64) | Array(Float32) | Slice(Float32)) : Bool
render

Constructor Detail

def self.new(sf : String | Path, settings : SynthesizerSettings) #

Creates a new Synthesizer instance by loading a SoundFont from the given path.


def self.new(soundFont : SoundFont, sampleRate : Int32) #

Creates a new Synthesizer instance that will use the given SoundFont.


def self.new(soundFont : SoundFont, settings : SynthesizerSettings) #

Creates a new Synthesizer instance that will use the given SoundFont.


Instance Method Detail

def activeChannels : BitArray #

def activeVoiceCount : Int32 #

The number of active voices.


def applySettings(settings : SynthesizerSettings) #

Applies a new set of settings to this Synthesizer instance.


def blockSize : Int32 #

The size of rendered blocks of audio, in bytes.

This is set when the instance is created via a SynthesizerSettings instance.


def bypassChorus : Bool #

When both this is false and #enableChorus is true, a chorus effect will be mixed into the output audio.

Unlike #enableChorus, this one is meant as a temporary switch. The chorus unit will continue to process information even when this is turned off, but will simply not be mixed into the output.


def bypassChorus=(bypassChorus : Bool) #

When both this is false and #enableChorus is true, a chorus effect will be mixed into the output audio.

Unlike #enableChorus, this one is meant as a temporary switch. The chorus unit will continue to process information even when this is turned off, but will simply not be mixed into the output.


def bypassReverb : Bool #

When both this is false and #enableReverb is true, a reverb effect will be mixed into the output audio.

Unlike #enableReverb, this one is meant as a temporary switch. The reverb unit will continue to process information even when this is turned off, but will simply not be mixed into the output.


def bypassReverb=(bypassReverb : Bool) #

When both this is false and #enableReverb is true, a reverb effect will be mixed into the output audio.

Unlike #enableReverb, this one is meant as a temporary switch. The reverb unit will continue to process information even when this is turned off, but will simply not be mixed into the output.


def chanFilterMode : FilterMode #

The type of lowpass filter to use. That is, the filter that gets applied according to MIDI controller 74/71 when outputting a voice.

This is set when the instance is created via a SynthesizerSettings instance.


def channels : Array(AudChannel) #

The set of MIDI channels.


def chorus : RemiAudio::DSP::HeraChorus #

def chorusInterpolation : RemiAudio::Interpolate::Mode #

The interpolation mode to use for the chorus.

This is set when the instance is created via a SynthesizerSettings instance.


def chorusSend : UInt8 #

Overrides the initial chorus level on all channels. Later MIDI events may still change the chorus. This does not affect the reverb settings for the instruments themselves.

This is set when the instance is created via a SynthesizerSettings instance.


def enableChorus : Bool #

When true, a chorus effect will be mixed into the output audio.

This is set when the instance is created via a SynthesizerSettings instance.


def enablePresetRemapping : Bool #

When enabled, presets that are not found are re-mapped to a preset with the same number in the default bank (0).

This is mainly intended for MIDI files that use non-standard bank numbers for General MIDI instruments. For example, the Roland JV-1010 uses bank 10371 for General MIDI patches.

This is set when the instance is created via a SynthesizerSettings instance.


def enableReverb : Bool #

When true, a reverb effect will be mixed into the output audio.

This is set when the instance is created via a SynthesizerSettings instance.


def enableSoftClipping : Bool #

When true, output from the synthesizer will have soft clipping applied to it.

This is set when the instance is created via a SynthesizerSettings instance.


def enableStereoEnhancer : Bool #

When true, a stereo enhancement effect will be applied to the output audio.

This is set when the instance is created via a SynthesizerSettings instance.


def instrumentChorus : Int16 | Nil #

Overrides the chorus level on all instruments/presets by setting the appropriate generator parameter.

This is set when the instance is created via a SynthesizerSettings instance.


def instrumentReverb : Int16 | Nil #

Overrides the reverb level on all instruments/presets by setting the appropriate generator parameter.

This is set when the instance is created via a SynthesizerSettings instance.


def mainVolume : Float64 #

The output volume.


def mainVolume=(mainVolume : Float64) #

The output volume.


def maximumPolyphony : Int32 #

The maximum number of concurrently playing voices.

This is set when the instance is created via a SynthesizerSettings instance.


def minimumVoiceDuration : Int32 #

The minimum length for a voice.


def noteOff(channel : Int32, key : Int32) #

Releases the given note on a given channel.


def noteOffAll(channel : Int32, immediate : Bool) #

Releases all notes on the given channel. If immediate is true, then they are immediately stopped. Otherwise, the voices are allowed to go through their release cycles.


def noteOffAll(immediate : Bool) #

Releases all notes on all channels. If immediate is true, then they are immediately stopped. Otherwise, the voices are allowed to go through their release cycles.


def noteOn(channel : Int32, key : Int32, velocity : Int32) #

Starts playing a note with the given velocity on the given channel.


def processMidiMessage(channel : Int32, command : Int32, data1 : Int32, data2 : Int32) #

Processes a single MIDI message.


def render(left : Slice(Float64), right : Slice(Float64)) : Bool #

Renders audio to left and right. This returns true if the song is not finished, or if the sequencer is set to loop. Otherwise this returns false when the song is finished and there is nothing left to render.


def reset #

Resets the synthesizer.


def resetAllControllers(channel : Int32) #

Resets all MIDI controller values on the given channel.


def resetAllControllers #

Resets all MIDI controller values on all channels.


def reverb : RemiAudio::DSP::Reverb #

def reverbSend : UInt8 #

Overrides the initial reverb level on all channels. Later MIDI events may still change the reverb. This does not affect the reverb settings for the instruments themselves.

This is set when the instance is created via a SynthesizerSettings instance.


def sampleRate : Int32 #

The output sample rate.

This is set when the instance is created via a SynthesizerSettings instance.


def settings : SynthesizerSettings | Nil #

The last set of settings loaded into this synthesizer, or nil if no settings have been applied.


def soundFont : SoundFont | Nil #

The SoundFont loaded into the synthesizer.


def soundFont? : SoundFont | Nil | Nil #

The SoundFont loaded into the synthesizer.


def stereoEnhancement : Float64 #

The amount of stereo enhancement to apply when the stereo enhancer effect is enabled.

This is set when the instance is created via a SynthesizerSettings instance.


def voiceFilterMode : FilterMode #

The type of lowpass filter to use for voices. That is, the filter that gets applied according to the SoundFont specification when rendering a voice.

This is set when the instance is created via a SynthesizerSettings instance.