Skip to content

Documentation / @debuffjp/audio / Audio

Class: Audio ​

Defined in: index.ts:50

Constructors ​

Constructor ​

new Audio(): Audio

Defined in: index.ts:57

Returns ​

Audio

Properties ​

ctx ​

readonly ctx: AudioContext

Defined in: index.ts:51

Accessors ​

unlocked ​

Get Signature ​

get unlocked(): boolean

Defined in: index.ts:81

Returns ​

boolean

Methods ​

buffer() ​

buffer(id): AudioBuffer | undefined

Defined in: index.ts:95

A decoded sound, to play through your own nodes (a positional audio plugin, say).

Parameters ​

id ​

string

Returns ​

AudioBuffer | undefined


bus() ​

bus(name): GainNode

Defined in: index.ts:77

A bus's gain node, to plug other audio in (a music generator such as plonk: new Player({ context: audio.ctx, destination: audio.bus("music") })), so it shares the game's volume and mute.

Parameters ​

name ​

Bus

Returns ​

GainNode


decode() ​

decode(id, data): Promise<void>

Defined in: index.ts:85

Parameters ​

id ​

string

data ​

ArrayBuffer

Returns ​

Promise<void>


has() ​

has(id): boolean

Defined in: index.ts:90

Parameters ​

id ​

string

Returns ​

boolean


play() ​

play(id, options?): Voice

Defined in: index.ts:99

Parameters ​

id ​

string

options? ​

PlayOptions = {}

Returns ​

Voice


stream() ​

stream(url, options?): Stream

Defined in: index.ts:161

Stream a long track (music, ambience) through an <audio> element into a bus. Unlike play, it isn't decoded into memory up front, so it starts immediately and stays light on mobile. If audio is still locked by the browser's autoplay policy, playback starts on the first gesture.

Parameters ​

url ​

string

options? ​

StreamOptions = {}

Returns ​

Stream


synth() ​

synth(o): Voice

Defined in: index.ts:123

Synthesize a short blip/zap/hit without any asset: one oscillator with a pitch slide, for a placeholder until the game has its sound. For sound effects a game keeps, use plonk's player.sfx(instrument, { degree }), which plays in the song's key (see bus).

Parameters ​

o ​

SynthOptions

Returns ​

Voice


volume() ​

volume(bus, value): void

Defined in: index.ts:232

Parameters ​

bus ​

Bus | "master"

value ​

number

Returns ​

void