libdonut  2.3.2
Application framework for cross-platform game development in C++20
Classes | Enumerations
donut::audio Namespace Reference

Classes

struct  Error
 Exception type for domain-specific errors originating from the donut::audio module. More...
 
struct  Listener
 Current state of the sound listener, i.e. More...
 
struct  SoundOptions
 Configuration options for a Sound. More...
 
class  Sound
 Container for a particular sound wave that can be played in a SoundStage. More...
 
struct  SoundStageOptions
 Configuration options for a SoundStage. More...
 
class  SoundStage
 Persistent system for playing sound in a simulated 3D arena to the default audio device. More...
 

Enumerations

enum class  SoundAttenuationModel : unsigned { NO_ATTENUATION , INVERSE_DISTANCE , LINEAR_DISTANCE , EXPONENTIAL_DISTANCE }
 Distance attenuation/falloff model for 3D positional audio. More...
 

Enumeration Type Documentation

◆ SoundAttenuationModel

enum donut::audio::SoundAttenuationModel : unsigned
strong

Distance attenuation/falloff model for 3D positional audio.

Enumerator
NO_ATTENUATION 

No distance attenuation; sound has the same volume regardless of distance between the sound instance and the listener.

INVERSE_DISTANCE 

Attenuate the amplitude of the sound by the inverse distance between the sound instance and the listener according to the formula:

gain = dmin / (dmin + r * (clamp(d, dmin, dmax) - dmin))

where:

  • d is the linear distance between the sound instance and the listener,
  • dmin = minDistance,
  • dmax = maxDistance,
  • r = rolloffFactor.
Note
When using this attenuation model, it is recommended to use a rolloffFactor greater than or equal to 1.
Warning
When using this attenuation model:
  • minDistance must be less than or equal to maxDistance.
  • minDistance must be greater than 0.
  • rolloffFactor must be greater than 0.
LINEAR_DISTANCE 

Attenuate the amplitude of the sound by the linear distance between the sound instance and the listener according to the formula:

gain = 1 - r * (clamp(d, dmin, dmax) - dmin) / (dmax - dmin)

where:

  • d is the linear distance between the sound instance and the listener,
  • dmin = minDistance,
  • dmax = maxDistance,
  • r = rolloffFactor.
Warning
When using this attenuation model:
  • minDistance must be less than or equal to maxDistance.
  • rolloffFactor must be between 0 and 1 (inclusive).
EXPONENTIAL_DISTANCE 

Attenuate the amplitude of the sound by the exponential distance between the sound instance and the listener according to the formula:

gain = pow(clamp(d, dmin, dmax) / dmin, -r)

where:

  • d is the linear distance between the sound instance and the listener,
  • dmin = minDistance,
  • dmax = maxDistance,
  • r = rolloffFactor.
Note
When using this attenuation model, it is recommended to use a rolloffFactor greater than or equal to 1.
Warning
When using this attenuation model:
  • minDistance must be less than or equal to maxDistance.
  • minDistance must be greater than 0.
  • rolloffFactor must be greater than 0.