Class Cacophony

Constructors

Properties

cache: ICache
context: BaseContext
createAudioWorkletNode: ((context, name, options?) => any)

Type declaration

    • (context, name, options?): any
    • Parameters

      • context: BaseContext
      • name: string
      • Optional options: AudioWorkletNodeOptions

      Returns any

eventEmitter: TypedEventEmitter<CacophonyEvents> = ...
finalizationRegistry: FinalizationRegistry<SoundCleanupHoldings>
globalGainNode: GainNode
listener: AudioListener
loadedAudioWorklets: Set<string> = ...
prevVolume: number = 1

Accessors

  • get isOffline(): boolean
  • Returns true if this instance is backed by an offline audio context (i.e., the context has a startRendering method).

    Returns boolean

Methods

  • Creates a Group containing Sound instances loaded from multiple URLs.

    Parameters

    • urls: string[]

      Array of URL strings to load as sounds

    • soundType: SoundType = SoundType.Buffer

      Type of sound (Buffer, HTML, Streaming)

    • panType: PanType = "HRTF"

      Type of panning (HRTF or stereo)

    • Optional signal: AbortSignal

      Optional AbortSignal to cancel the operation

    Returns Promise<Group>

    Promise that resolves to a Group containing all loaded sounds

  • Creates a PannerNode with the specified options.

    Parameters

    • options: Partial<PannerOptions>

      An object containing the options to use when creating the PannerNode.

    Returns PannerNode

    A new PannerNode instance with the specified options.

    Example

    const panner = audio.createPanner({
    positionX: 0,
    positionY: 0,
    positionZ: 0,
    orientationX: 0,
    orientationY: 0,
    orientationZ: 0,
    });
  • Creates a Sound instance from an AudioBuffer or URL.

    Parameters

    • buffer: AudioBuffer
    • Optional soundType: SoundType

      Type of sound (Buffer, HTML, Streaming)

    • Optional panType: PanType

      Type of panning (HRTF or stereo)

    • Optional signal: AbortSignal

      Optional AbortSignal to cancel the operation

    Returns Promise<Sound>

    Promise that resolves to a Sound instance

  • Parameters

    • url: string
    • Optional soundType: SoundType
    • Optional panType: PanType
    • Optional signal: AbortSignal

    Returns Promise<Sound>

  • Creates a streaming Sound instance from a URL.

    Parameters

    • url: string

      URL string to stream audio from

    • Optional signal: AbortSignal

      Optional AbortSignal to cancel the operation

    Returns Promise<Sound>

    Promise that resolves to a Sound instance for streaming

  • Returns Promise<MicrophoneStream>

  • Parameters

    • name: string
    • url: string
    • Optional signal: AbortSignal

    Returns Promise<void>

  • Parameters

    • Optional signal: AbortSignal

    Returns Promise<void>

  • Parameters

    • Optional signal: AbortSignal

    Returns Promise<void>

  • Register event listener.

    Type Parameters

    Parameters

    • event: K
    • listener: ((data) => void)

    Returns (() => void)

    Cleanup function

      • (): void
      • Returns void

  • Resumes the audio context. This method is required to resume the audio context on mobile devices. On desktop, the audio context will automatically resume when a sound is played.

    Returns void

  • Renders the offline audio graph to a buffer. Only available when the context has a startRendering method.

    Returns Promise<AudioBuffer>

    Promise that resolves to the rendered AudioBuffer

    Throws

    Error if the context does not support offline rendering

  • Internal

    Parameters

    • unregisterToken: object

    Returns void

  • Creates a Cacophony instance backed by an OfflineAudioContext. Use this for rendering, bouncing, precomputing processed output, or non-realtime scenarios.

    Parameters

    • options: OfflineOptions

      Offline context configuration (channels, length, sampleRate)

    • Optional cache: ICache

      Optional cache implementation

    Returns Cacophony

    A Cacophony instance backed by OfflineAudioContext