natiny_audio_source_set_attenuation
void natiny_audio_source_set_attenuation(
NatinyAudioSource source,
uint32_t model,
float min_distance,
float max_distance,
float rolloff
);
Sets distance attenuation for a spatial source.
Parameters
| Name | Type | Description |
|---|---|---|
source |
NatinyAudioSource |
Source handle |
model |
uint32_t |
Attenuation formula; one of the constants below |
min_distance |
float |
Distance at which attenuation begins; clamped to at least 0.0001f |
max_distance |
float |
Distance beyond which gain stops changing; clamped to at least min_distance |
rolloff |
float |
Attenuation strength; clamped to at least 0.0f |
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
natiny_audio_source_set_attenuation(source, NATINY_AUDIO_ATTENUATION_LINEAR,
1.0f, 8.0f, 1.0f);