cacophony
    Preparing search index...

    Class Sound

    The base interface for any sound-producing entity, including individual sounds, groups, and playbacks. BaseSound

    Hierarchy

    • RoutableSource
      • Sound

    Implements

    Index
    • Parameters

      • url: string
      • buffer: AudioBuffer | undefined
      • context: BaseContext
      • globalGainNode: GainNode
      • soundType: SoundType = "buffer"
      • panType: PanType = "HRTF"
      • Optional_cacophony: Cacophony
      • OptionalpreparedMediaElement: HTMLAudioElement
      • Optional_preparedMediaElementCleanup: () => void
      • Optionalregion: Readonly<SpriteRegion>

        Immutable atlas bounds for a region-backed Sound.

      • OptionalspriteName: string

        Original sprite key, retained by clones for attribution.

      Returns Sound

    _filters: BiquadFilterNode[] = []
    _position: Position
    _routeTarget: Bus | null = null

    Primary route target. null is the canonical master route.

    _sends: Map<Bus, number> = ...

    Additional send target to gain-value mappings.

    _stereoPan: number
    _threeDOptions: ThreeDOptions
    _volume: number
    buffer?: AudioBuffer
    context: BaseContext
    globalGainNode: GainNode
    loopCount: LoopCount = 0
    panType: PanType = "HRTF"
    playbacks: Playback[]
    region?: Readonly<SpriteRegion>

    Immutable atlas bounds for a region-backed Sound.

    soundType: SoundType = "buffer"
    spriteName?: string

    Original sprite key, retained by clones for attribution.

    streamCapabilities?: StreamCapabilities
    url: string
    • get duration(): number

      Retrieves the duration of the sound in seconds. If the sound is based on an AudioBuffer, it returns the duration of the buffer. Otherwise, if the sound has not been played and is a MediaElementSource, it returns NaN, indicating that the duration is unknown or not applicable.

      Returns number

      The duration of the sound in seconds.

    • get playbackRate(): number

      Returns number

    • set playbackRate(rate: number): void

      Parameters

      • rate: number

      Returns void

    • get stereoPan(): number

      Returns number

    • set stereoPan(value: number): void

      Parameters

      • value: number

      Returns void

    • Called by Bus.drainTo to move this source off the draining bus onto target. The source reroutes its primary route and/or any send that targeted bus.

      Parameters

      Returns void

    • Materialize all declared recipes, then establish this playback's sends.

      Parameters

      • playback: BasePlayback

      Returns void

    • Resolve the node used by future playbacks for their primary output. Sources left on a subsequently destroyed bus fall back to master.

      Returns GainNode

    • Establish every configured send on a newly created playback.

      Parameters

      • playback: BasePlayback

      Returns void

    • Returns void

    • Clones the current Sound instance, creating a deep copy with the option to override specific properties. This method allows for the creation of a new, independent Sound instance based on the current one, with the flexibility to modify certain attributes through the overrides parameter. This is particularly useful for creating variations of a sound without affecting the original instance. The cloned instance includes all properties, playback settings, and filters of the original, unless explicitly overridden.

      Parameters

      • overrides: Partial<SoundCloneOverrides> = {}

        An object specifying properties to override in the cloned instance. This can include audio settings like volume, playback rate, and spatial positioning, as well as more complex configurations like 3D audio options and filter adjustments.

      Returns Sound

    • Type Parameters

      • K extends (keyof BaseAudioEvents) | "soundError" | "loopEnd" | "rateChange"

      Parameters

      Returns void

    • Type Parameters

      • K extends (keyof BaseAudioEvents) | "soundError" | "loopEnd" | "rateChange"

      Parameters

      Returns Promise<void>

    • Parameters

      • value: number
      • duration: number
      • Optionaltype: FadeType

      Returns Promise<void>

    • Sets or retrieves the loop behavior for the sound. If loopCount is provided, the sound will loop the specified number of times. If loopCount is 'infinite', the sound will loop indefinitely until stopped. If no argument is provided, the method returns the current loop count setting.

      Parameters

      • OptionalloopCount: LoopCount

        The number of times to loop or 'infinite' for indefinite looping.

      Returns LoopCount

      The current loop count setting if no argument is provided.

    • Remove event listener.

      Type Parameters

      • K extends (keyof BaseAudioEvents) | "soundError" | "loopEnd" | "rateChange"

      Parameters

      Returns void

    • Register event listener.

      Type Parameters

      • K extends (keyof BaseAudioEvents) | "soundError" | "loopEnd" | "rateChange"

      Parameters

      Returns () => void

      Cleanup function

    • Generates a Playback instance for the sound without starting playback. This allows for pre-configuration of playback properties such as volume and position before the sound is actually played.

      Returns Playback[]

    • Routes a media-loader failure through the Sound's existing typed event system. Used by optional media transports after the Sound has loaded.

      Parameters

      • error: Error
      • recoverable: boolean

      Returns void

    • Route this source to a bus, or add an independent send when sendGain is provided.

      Parameters

      • target: string | Bus
      • OptionalsendGain: number

      Returns void

    • Seeks to a specific time within the sound's playback.

      Parameters

      • time: number

        The time in seconds to seek to. This method iterates through all active Playback instances and calls their seek() method with the specified time.

      Returns void

    • Pitch-shifts every live playback of this Sound, resurrecting the dormant phase-vocoder worklet (Jean Laroche & Mark Dolson, 1999 IEEE WASPAA — peak-based pitch shift with Identity Phase-Locking). Mirrors how playbackRate fans a per-playback control out across this.playbacks. The factor is also stored so future playbacks pick it up at preplay.

      Parameters

      • factor: number

        Pitch multiplier (> 0; 2 = +1 octave, 0.5 = -1 octave).

      Returns Promise<void>

      Resolves once every live playback's worklet node has been built and its pitchFactor param updated.

    • OFFLINE independent time-stretch: produce a NEW buffer-based Sound whose tempo is changed by factor WITHOUT changing pitch (Phase Gradient Heap Integration, Průša & Holighaus, "Phase Vocoder Done Right", EUSIPCO 2017 / arXiv:2202.07382). factor > 1 is slower/longer, factor < 1 is faster/shorter. Only valid for buffer-based sounds (a loaded AudioBuffer); streaming / media-element sounds have no decoded buffer to transform.

      The original Sound is left untouched; a fresh Sound wrapping the stretched buffer is returned. Delegates to Cacophony.timeStretchBuffer.

      Parameters

      • factor: number

        Stretch factor (> 0); pitch is preserved.

      • Optionaloptions: TimeStretchOptions

        Optional PGHI parameters (fftSize, analysisHop, tol, seed).

      Returns Sound

      A new buffer-based Sound at the stretched tempo.

      If this Sound has no AudioBuffer (e.g. streaming/HTML5 audio).