audio
Sound playback: play starts a node's sound component and returns a handle that is_playing takes; seek and skip move it, and the node's sound properties…
Sound playback: play starts a node's sound component and returns a handle that is_playing takes; seek and skip move it, and the node's sound properties change it as it plays. play_file plays a file on a node of its own, from a position heard from the listener when given one. A node's sound announces sound_finished (EVENT_SOUND_FINISHED) with the handle when it plays out. devices lists the outputs [audio] device can name.
19 functions, 1 constant. Scripts reach it as audio::.
Acts on sound: those functions are also methods on the component's handle, without the node argument.
Functions
Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.
| function | acts on | what it does |
|---|---|---|
bus_effects(string) -> audio::BusEffects? |
— | One bus's effects as [audio.buses] declares them, applied once to everything the bus mixes. Built when the output device opens, as the limiter is. Nil for a bus with none switched on. |
bus_limit(string) -> audio::BusLimit? |
— | One bus's limiter as [audio.buses] declares it. Nil for a bus with none. |
bus_volume_linear(string) -> float |
— | One bus's own gain, without its parents'. |
buses() -> [str] |
— | Every audio bus, declared in [audio.buses] or made by setting a volume, in name order. |
device_ready() -> bool |
— | Whether an output device is open. False on a page until the first gesture, and false for good with no sound card; playing before then hands out handles that make no sound. Recorded: a replay answers what its recording did, whatever the machine it runs on has. |
devices() -> [str] |
— | Every output device's name, as [audio] device takes it. Empty when the platform lists none. Recorded, as device_ready is. |
distance_gain(int) -> float? |
— | The gain the distance to the listener is costing a positional handle right now: 1 up close, 0 out of range. |
emitter_position(int) -> Vec3? |
— | Where a handle played with a position is; nil for a flat or unknown one. |
is_playing(int) -> bool |
— | Whether a handle's sound is still going: false once it plays out or is stopped, on the same tick with or without an output device. |
listener_position() -> Vec3 |
— | Where the ears are: the current listener node's world position, else the current camera's. |
pan(int) -> float? |
— | Where a positional handle sits between the speakers: -1 hard left, 0 centred, 1 hard right. |
play(Node) -> int |
sound |
Start the node's own sound from the top, replacing what it had going, and return the new handle. |
play_file(string, audio::PlayFileOptions?) -> Node |
— | Play a sound file on a node of its own under the scene's root, through bus at volume_linear and pitch_scale, looping when loop is true; a position places it, heard from the listener over min_distance to max_distance. Returns the node, which frees itself once the sound plays out: free it to stop the sound, or set its sound to change it. |
seek(Node, float) |
sound |
Jump the node's sound to seconds into the file it is playing; playback_time reads it back. A node with nothing playing is left alone. |
set_bus_volume_linear(string, float) |
— | Set one bus's gain and re-apply it to everything already playing on it: which is what a volume slider is. |
set_emitter_position(int, Vec3) |
— | Move what a handle plays from, so a sound follows something the script is driving; the frame takes its doppler from how far it moved. |
skip(Node) |
sound |
Move the node's sound on to the next file in its queue. Past the last one it has played out, and the node announces sound_finished. |
stop(Node) |
sound |
Silence what the node's sound started, over its fade_out_time; a node carrying none is left alone. |
stop_all() |
— | Silence everything at once and clear the playback every sound component was holding. |
Constants
| name | value |
|---|---|
EVENT_SOUND_FINISHED |
"sound_finished" |