Skip to main content

SoundTrack

A single playback of a Sound. Produced by Sound.play(), Sound.start() and Sound.seek(), see Sound.instances.

Wraps a single-use Web Audio AudioBufferSourceNode routed through a per-track volume gain; a fresh buffer source is allocated each time the track (re)starts.

@see

Index

Constructors

constructor

  • Parameters

    • _buffer: AudioBuffer

      The decoded audio to play

    • _destination: AudioNode

      The node this track is wired into (the owning Sound's output)

    • optional_onPlay: AudioGraphBuilder

      Optional hook that wires source → destination, see AudioGraphBuilder

    Returns SoundTrack

Properties

publicreadonlyid

id: number = ...

Monotonically increasing id, older tracks have lower ids

publicscheduledStartTime

scheduledStartTime: number = 0

Audio context time in seconds at which the next (re)start is scheduled, 0 means immediately

Accessors

publicdone

  • get done(): Promise<boolean>
  • Resolves when the track completes or is stopped


    Returns Promise<boolean>

publicduration

  • get duration(): number
  • set duration(duration: number | undefined): void
  • The duration in seconds this track plays for, or the buffer's total duration when unset.

    Note: the duration starts from the seeked position, seeking a 10 second clip to 5 seconds and setting a duration of 2 plays seconds 5-7.


    Returns number

  • Parameters

    • duration: number | undefined

    Returns void

publicloop

  • get loop(): boolean
  • set loop(value: boolean): void
  • Loop infinitely, when changed the live source is updated


    Returns boolean

  • Parameters

    • value: boolean

    Returns void

publicpitch

  • get pitch(): number
  • set pitch(pitch: number): void
  • Pitch shift in cents (a semitone is 100 cents), default 0. Backed by AudioBufferSourceNode.detune and composes with SoundTrack.playbackRate. Note: detune also changes playback speed, this is a Web Audio limitation.


    Returns number

  • Parameters

    • pitch: number

    Returns void

publicplaybackRate

  • get playbackRate(): number
  • set playbackRate(playbackRate: number): void
  • Playback speed multiplier, default 1


    Returns number

  • Parameters

    • playbackRate: number

    Returns void

publicvolume

  • get volume(): number
  • set volume(value: number): void
  • Volume [0-1] of this track only, multiplied with Sound.volume. Default 1.


    Returns number

  • Parameters

    • value: number

    Returns void

Methods

publicgetPlaybackPosition

  • getPlaybackPosition(): number
  • Current position in the buffer in seconds


    Returns number

publicgetTotalPlaybackDuration

  • getTotalPlaybackDuration(): number
  • Returns number

publicisPaused

  • isPaused(): boolean
  • Returns boolean

publicisPlaying

  • isPlaying(): boolean
  • Returns boolean

publicisStopped

  • isStopped(): boolean
  • Returns boolean

publicpause

  • pause(): void
  • Returns void

publicplay

  • play(playStarted?: () => any): Promise<boolean>
  • Start or resume playback, resolves when the track stops or completes


    Parameters

    • playStarted: () => any = ...

      Returns Promise<boolean>

    publicseek

    • seek(position: number): void
    • Move to a position in seconds, the track is paused until the next play()


      Parameters

      • position: number

      Returns void

    publicstop

    • stop(): void
    • Returns void