svelte-audio-renderer

API

Everything is exported from svelte-audio-renderer. The rest is plain Web Audio.

setAudioContext

function setAudioContext(create: () => BaseAudioContext): void

Gives the audio components below this component a context. create is called once, by the first audio component that needs it, so a page that calls it stays safe to server-render. Call it during component initialisation, like setContext.

getAudioContext

function getAudioContext(): BaseAudioContext

Returns the context in any component below setAudioContext, creating it on first use. It throws if no parent called setAudioContext.

audioNode

function audioNode<T extends AudioNode>(
	callback: (node: T) => void | (() => void)
): Attachment

An attachment for {@attach} that calls callback with the element's real AudioNode. A function it returns runs when the element is removed. See Direct node access.

createRoot

function createRoot(options: { context: BaseAudioContext }): TreeNode

A target for mount(), without a page. Its children connect to the context's destination. See Offline rendering.

renderer

import renderer from 'svelte-audio-renderer';
import { renderer } from 'svelte-audio-renderer';

The renderer itself, for mount(Component, { renderer, target }). It is also the default export, which customRenderer="svelte-audio-renderer" uses.

Types

import type {
	AudioElements,
	NodeAttributes,
	SourceAttributes,
	ConnectionAttributes,
	ScheduleAttributes,
	TreeNode
} from 'svelte-audio-renderer';
  • AudioElements: every tag and its attributes, used by svelte-check.
  • NodeAttributes<T>: the attributes of a node type.
  • SourceAttributes<T>: a source's attributes, with start and stop.
  • ConnectionAttributes: param, output and input.
  • ScheduleAttributes: start and stop.
  • TreeNode: an element in the renderer's tree.