Skip to main content

FlixelTeaVMSoundHandler

View source

class

org.flixelgdx.backend.teavm.audio.FlixelTeaVMSoundHandler

public class FlixelTeaVMSoundHandler implements Factory

TeaVM/web implementation of Factory backed by the Web Audio API.

A single AudioContext and master GainNode are shared across all sounds. Both are created lazily on the first FlixelTeaVMSoundHandler.createSound(...) or FlixelTeaVMSoundHandler.prewarmSound(String) call to respect browser policies that require an active user gesture before audio can play.

Audio data is read synchronously from the virtual filesystem (which is fully preloaded before the game starts) and decoded asynchronously via AudioContext.decodeAudioData.

Decoded AudioBuffer objects are cached by path. Once a path has been decoded (either by a previous FlixelTeaVMSoundHandler.createSound(...) call or by an explicit FlixelTeaVMSoundHandler.prewarmSound(String) call), subsequent FlixelTeaVMSoundHandler.createSound(...) calls for that path use the cached buffer and start playback immediately with no decode lag. This is the mechanism that keeps multiple tracks started in the same frame in perfect sync without skipping into the audio.

Focus-based pause and resume are implemented via AudioContext.suspend() and AudioContext.resume(), which atomically halts or continues every active sound with no per-instance bookkeeping.

Groups are no-ops beyond triggering context-level suspend/resume: the Web Audio API does not expose per-group routing without a dedicated graph, and the engine's SFX and music groups are always paused and resumed together by FlixelSoundManager.

Audio-graph effects (ReverbNode, EchoNode, LowPassNode) are fully supported on web using native Web Audio API nodes. Reverb uses a ConvolverNode driven by a procedurally generated impulse response; echo uses a DelayNode with a feedback GainNode; low-pass uses a BiquadFilterNode.

Constructors

FlixelTeaVMSoundHandler()

public FlixelTeaVMSoundHandler()

Methods

createSound(String, short, Object, boolean)

public FlixelSoundBackend createSound(String path, short flags, Object group, boolean external)

prewarmSound(String)

public void prewarmSound(String path)

isPrewarmPending()

public boolean isPrewarmPending()

createGroup()

public Object createGroup()

disposeGroup(Object)

public void disposeGroup(Object group)

groupPause(Object)

public void groupPause(Object group)

groupPlay(Object)

public void groupPlay(Object group)

setMasterVolume(float)

public void setMasterVolume(float volume)

getMasterVolume()

public float getMasterVolume()

Returns the tracked master volume.

Returns: Master volume in [0, 1].


disposeEngine()

public void disposeEngine()

attachToEngineOutput(FlixelSoundBackend, int)

public void attachToEngineOutput(FlixelSoundBackend sound, int outputBusIndex)

attachEffectToEngineOutput(EffectNode, int)

public void attachEffectToEngineOutput(EffectNode node, int outputBusIndex)

createReverbNode(float)

public ReverbNode createReverbNode(float wet)

createDelayNode(float, float)

public EchoNode createDelayNode(float delaySeconds, float decay)

createLowPassFilter(double, int)

public LowPassNode createLowPassFilter(double cutoffHz, int order)