spessasynth_core documentation
    Preparing search index...

    Class SpessaSynthProcessor

    The core synthesis engine of SpessaSynth. This module converts sound bank and MIDI data into PCM audio data. The internal synthesis system is modeled after SoundFont2 synthesis model, with additional extensions and functionality.

    MIDI implementation of the synthesizer can be found here.

    These are active when GlobalMIDIParameter.system is set to gm, gm2, or gs.

    These are active when GlobalMIDIParameter.system is set to xg.

    Index
    currentTime: number

    The current time of the synthesizer, in seconds.

    midiChannels: MIDIChannel[] = []

    All MIDI channels of the synthesizer.

    midiParameters: Readonly<GlobalMIDIParameter> = ...

    The global MIDI parameters of the synthesizer. These are only editable via MIDI messages.

    onEventCall?: (event: SynthesizerEventCallback) => unknown

    This property can be defined as a function that listens for events. All events are defined in SynthesizerEvent. It is not called while the eventsEnabled system parameter is false.

    Type Declaration

    ready: Promise<void> = BasicSoundBank.ready

    A Promise that must be awaited before the processor can be used with a compressed sound bank.

    sampleRate: number

    The sample rate, in Hertz.

    soundBankManager: SoundBankManager = ...

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

    systemParameters: Readonly<GlobalSystemParameter> = ...

    The global system parameters of the synthesizer. These are only editable via the API.

    Use SpessaSynthProcessor.setSystemParameter to set them.

    • Executes a MIDI Channel Pressure (Aftertouch) message on the specified channel.

      Parameters

      • channel: number

        The MIDI channel to send the channel pressure on. It usually ranges from 0 to 15, but it depends on the channel count.

      • pressure: number

        The pressure value, from 0 to 127.

      Returns void

    • Executes a MIDI controller change message on the specified channel.

      Parameters

      • channel: number

        The MIDI channel to change the controller on. It usually ranges from 0 to 15, but it depends on the channel count.

      • controller: MIDIController

        The MIDI controller number (0-127). Refer to the MIDI Implementation for the list of controllers supported by default.

      • value: number

        The value of the controller (0-127).

      Returns void

    • Destroy the synthesizer processor, clearing all channels and voices.

      Returns void

    • Executes a MIDI Note Off message on the specified channel. Stops playing a note.

      Parameters

      • channel: number

        The MIDI channel to send the note off. It usually ranges from 0 to 15, but it depends on the channel count.

      • midiNote: number

        The MIDI note number to stop playing. Ranges from 0 to 127.

      Returns void

    • Executes a MIDI Note On message on the specified channel. Starts playing a note.

      Parameters

      • channel: number

        The MIDI channel to send the note on. It usually ranges from 0 to 15, but it depends on the channel count.

      • midiNote: number

        The MIDI note number to play. Ranges from 0 to 127.

      • velocity: number

        The velocity of the note, from 0 to 127. Ranges from 0 to 127, where 127 is the loudest and 1 is the quietest. If the velocity is 0, it will be treated as a Note Off message.

      Returns void

    • A handler for missing presets during program change. By default, it warns to console. It may be useful for allowing the synthesizer to work without any sound banks.

      Parameters

      • patch: MIDIPatch

        The MIDI patch that was requested.

      • system: MIDISystem

        The MIDI System for the request.

      Returns BasicPreset | undefined

      If a BasicPreset instance is returned, it will be used by the channel as a fallback.

    • Executes a MIDI Pitch Wheel message on the specified channel.

      Parameters

      • channel: number

        The MIDI channel to send the pitch wheel on. It usually ranges from 0 to 15, but it depends on the channel count.

      • pitch: number

        The new 14-bit MIDI pitch value (0-16,383). 8,192 is center.

      • midiNote: number = -1

        The MIDI note number for the per-note pitch wheel mode. Leave unset or set it to -1 for the regular pitch wheel.

      Returns void

    • Executes a MIDI Poly Pressure (Aftertouch) message on the specified channel. This differs from the Channel Pressure in that it's per-note and not for the whole channel.

      Parameters

      • channel: number

        The MIDI channel to send the poly pressure on. It usually ranges from 0 to 15, but it depends on the channel count.

      • midiNote: number

        The MIDI note number to apply the pressure to. Ranges from 0 to 127.

      • pressure: number

        The pressure value, from 0 to 127.

      Returns void

    • Renders Float32 PCM audio data to stereo outputs; buffer size must be equal or smaller than maxBufferSize. All float arrays must have the same length.

      The audio is added to the existing contents of the output arrays, so make sure to clear them when reusing them.

      Parameters

      • left: Float32Array

        The left output buffer for PCM data.

      • right: Float32Array

        The right output buffer for PCM data.

      • startIndex: number = 0

        The offset at which to start rendering audio in the provided arrays. Default is 0.

      • sampleCount: number = 0

        The number of samples to render. Default is the entire length, starting from startIndex.

      • OptionalchannelOutputs: Float32Array<ArrayBufferLike>[][]

        optional stereo channel outputs with dry (no effects) PCM data of specific channels. These shouldn't be added to the left and right outputs. Recommended use-case is visualization.

      Returns void

    • Executes a MIDI Program Change message on the specified channel.

      Parameters

      • channel: number

        The MIDI channel to send the program change on. It usually ranges from 0 to 15, but it depends on the channel count.

      • programNumber: number

        The program number to change to, from 0 to 127.

      Returns void

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

      Parameters

      • system: MIDISystem = DEFAULT_SYNTH_MODE

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

      Returns void

    • Stops all notes on all channels.

      Parameters

      • force: boolean = false

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

      Returns void

    • Executes a system exclusive message for the synthesizer.

      Parameters

      • this: SpessaSynthProcessor
      • syx: SysExAcceptedArray

        The system exclusive message as an array of bytes.

      • channelOffset: number = 0

        The channel offset for the message as they usually can only address the first 16 channels. For example, to send a system exclusive on channel 16, send a system exclusive for channel 0 and set an offset of 16.

      Returns void