Class Synthesizer

Namespace
SpessaSharp.Synthesizer
Assembly
SpessaSharp.dll

The core synthesis engine which interacts with channels and holds all the synth parameters.

public sealed class Synthesizer
Inheritance
Synthesizer
Inherited Members

Fields

ChorusInput

The chorus processor's input buffer.

public readonly float[] ChorusInput

Field Value

float[]

ChorusProcessor

The synthesizer's chorus processor.

public readonly Effect.ChorusProcessor ChorusProcessor

Field Value

Effect.ChorusProcessor

CurrentTime

The current time of the synthesizer, in seconds.

public double CurrentTime

Field Value

double

DEFAULT_PERCUSSION

public const int DEFAULT_PERCUSSION = 9

Field Value

int

DefaultMode

public const Midi.System DefaultMode = GS

Field Value

Midi.System

DefaultPreset

Synth's default (reset) preset.

public BasicPreset? DefaultPreset

Field Value

BasicPreset

DelayActive

Delay is not used outside SC-88+ MIDIs, this is an optimization.

public bool DelayActive

Field Value

bool

DelayInput

The reverb processor's input buffer.

public readonly float[] DelayInput

Field Value

float[]

DelayProcessor

The synthesizer's delay processor.

public readonly Effect.DelayProcessor DelayProcessor

Field Value

Effect.DelayProcessor

DrumPreset

Synth's default (reset) drum preset.

public BasicPreset? DrumPreset

Field Value

BasicPreset

EFX_SENDS_GAIN_CORRECTION

This is needed because effects (regular ones) are send straight from the mono signal, whereas insertion effects receive the panned audio (twice), which reduces gain by a factor of cos(pi/4) * cos(pi/4) (master pan + voice pan). This reverses it.

public static readonly float EFX_SENDS_GAIN_CORRECTION

Field Value

float

EventCallbackHandler

Calls when an event occurs.

public readonly Action<Event> EventCallbackHandler

Field Value

Action<Event>

FreeVoices

Unused voices of this synthesizer

public readonly List<Voice> FreeVoices

Field Value

List<Voice>

GENERATOR_OVERRIDE_NO_CHANGE_VALUE

public const short GENERATOR_OVERRIDE_NO_CHANGE_VALUE = 32767

Field Value

short

GainSmoothingFactor

Gain smoothing factor, adjusted to the sample rate.

public readonly float GainSmoothingFactor

Field Value

float

InsertionInputL

The insertion processor's left input buffer.

public readonly float[] InsertionInputL

Field Value

float[]

InsertionInputR

The insertion processor's right input buffer.

public readonly float[] InsertionInputR

Field Value

float[]

KeyModifierManager

Handles the custom key overrides: velocity and preset

public readonly KeyModifier.Manager KeyModifierManager

Field Value

KeyModifier.Manager

MIDI_CHANNEL_COUNT

public const int MIDI_CHANNEL_COUNT = 16

Field Value

int

MIN_EXCLUSIVE_LENGTH

This sounds way nicer for an instant hi-hat cutoff

public const float MIN_EXCLUSIVE_LENGTH = 0.07

Field Value

float

MIN_NOTE_LENGTH

If the note is released faster than that, it forced to last that long This is used mostly for drum channels, where a lot of midis like to send instant note off after a note on

public const float MIN_NOTE_LENGTH = 0.03

Field Value

float

MaxBufferSize

The maximum allowed buffer size to render.

public readonly int MaxBufferSize

Field Value

int

MidiChannels

All MIDI channels of the synthesizer.

public readonly List<MidiChannel> MidiChannels

Field Value

List<MidiChannel>

MidiParameters

The global MIDI parameters of the synthesizer.

public readonly GlobalMidiParameter[] MidiParameters

Field Value

GlobalMidiParameter[]

MissingPreset

public readonly Synthesizer.MissingPresetHandler MissingPreset

Field Value

Synthesizer.MissingPresetHandler

PanSmoothingFactor

Pan smoothing factor, adjusted to the sample rate.

