跳转到内容

AudioAPI

此内容尚不支持你的语言。

Defined in: audio/Audio.ts:62

new AudioAPI(backend, mixer?): AudioAPI

Defined in: audio/Audio.ts:97

PlatformAudioBackend

AudioMixer | null

AudioAPI

baseUrl: string = ''

Defined in: audio/Audio.ts:95

get bufferBudget(): number

Defined in: audio/Audio.ts:110

The effective warm-cache byte budget: an explicit override, else the live RuntimeConfig.audioCacheBudget (so build-config changes apply without plumbing). 0 disables the warm cache — a buffer is freed the moment its refCount reaches 0.

number

dispose(): void

Defined in: audio/Audio.ts:600

void


ensureBus(name, parent?): boolean

Defined in: audio/Audio.ts:542

Ensure a named bus exists (creating it under parent ?? master). False on backends without a mixer graph.

string

string

boolean


getBufferHandle(url): AudioBufferHandle | undefined

Defined in: audio/Audio.ts:589

string

AudioBufferHandle | undefined


getBufferStats(): AudioBufferStats

Defined in: audio/Audio.ts:184

Buffer residency counters — the observability side of the budget.

AudioBufferStats


getBusDucking(target): BusDuckRule | null

Defined in: audio/Audio.ts:580

string

BusDuckRule | null


getBusEffects(busName): BusEffectDef[]

Defined in: audio/Audio.ts:570

string

BusEffectDef[]


getBusVolume(busName): number

Defined in: audio/Audio.ts:468

Unity (1) for an unknown bus.

string

number


getMasterVolume(): number

Defined in: audio/Audio.ts:451

Mixerless backends (WeChat/Null) report unity volume and unmuted — the read-side mirror of the volume setters’ silent no-op there.

number


getMusicVolume(): number

Defined in: audio/Audio.ts:455

number


getSFXVolume(): number

Defined in: audio/Audio.ts:459

number


getSpectrum(out): boolean

Defined in: audio/Audio.ts:596

Fill out with the master output’s frequency spectrum (0-255 per bin, low→high) for visualizers. Returns false on backends without analysis (e.g. WeChat) — callers should treat that as silence.

Uint8Array

boolean


getUIVolume(): number

Defined in: audio/Audio.ts:463

number


invalidateBuffer(url): boolean

Defined in: audio/Audio.ts:159

Drop a buffer whose source bytes changed (hot reload) so no future play or load serves stale audio. Safe while sounds are playing — live sources keep their own reference to the decoded data; only the cache entry goes, and the next play/load re-fetches fresh bytes. Returns true if the url was cached.

string

boolean


isBusMuted(busName): boolean

Defined in: audio/Audio.ts:473

string

boolean


muteBus(busName, muted): void

Defined in: audio/Audio.ts:529

string

boolean

void


playBGM(url, config?): void

Defined in: audio/Audio.ts:350

string

number

number

number

void


playSFX(url, config?): AudioHandle

Defined in: audio/Audio.ts:320

string

number

number

number

number

AudioHandle


playTrack(url, config?): Promise<AudioHandle | null>

Defined in: audio/Audio.ts:306

Play a fully-RESOLVED clip URL on an explicit bus (created on demand under master). Unlike playSFX/playBGM this applies no ref resolution — the caller already holds the final URL (the video system’s audio track derives it from the resolved video source). Null when the clip can’t load; loaded buffers share the residency cache.

string

PlayConfig = {}

Promise<AudioHandle | null>


preload(url): Promise<void>

Defined in: audio/Audio.ts:280

string

Promise<void>


preloadAll(urls): Promise<void>

Defined in: audio/Audio.ts:291

string[]

Promise<void>


preloadFromData(url, data): Promise<void>

Defined in: audio/Audio.ts:295

string

ArrayBuffer

Promise<void>


releaseBuffer(url): void

Defined in: audio/Audio.ts:139

Unpin a buffer. At refCount 0 it becomes an evictable warm-cache entry (bounded by bufferBudget) — still instantly playable and revivable by retainBuffer — or is freed outright when the budget is 0.

string

void


retainBuffer(url): boolean

Defined in: audio/Audio.ts:125

Pin a cached buffer: refCount + 1 (reviving an evictable entry back to held). Returns false on a miss — the caller must load and re-acquire. Every retain needs a matching releaseBuffer.

string

boolean


setAssetResolver(resolver): void

Defined in: audio/Audio.ts:236

(url) => ArrayBuffer | null

void


setBufferBudget(bytes): void

Defined in: audio/Audio.ts:115

Override the warm-cache byte budget; null returns to RuntimeConfig.

number | null

void


setBusDucking(target, rule): boolean

Defined in: audio/Audio.ts:576

Install (or clear with null) sidechain ducking on target — e.g. duck ‘music’ to 30% while ‘voice’ carries signal.

string

BusDuckRule | null

boolean


setBusEffects(busName, effects): boolean

Defined in: audio/Audio.ts:563

Replace a bus’s DSP insert chain. No-op (false) on backends without a WebAudio graph (WeChat/Null) — same degradation as the volume APIs.

string

BusEffectDef[]

boolean


setBusVolume(busName, volume): void

Defined in: audio/Audio.ts:550

string

number

void


setMasterVolume(volume): void

Defined in: audio/Audio.ts:417

number

void


setMusicVolume(volume): void

Defined in: audio/Audio.ts:425

number

void


setRefResolver(resolver): void

Defined in: audio/Audio.ts:247

Route play refs through the realm’s single asset resolver — the same channel every other asset type resolves through (uuid manifest, cooked logical→staged maps, project base). Takes precedence over the legacy baseUrl prefix, so playSFX('assets/…') works in cooked builds whose content-addressed staging renamed the physical files.

((ref) => string) | null

void


setSFXVolume(volume): void

Defined in: audio/Audio.ts:433

number

void


setUIVolume(volume): void

Defined in: audio/Audio.ts:441

number

void


stopAll(): void

Defined in: audio/Audio.ts:396

void


stopBGM(fadeOut?): void

Defined in: audio/Audio.ts:404

number

void


trimBufferCache(): number

Defined in: audio/Audio.ts:171

Free every evictable warm-cache buffer now (memory pressure). Held buffers and the budget are untouched; the cache refills as buffers are released afterwards. Returns the number of buffers freed.

number


updateDucking(): void

Defined in: audio/Audio.ts:585

Advance duck envelopes (driven per-frame by AudioUpdateSystem).

void


updateFades(dt): void

Defined in: audio/Audio.ts:621

Advance every fade by dt seconds — called once a frame by the audio system, which is what makes a fade the game’s clock rather than the browser’s: it pauses when the game does, and it exists on a device.

number

void