natiny.audio.create_source

Lua
natiny.audio.create_source(clip) -> source

Creates a stopped sound-source entity that plays a clip.

Parameters

Name Type Description
clip number Clip handle whose samples this source plays

Returns

Type Description
number Source handle, also usable as an entity handle

Example

Lua
local source = natiny.audio.create_source(clip)

Notes

  • The source does not own the clip or its decoded samples. Multiple sources can share one clip; destroying the source leaves the clip intact.
  • Each source owns one playback voice. At most 256 sources can exist at once.
  • A source starts stopped, spatial, non-looping, at volume and pitch 1.0. Its attenuation defaults to ATTENUATION_INVERSE, distances 1.0 and 100.0, and rolloff 1.0.
  • The handle can be moved or parented with natiny.entity.
  • A source whose clip is destroyed plays nothing; it is not an error.
  • A nonzero invalid clip handle also creates a silent source. Lua rejects 0 as a clip handle.
  • Lua raises an error when the voice limit is exhausted or the source cannot be created.