public readonly float PanSmoothingFactor

Field Value

float

ReverbInput

The reverb processor's input buffer.

public readonly float[] ReverbInput

Field Value

float[]

ReverbProcessor

The synthesizer's reverb processor.

public readonly Effect.ReverbProcessor ReverbProcessor

Field Value

Effect.ReverbProcessor

SPESSASYNTH_GAIN_FACTOR

This gain factor ensures that spessasynth doesn't stay too loud. You can set the gain system parameter to an inverse of it to negate the effect.

public const float SPESSASYNTH_GAIN_FACTOR = 0.6

Field Value

float

SPESSA_BUFSIZE

Buffer size is recommended to be very small, as this is the interval between modulator updates and LFO updates

public const int SPESSA_BUFSIZE = 128

Field Value

int

SampleRate

public readonly int SampleRate

Field Value

int

SoundBankManager

The sound bank manager, which manages all sound banks and presets.

public readonly SoundBankManager SoundBankManager

Field Value

SoundBankManager

SystemParameters

The system parameters of the synthesizer.

public readonly GlobalSystemParameter[] SystemParameters

Field Value

GlobalSystemParameter[]

Tunings

This.tunings[program * 128 + key] = midiNote,cents (fraction). All MIDI Tuning Standard tunings, 128 keys for each of 128 programs. -1 means no change.

public readonly float[] Tunings

Field Value

float[]

VOICE_CAP

public const int VOICE_CAP = 350

Field Value

int

VoiceBuffer

The buffer to use when rendering a voice.

public readonly float[] VoiceBuffer

Field Value

float[]

Voices

Active Voices of this synthesizer

public readonly List<Voice> Voices

Field Value

List<Voice>

Properties

CustomChannelNumbers

A sysEx may set a "Part" (channel) to receive on a different channel number. This slows down the access, so this toggle tracks if it's enabled or not.

public bool CustomChannelNumbers { get; }

Property Value

bool

VoiceCount

Current total amount of voices that are currently playing.

public int VoiceCount { get; }

Property Value

int

Methods

AssignVoice()

Assigns the first available voice for use. If none available, will assign priorities.

public Voice AssignVoice()

Returns

Voice

CallEvent(Event)

Copied callback so MIDI channels can call it.

public void CallEvent(Event ev)

Parameters

ev Event

ChannelPressure(int, int)

public void ChannelPressure(int channel, int pressure)

Parameters

channel int
pressure int

ClearCache()

public void ClearCache()

ControllerChange(int, CC, int)

public void ControllerChange(int channel, Midi.CC controller, int value)

Parameters

channel int
controller Midi.CC
value int

CreateMIDIChannel(bool)

public void CreateMIDIChannel(bool sendEvent)

Parameters

sendEvent bool

Destroy()

public void Destroy()

GetInsertionSnapshot()

public Effect.InsertionProcessorSnapshot GetInsertionSnapshot()

Returns

Effect.InsertionProcessorSnapshot

LockParameter(Type, bool)

Locks or unlocks a given Global MIDI Parameter. This prevents any changes to it until it's unlocked.

public void LockParameter(GlobalMidiParameter.Type parameter, bool isLocked)

Parameters

parameter GlobalMidiParameter.Type

The Global MIDI Parameter to lock.

isLocked bool

If the parameter should be locked.

NoteOff(int, int)

public void NoteOff(int channel, int midiNote)

Parameters

channel int
midiNote int

NoteOn(int, int, int)

public void NoteOn(int channel, int midiNote, int velocity)

Parameters

channel int
midiNote int
velocity int

PitchWheel(int, short, int?)

public void PitchWheel(int channel, short pitch, int? midiNote = null)

Parameters

channel int
pitch short
midiNote int?

PolyPressure(int, int, int)

public void PolyPressure(int channel, int midiNote, int pressure)

Parameters

channel int
midiNote int
pressure int

Process(ArraySegment<float>, ArraySegment<float>, int, int?)

public void Process(ArraySegment<float> left, ArraySegment<float> right, int startIndex = 0, int? sampleCount = null)

