Options
All
  • Public
  • Public/Protected
  • All
Menu

Multi-instrument SoundFont. Must be initialized and samples must be pre-loaded using the loadSamples method before any notes can be played.

If you want to use your own SoundFont samples, your SoundFont directory must have this structure:

└─your_local_soundfont |-- soundfont.json |-- instrument_name (for each of the instruments listed in soundfont.json) |-- instrument.json |-- p1_v1.mp3 |-- p1_v2.mp3 |-- ... |-- p${PITCH}_v${VELOCITY}.mp3, for all the pitches and velocities you want to support

The soundfont.json file contains the name of the SoundFont, as well as all the available instruments. The sgm_plus/soundfont.json for example looks like: { "name": "sgm_plus", "instruments": { "0": "acoustic_grand_piano", "1": "bright_acoustic_piano", "2": "electric_grand_piano", ... }

For each of the instruments listed in the soundfont.json file, the instrument.json contains an InstrumentSpec. For example, the sgm_plus/acoustic_grand_piano/instrument.json:

{ "name": "acoustic_grand_piano", "minPitch": 21, "maxPitch": 108, "durationSeconds": 3.0, "releaseSeconds": 1.0, "percussive": false, "velocities": [15, 31, 47, 63, 79, 95, 111, 127] }

Hierarchy

  • SoundFont

Index

Constructors

constructor

Properties

name

name: string

Methods

initialize

  • initialize(): Promise<void>
  • Loads SoundFont configuration from a soundfont.json file in the base URL directory. Does not load any of the samples.

    Returns Promise<void>

loadSamples

  • Load samples necessary to play a set of notes. This must be called before any notes can be played.

    Parameters

    Returns Promise<void>

playNote

  • playNote(pitch: number, velocity: number, startTime: number, duration: number, program?: number, isDrum?: boolean, output: any): void
  • Play a note using one of the sampled instruments.

    Parameters

    • pitch: number

      Pitch of the note.

    • velocity: number

      Velocity of the note.

    • startTime: number

      Time at which to start playing the note.

    • duration: number

      Length of the note in seconds.

    • Default value program: number = 0

      Program number to use for instrument lookup.

    • Default value isDrum: boolean = false

      Drum status to use for instrument lookup.

    • output: any

      Output AudioNode.

    Returns void

playNoteDown

  • playNoteDown(pitch: number, velocity: number, program?: number, isDrum?: boolean, output: any): void
  • Strikes a note down using one of the sampled instruments. If you call this twice without calling playNoteUp() in between, it will implicitly release the note before striking it the second time.

    Parameters

    • pitch: number

      Pitch of the note.

    • velocity: number

      Velocity of the note.

    • Default value program: number = 0

      Program number to use for instrument lookup.

    • Default value isDrum: boolean = false

      Drum status to use for instrument lookup.

    • output: any

      Output AudioNode.

    Returns void

playNoteUp

  • playNoteUp(pitch: number, velocity: number, program?: number, isDrum?: boolean, output: any): void
  • Releases a note using one of the sampled instruments. If you call this twice without calling playNoteDown() in between, it will not implicitly call playNoteDown() for you, and the second call will have no noticeable effect.

    Parameters

    • pitch: number

      Pitch of the note.

    • velocity: number

      Velocity of the note.

    • Default value program: number = 0

      Program number to use for instrument lookup.

    • Default value isDrum: boolean = false

      Drum status to use for instrument lookup.

    • output: any

      Output AudioNode.

    Returns void

Generated using TypeDoc