Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • Instrument

Index

Constructors

constructor

Properties

durationSeconds

durationSeconds: number

maxPitch

maxPitch: number

minPitch

minPitch: number

name

name: string

percussive

percussive: boolean

releaseSeconds

releaseSeconds: number

sourceMap

sourceMap: Map<number, any>

Optional velocities

velocities: number[]

Methods

getBuffer

  • getBuffer(pitch: number, velocity: number): any
  • Get the buffer for this pitch and velocity, if it exists.

    throws

    Error if this instrument is not initialized, if the pitch is invalid, or if the buffer cannot be found or loaded.

    Parameters

    • pitch: number

      Pitch of the note.

    • velocity: number

      Velocity of the note.

    Returns any

initialize

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

    Returns Promise<void>

loadSamples

  • loadSamples(samples: SampleInfo[]): Promise<void>
  • Load samples necessary to play a set of pitch/velocity pairs. This must be called before any notes can be played.

    Parameters

    • samples: SampleInfo[]

      Array of pitch/velocity pairs.

    Returns Promise<void>

playNote

  • playNote(pitch: number, velocity: number, startTime: number, duration: number, output: any): void
  • Play a note using one of the samples.

    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.

    • output: any

      Output AudioNode.

    Returns void

playNoteDown

  • playNoteDown(pitch: number, velocity: number, output: any): void
  • Strike a note down using one of the samples. 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.

    • output: any

      Output AudioNode.

    Returns void

playNoteUp

  • playNoteUp(pitch: number, velocity: number, output: any): void
  • Release a note using one of the samples. 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.

    • output: any

      Output AudioNode.

    Returns void

Generated using TypeDoc