natiny_audio_source_set_attenuation
C
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 |
NATINY_AUDIO_ATTENUATION_* constant |
min_distance |
float |
Distance at which attenuation begins |
max_distance |
float |
Distance beyond which gain stops changing |
rolloff |
float |
Attenuation strength |
Example
C
natiny_audio_source_set_attenuation(source, NATINY_AUDIO_ATTENUATION_LINEAR,
1.0f, 8.0f, 1.0f);
Notes
- With distance
d clamped between min_distance and max_distance, the
models calculate gain as follows:
| Constant |
Gain |
NATINY_AUDIO_ATTENUATION_NONE |
1 |
NATINY_AUDIO_ATTENUATION_INVERSE |
min / (min + rolloff * (d - min)) |
NATINY_AUDIO_ATTENUATION_LINEAR |
max(0, 1 - rolloff * (d - min) / (max - min)) |
NATINY_AUDIO_ATTENUATION_EXPONENTIAL |
(d / min) ^ -rolloff |
min_distance is clamped to at least 0.0001f, max_distance to at least
min_distance, and rolloff to at least 0.0f.
- An unknown model uses inverse attenuation. Non-spatial sources ignore these
settings.