/** * Public type declarations for the audio module. Kept in a dedicated * file so the runtime entry point (`audio.ts`) stays focused on * implementation; consumers can import types from * `me.audio` exactly as before. */ /** * Sound asset descriptor passed to `audio.load`. * @category Audio */ export interface SoundAsset { /** Logical name used to play / stop / reference the sound later. */ name: string; /** * Base path / prefix for the audio resource. The loader builds the * full URL as `${src}${name}.${ext}` for each format configured by * `audio.init()`, so `src` is typically a directory ending in `/`. * Data URLs (`data:audio/...`) are used as-is and skip the prefix * + extension construction. */ src: string; /** * Named regions within a single file, each `[start, duration]` in * milliseconds, with an optional third element marking the region as * looping. Lets one download carry many effects. * @example * ```js * loader.preload([{ * type: "audio", name: "sfx", src: "data/sfx/", * sprite: { jump: [0, 450], hit: [2000, 250], music: [4000, 12000, true] }, * }]); * // then * audio.play("sfx", { sprite: "jump" }); * ``` */ sprite?: Record; /** * How many finished instances of this clip are kept around for reuse before * being discarded. Defaults to `5`. * * This does not limit how many instances can play at once — it trades * memory against the cost of recreating an instance for a clip that is * triggered rapidly. */ pool?: number; /** Initial playback rate, `0.5..4.0`. Defaults to `1.0`. */ rate?: number; /** Start muted. Defaults to `false`. */ mute?: boolean; /** * Whether to begin downloading on load. `"metadata"` fetches only enough to * report duration. Defaults to `true`. */ preload?: boolean | "metadata"; /** * Explicit format hint, for sources whose extension cannot be read from the * URL (a blob, or a URL without one). */ format?: string | string[]; /** * Lifecycle callbacks for this clip. Each is optional and fires for every * instance of the clip. */ on?: SoundEvents; /** Begin playback immediately on load. Defaults to `false`. */ autoplay?: boolean; /** Loop playback when the clip ends. Defaults to `false`. */ loop?: boolean; /** * Stream the resource instead of fully decoding upfront — preferred * for long music tracks. Defaults to `false`. */ stream?: boolean; /** * Force the HTML5 `