Parameters

left ArraySegment<float>
right ArraySegment<float>
startIndex int
sampleCount int?

Process(Span<short>, int, int?)

public void Process(Span<short> output, int startIndex = 0, int? sampleCount = null)

Parameters

output Span<short>
startIndex int
sampleCount int?

ProcessMessage(ReadOnlySpan<byte>, int, double?)

Processes a raw MIDI message.

public void ProcessMessage(ReadOnlySpan<byte> message, int channelOffset = 0, double? time = null)

Parameters

message ReadOnlySpan<byte>

The message to process.

channelOffset int

The channel offset for the message.

time double?

The audio context time when the event should execute, in seconds.

ProcessSplit(ReadOnlySpan<(ArraySegment<float> Left, ArraySegment<float> Right)>, Span<float>, Span<float>, int, int?)

The main rendering pipeline, renders all voices and processes the effects

public void ProcessSplit(ReadOnlySpan<(ArraySegment<float> Left, ArraySegment<float> Right)> outputs, Span<float> effectsLeft, Span<float> effectsRight, int startIndex = 0, int? samples = null)

Parameters

outputs ReadOnlySpan<(ArraySegment<float> Left, ArraySegment<float> Right)>

The stereo pairs for each MIDI channel's dry output, will be wrapped if less.

effectsLeft Span<float>

The left stereo effect output buffer.

effectsRight Span<float>

The right stereo effect output buffer.

startIndex int

The index to start writing at into the output buffer.

samples int?

The amount of samples to write.

Remarks

               ┌────────────────────────────────┐
               │        Voice Processor         │
               └───────────────┬────────────────┘
                               │
               ┌───────────────┴────────────────┐
               │      Insertion Processor       │
               │      (Bypass or Process)       │
               └───────────────┬────────────────┘
                               │
          ┌──────────┬─────────┼────────────────────────┐
          │          │         │                        │
          │          │         v                        │
          │          │ ┌───────┴───────┐                │
          │          │ │    Chorus     │                │
          │          │ │   Processor   ├──────────┐     │
          │          │ └─┬──────────┬──┘          │     │
          │          │   │          │             │     │
          │          │   │          │             │     │
          │          │   │          │             │     │
          │          │   │          │             │     │
          │          │   │          v             v     v
          │          │   │ ┌────────┴───────┐   ┌─┴─────┴────────┐
          │          └───┼>┤     Delay      ├─>>┤     Reverb     │
          │              │ │   Processor    │   │   Processor    │
          │              │ └────────┬───────┘   └───────┬────────┘
          │              │          │                   │
          │              │          │                   │
          │              │          │                   │
          │              │          │                   │
          v              v          v                   v
┌─────────┴──────────┐ ┌─┴──────────┴───────────────────┴────┐
│  Dry Output Pairs  │ │        Stereo Effects Output        │
└────────────────────┘ └─────────────────────────────────────┘

The pipeline is quite similar to the one on SC-8850 manual page 78. All output arrays must be the same length, the method will crash otherwise.

ProgramChange(int, int)

public void ProgramChange(int channel, int programNumber)

Parameters

channel int
programNumber int

Reset(System)

Executes a full system reset of the synthesizer. This will reset all controllers to their default values, except for the locked controllers.

public void Reset(Midi.System system = System.GS)

Parameters

system Midi.System

The MIDI system to reset the synthesizer to. Defaults to gs.

Set(GlobalSystemParameter)

Sets a system parameter of the synthesizer.

public void Set(GlobalSystemParameter param)

Parameters

param GlobalSystemParameter

The type and value of the system parameter to set.

StopAllChannels(bool)

Stops all notes on all channels.

public void StopAllChannels(bool force)

Parameters

force bool

If true, all notes are stopped immediately, otherwise they are stopped gracefully.

SystemExclusive(ReadOnlySpan<byte>, int)

public void SystemExclusive(ReadOnlySpan<byte> syx, int channelOffset = 0)

Parameters

syx ReadOnlySpan<byte>
channelOffset int