natiny.audio.source_set_attenuation

Lua
natiny.audio.source_set_attenuation(source, model [, min_distance [, max_distance [, rolloff]]])

Sets distance attenuation for a spatial source.

Parameters

Name Type Default Description
source number Source handle
model integer Attenuation formula; one of the constants below
min_distance number 1.0 Distance at which attenuation begins; clamped to at least 0.0001
max_distance number 100.0 Distance beyond which gain stops changing; clamped to at least min_distance
rolloff number 1.0 Attenuation strength; clamped to at least 0.0

Constants

For the formulas below, d is the source distance clamped between min_distance and max_distance.

Constant Gain
natiny.audio.ATTENUATION_NONE 1
natiny.audio.ATTENUATION_INVERSE min_distance / (min_distance + rolloff * (d - min_distance))
natiny.audio.ATTENUATION_LINEAR max(0, 1 - rolloff * (d - min_distance) / (max_distance - min_distance))
natiny.audio.ATTENUATION_EXPONENTIAL (d / min_distance) ^ -rolloff

Example

Lua
natiny.audio.source_set_attenuation(source, natiny.audio.ATTENUATION_LINEAR,
                             1.0, 8.0, 1.0)