Audio
Backend interface for audio operations.
This interface defines the contract that all backend implementations (Clay, Unity, Headless, Web)
must fulfill to provide audio functionality in Ceramic. It handles loading, playback control,
real-time effects, and bus management.
The audio system uses a bus-based architecture where sounds can be routed to different buses
(0-7) for group control and effects processing.
Instance Members
Loads an audio file from the specified path.
Name |
Type |
Default |
Description |
path |
String |
|
The path to the audio file (relative to assets directory) |
options |
Null<backend.LoadAudioOptions> |
(optional) |
Optional loading configuration (streaming, format hints, etc.) |
done |
Function |
|
Callback invoked with the loaded AudioResource or null on failure |
Creates an audio resource from raw PCM sample data.
Name |
Type |
Description |
buffer |
backend.Float32Array |
The raw audio sample data as 32-bit floats (-1.0 to 1.0 range) |
samples |
Int |
The total number of samples in the buffer |
channels |
Int |
The number of audio channels (1 for mono, 2 for stereo) |
sampleRate |
Float |
The sample rate in Hz (e.g., 44100, 48000) |
interleaved |
Bool |
Whether samples are interleaved (L,R,L,R) or planar (L,L,L...,R,R,R) |
supportsHotReloadPath(): Bool
Checks if the backend supports hot-reloading of audio files.
When true, the audio system can detect file changes and reload automatically.
Returns |
Description |
Bool |
True if hot-reload is supported, false otherwise |
Gets the duration of an audio resource in seconds.
Returns |
Description |
Float |
The duration in seconds, or -1 if unknown (e.g., for streams) |
resumeAudioContext(done: Function): Void
Resumes the audio context after user interaction.
This is required on web platforms where audio contexts start suspended
until user interaction occurs (click, touch, etc.).
Name |
Type |
Description |
done |
Function |
Callback invoked with true on success, false on failure |
Destroys an audio resource and frees its memory.
After calling this, the AudioResource should not be used.
Creates a muted audio handle without actually playing the sound.
Useful for pre-allocating handles or silent placeholders.
Returns |
Description |
backend.AudioHandle |
A muted AudioHandle that can be controlled like a playing sound |
Plays an audio resource with the specified parameters.
Name |
Type |
Default |
Description |
audio |
backend.AudioResource |
|
The audio resource to play |
volume |
Float |
0.5 |
The playback volume (0.0 to 1.0, default 0.5) |
pan |
Float |
0 |
The stereo panning (-1.0 for left, 0.0 for center, 1.0 for right) |
pitch |
Float |
1 |
The playback pitch/speed multiplier (1.0 is normal speed) |
position |
Float |
0 |
The starting position in seconds |
loop |
Bool |
false |
Whether to loop playback when reaching the end |
bus |
Int |
0 |
The audio bus to route this sound through (0-7) |
Pauses playback of an audio handle.
The sound can be resumed from the same position with resume().
Resumes playback of a paused audio handle.
Playback continues from where it was paused.
Stops playback of an audio handle.
Unlike pause, this cannot be resumed - the handle becomes invalid.
Gets the current volume of an audio handle.
Returns |
Description |
Float |
The current volume (0.0 to 1.0) |
Sets the volume of an audio handle.
Gets the current stereo panning of an audio handle.
Returns |
Description |
Float |
The current pan value (-1.0 for left, 0.0 for center, 1.0 for right) |
Sets the stereo panning of an audio handle.
Name |
Type |
Description |
handle |
backend.AudioHandle |
The audio handle to modify |
pan |
Float |
The new pan value (-1.0 for left, 0.0 for center, 1.0 for right) |
Gets the current pitch/speed multiplier of an audio handle.
Returns |
Description |
Float |
The current pitch multiplier (1.0 is normal speed) |
Sets the pitch/speed multiplier of an audio handle.
This affects both pitch and playback speed proportionally.
Name |
Type |
Description |
handle |
backend.AudioHandle |
The audio handle to modify |
pitch |
Float |
The new pitch multiplier (0.5 = half speed/octave down, 2.0 = double speed/octave up) |
Gets the current playback position of an audio handle.
Returns |
Description |
Float |
The current position in seconds |
Sets the playback position of an audio handle.
Adds an audio filter to a bus for real-time effects processing.
Filters are processed in the order they are added.
Name |
Type |
Description |
bus |
Int |
The audio bus number (0-7) to add the filter to |
filter |
ceramic.AudioFilter |
The AudioFilter instance to add (e.g., LowPassFilter, HighPassFilter) |
onReady |
Function |
Callback invoked when the filter is ready to process audio |
Removes an audio filter from a bus.
Name |
Type |
Description |
bus |
Int |
The audio bus number (0-7) to remove the filter from |
filterId |
Int |
The ID of the filter to remove (from AudioFilter.id) |
filterParamsChanged(bus: Int, filterId: Int): Void
Notifies the backend that a filter's parameters have changed.
This allows the backend to update real-time processing accordingly.
Name |
Type |
Description |
bus |
Int |
The audio bus number (0-7) containing the filter |
filterId |
Int |
The ID of the filter whose parameters changed |