![]() |
RigsofRods
Soft-body Physics Simulation
|
#include <SoundManager.h>
Public Member Functions | |
SoundManager () | |
~SoundManager () | |
void | CleanUp () |
Cleans up various objects that should be reset when returning from a terrain to the main menu. More... | |
SoundPtr | createSound (Ogre::String filename, Ogre::String resource_group_name="") |
Ogre::Vector3 | GetListenerPosition () const |
Returns the position vector of the listener. More... | |
bool | ListenerIsUnderwater () const |
void | Update (const float dt) |
Does the per-frame update of sounds and listener environment. More... | |
void | UpdateGlobalDopplerFactor () const |
Updates the global Doppler factor based on CVar settings and the state of the physics simulation. More... | |
void | UpdateEfxSpecificProperties (const float dt) |
Updates properties of OpenAL facilities that are only available with EFX. More... | |
void | UpdateSourceSpecificDopplerFactor (const int hardware_index) const |
Identifies the actor to which the sound corresponding to a hardware source belongs and updates the Doppler factor based on CVar settings and the actor's physics sim state. More... | |
void | SetListener (Ogre::Vector3 position, Ogre::Vector3 direction, Ogre::Vector3 up, Ogre::Vector3 velocity) |
Sets position and speed of the listener. More... | |
void | pauseAllSounds () |
Unlike the name suggests, this sets the listener's gain to 0, essentially muting all sounds. More... | |
void | resumeAllSounds () |
Unlike the name suggests, this sets the listener's gain to the value of the CVar audio_master_volume. More... | |
void | setMasterVolume (float v) |
Updates both CVar audio_master_volume and the listener's gain to the provided value. More... | |
bool | isDisabled () |
float | GetSpeedOfSound () const |
void | SetSpeedOfSound (const float speed_of_sound) const |
Updates the speed of sound in OpenAL with the provided value. More... | |
float | GetDopplerFactor () const |
void | SetDopplerFactor (const float doppler_factor) const |
Updates the global Doppler factor in OpenAL with the provided value. More... | |
void | SetDopplerFactor (const ALuint hardware_source, const float doppler_factor) const |
Updates the Doppler factor of an OpenAL source with the provided value. More... | |
void | SetAirAbsorptionFactor (const float air_absorption_factor) |
Sets the air absorptions factor for the direct path of all sounds. More... | |
float | GetAirAbsorptionFactor () const |
int | getNumHardwareSources () |
Returns the number of currently used hardware sources. More... | |
const std::map< std::string, EFXEAXREVERBPROPERTIES > & | getEfxPropertiesMap () const |
Returns currently registered EFX presets. More... | |
const EFXEAXREVERBPROPERTIES * | GetEfxProperties (const std::string &efx_preset_name) const |
Returns a pointer to properties of an EFX preset stored in the EFX properties map. More... | |
const EFXEAXREVERBPROPERTIES * | GetReverbPresetAt (Ogre::Vector3 position) const |
Determines which reverb preset corresponds to the provided position and returns its properties. More... | |
Static Public Attributes | |
static const float | MAX_DISTANCE = 500.0f |
static const float | ROLLOFF_FACTOR = 1.0f |
static const float | REFERENCE_DISTANCE = 7.5f |
static const unsigned int | MAX_HARDWARE_SOURCES = 32 |
static const unsigned int | MAX_AUDIO_BUFFERS = 8192 |
Private Member Functions | |
void | UpdateAlListener () |
Updates the listener's position, orientation and velocity vectors in OpenAL. More... | |
void | UpdateListenerEnvironment () |
Determines several properties of the environment of the listener and updates OpenAL to use them. More... | |
void | recomputeAllSources () |
void | recomputeSource (int source_index, int reason, float vfl, Ogre::Vector3 *vvec) |
Computes audibility of an audio source and retires it if it is inaudible. More... | |
ALuint | getHardwareSource (int hardware_index) |
Returns the AL handle for the hardware source with the provided index. More... | |
void | assign (int source_index, int hardware_index) |
Adds an audio source to hardware source. More... | |
void | retire (int source_index) |
Stops and the removes an audio source from hardware source. More... | |
bool | loadWAVFile (Ogre::String filename, ALuint buffer, Ogre::String resource_group_name="") |
ALuint | CreateAlEffect (const EFXEAXREVERBPROPERTIES *efx_properties) const |
Creates an OpenAL effect based on the parameters of an efx/eax reverb preset. More... | |
void | DeleteAlEffect (const ALuint efx_effect_id) const |
Deletes an OpenAL effect. More... | |
void | PrepopulateEfxPropertiesMap () |
Helper function that fills the m_efx_properties_map with presets provided by OpenAL's efx-presets.h header. More... | |
void | UpdateListenerEffectSlot (const float dt) |
Dynamically adjusts some parameters of the currently active reverb preset based on the current environment of the listener. More... | |
void | SmoothlyUpdateAlAuxiliaryEffectSlot (const float dt, const ALuint slot_id, const EFXEAXREVERBPROPERTIES *target_efx_properties) |
This performs a smooth update of the efx properties of an OpenAL Auxiliary Effect slot using linear interpolation over several timesteps. More... | |
std::tuple< Ogre::Vector3, float, float > | ComputeEarlyReflectionsProperties () const |
Detects surfaces close to the listener and calculates a user-relative (as opposed to listener-relative) panning vector for early reflections as well as gain and delay values for early reflections based on surface distance. More... | |
void | UpdateSourceFilters (const int hardware_index) const |
Helper function to call several other functions to update source filters. More... | |
bool | IsHardwareSourceObstructed (const int hardware_index) const |
Performs various checks against the environment of the listener to determine whether the sound belonging to a hardware source is obstructed or not. More... | |
void | UpdateObstructionFilter (const int hardware_index, const bool enable_obstruction_filter) const |
Applies an obstruction filter to the provided hardware source. More... | |
bool | UpdateOcclusionFilter (const int hardware_index, const ALuint effect_slot_id, const EFXEAXREVERBPROPERTIES *reference_efx_reverb_properties) const |
Applies an occlusion filter to the provided source if certain conditions apply. More... | |
void | UpdateDirectedSounds () const |
Updates AL Cones for sources of directed sound emissions (exhausts, turboprops and turbojets). More... | |
void | UpdateConeProperties (const ALuint source, const Ogre::Vector3 &cone_direction, const float cone_inner_angle, const float cone_outer_angle, const float cone_outer_gain, const float cone_outer_gain_hf) const |
Updates the Cone properties for the hardware source. More... | |
Private Attributes | |
int | hardware_sources_num = 0 |
total number of allocated hardware sources (<= MAX_HARDWARE_SOURCES) More... | |
int | hardware_sources_in_use_count = 0 |
int | hardware_sources_map [MAX_HARDWARE_SOURCES] |
maps from the index of a hardware source to the index of the audio source currently assigned to the corresponding hardware source. -1 = unmapped More... | |
ALuint | hardware_sources [MAX_HARDWARE_SOURCES] |
int | m_audio_sources_in_use_count = 0 |
SoundPtr | audio_sources [MAX_AUDIO_BUFFERS] = { nullptr } |
std::pair< int, float > | audio_sources_most_audible [MAX_AUDIO_BUFFERS] |
int | audio_buffers_in_use_count = 0 |
ALuint | audio_buffers [MAX_AUDIO_BUFFERS] |
Ogre::String | audio_buffer_file_name [MAX_AUDIO_BUFFERS] |
bool | m_listener_is_underwater = false |
Ogre::Vector3 | m_listener_position = Ogre::Vector3::ZERO |
Ogre::Vector3 | m_listener_direction = Ogre::Vector3::ZERO |
Ogre::Vector3 | m_listener_up = Ogre::Vector3::ZERO |
Ogre::Vector3 | m_listener_velocity = Ogre::Vector3::ZERO |
ALCdevice * | audio_device = nullptr |
ALCcontext * | sound_context = nullptr |
bool | m_efx_is_available = false |
ALuint | m_listener_slot = 0 |
ALuint | m_efx_outdoor_obstruction_lowpass_filter_id = 0 |
ALuint | m_efx_occlusion_wet_path_send_id = 0 |
ALuint | m_efx_occlusion_wet_path_lowpass_filter_id = 0 |
float | m_air_absorption_factor = 1.0f |
EfxReverbEngine | m_efx_reverb_engine = EfxReverbEngine::NONE |
const EFXEAXREVERBPROPERTIES * | m_listener_efx_reverb_properties = nullptr |
std::map< std::string, EFXEAXREVERBPROPERTIES > | m_efx_properties_map |
std::map< ALuint, ALuint > | m_efx_effect_id_map |
LPALGENEFFECTS | alGenEffects = nullptr |
LPALDELETEEFFECTS | alDeleteEffects = nullptr |
LPALISEFFECT | alIsEffect = nullptr |
LPALEFFECTI | alEffecti = nullptr |
LPALEFFECTF | alEffectf = nullptr |
LPALEFFECTFV | alEffectfv = nullptr |
LPALGENFILTERS | alGenFilters = nullptr |
LPALDELETEFILTERS | alDeleteFilters = nullptr |
LPALISFILTER | alIsFilter = nullptr |
LPALFILTERI | alFilteri = nullptr |
LPALFILTERF | alFilterf = nullptr |
LPALGENAUXILIARYEFFECTSLOTS | alGenAuxiliaryEffectSlots = nullptr |
LPALDELETEAUXILIARYEFFECTSLOTS | alDeleteAuxiliaryEffectSlots = nullptr |
LPALISAUXILIARYEFFECTSLOT | alIsAuxiliaryEffectSlot = nullptr |
LPALAUXILIARYEFFECTSLOTI | alAuxiliaryEffectSloti = nullptr |
LPALAUXILIARYEFFECTSLOTF | alAuxiliaryEffectSlotf = nullptr |
LPALAUXILIARYEFFECTSLOTFV | alAuxiliaryEffectSlotfv = nullptr |
Friends | |
class | Sound |
Definition at line 53 of file SoundManager.h.
SoundManager::SoundManager | ( | ) |
SoundManager::~SoundManager | ( | ) |
Definition at line 253 of file SoundManager.cpp.
|
private |
Adds an audio source to hardware source.
source_index | Index of the audio source. |
hardware_index | Index of the hardware source to which the audio source will be assigned. |
Definition at line 1412 of file SoundManager.cpp.
void SoundManager::CleanUp | ( | ) |
Cleans up various objects that should be reset when returning from a terrain to the main menu.
Definition at line 293 of file SoundManager.cpp.
|
private |
Detects surfaces close to the listener and calculates a user-relative (as opposed to listener-relative) panning vector for early reflections as well as gain and delay values for early reflections based on surface distance.
Definition at line 738 of file SoundManager.cpp.
|
private |
Creates an OpenAL effect based on the parameters of an efx/eax reverb preset.
efx_properties | EFXEAXREVERBPROPERTIES object holding the parameters of the reverb preset. |
AL/efx-presets.h
from OpenAL Definition at line 854 of file SoundManager.cpp.
SoundPtr SoundManager::createSound | ( | Ogre::String | filename, |
Ogre::String | resource_group_name = "" |
||
) |
filename | WAV file. |
resource_group_name | Leave empty to auto-search all groups (classic behavior). |
Definition at line 1476 of file SoundManager.cpp.
|
private |
Deletes an OpenAL effect.
effect_id | ID of the effect targeted for removal. |
Definition at line 927 of file SoundManager.cpp.
|
inline |
Definition at line 174 of file SoundManager.h.
|
inline |
Definition at line 149 of file SoundManager.h.
const EFXEAXREVERBPROPERTIES * SoundManager::GetEfxProperties | ( | const std::string & | efx_preset_name | ) | const |
Returns a pointer to properties of an EFX preset stored in the EFX properties map.
The presets should not be modified directly so they can serve as a reference.
efx_preset_name | The name of the preset for which the properties shall be returned. |
Definition at line 313 of file SoundManager.cpp.
|
inline |
Returns currently registered EFX presets.
Definition at line 187 of file SoundManager.h.
|
inlineprivate |
Returns the AL handle for the hardware source with the provided index.
hardware_index | Index of the hardware source. |
Definition at line 239 of file SoundManager.h.
|
inline |
Returns the position vector of the listener.
Definition at line 75 of file SoundManager.h.
|
inline |
Returns the number of currently used hardware sources.
In a typical scenario, this value changes dynamically.
Definition at line 181 of file SoundManager.h.
const EFXEAXREVERBPROPERTIES * SoundManager::GetReverbPresetAt | ( | Ogre::Vector3 | position | ) | const |
Determines which reverb preset corresponds to the provided position and returns its properties.
position | Position for which the reverb preset of the encompassing environment will be returned. |
Definition at line 551 of file SoundManager.cpp.
|
inline |
Definition at line 137 of file SoundManager.h.
|
inline |
|
private |
Performs various checks against the environment of the listener to determine whether the sound belonging to a hardware source is obstructed or not.
hardware_index | The index of the hardware source. |
Definition at line 1012 of file SoundManager.cpp.
|
inline |
Definition at line 80 of file SoundManager.h.
|
private |
void SoundManager::pauseAllSounds | ( | ) |
Unlike the name suggests, this sets the listener's gain to 0, essentially muting all sounds.
Definition at line 1451 of file SoundManager.cpp.
|
private |
Helper function that fills the m_efx_properties_map with presets provided by OpenAL's efx-presets.h header.
Definition at line 327 of file SoundManager.cpp.
|
private |
|
private |
Computes audibility of an audio source and retires it if it is inaudible.
Otherwise, it updates its parameters (e.g. play/stop) if it is already assigned to a hardware source. If it was not assigned to a hardware source yet, it will either be assigned to a free slot or replace a less audible source if one exists.
Definition at line 1327 of file SoundManager.cpp.
void SoundManager::resumeAllSounds | ( | ) |
Unlike the name suggests, this sets the listener's gain to the value of the CVar audio_master_volume.
Definition at line 1459 of file SoundManager.cpp.
|
private |
Stops and the removes an audio source from hardware source.
source_index | The index of the audio source. |
Definition at line 1439 of file SoundManager.cpp.
|
inline |
Sets the air absorptions factor for the direct path of all sounds.
air_absorption_factor | Air absorption factor within the range of AL_AIR_ABSORPTION_FACTOR. |
Definition at line 169 of file SoundManager.h.
void SoundManager::SetDopplerFactor | ( | const ALuint | hardware_source, |
const float | doppler_factor | ||
) | const |
Updates the Doppler factor of an OpenAL source with the provided value.
EFX has to be supported and enabled, otherwise this is a no-op.
hardware_source | Index of the hardware source. |
doppler_factor | Doppler factor within the range of AL_DOPPLER_FACTOR. |
Definition at line 500 of file SoundManager.cpp.
|
inline |
Updates the global Doppler factor in OpenAL with the provided value.
doppler_factor | Doppler factor within the range of AL_DOPPLER_FACTOR. |
Definition at line 155 of file SoundManager.h.
void SoundManager::SetListener | ( | Ogre::Vector3 | position, |
Ogre::Vector3 | direction, | ||
Ogre::Vector3 | up, | ||
Ogre::Vector3 | velocity | ||
) |
Sets position and speed of the listener.
position | The position of the listener. |
direction | This direction vector specifies where the front of the listener is pointing to. |
up | This direction vector specifies where the top of the head of the listener is pointing to. |
velocity | The movement speed of the listener in each dimension. |
Definition at line 492 of file SoundManager.cpp.
void SoundManager::setMasterVolume | ( | float | v | ) |
Updates both CVar audio_master_volume and the listener's gain to the provided value.
v | Volume within the range of AL_GAIN. |
Definition at line 1467 of file SoundManager.cpp.
|
inline |
Updates the speed of sound in OpenAL with the provided value.
This value should based on RoR units for correct results.
speed_of_sound | Speed of sound within the range of AL_SPEED_OF_SOUND. |
Definition at line 144 of file SoundManager.h.
|
private |
This performs a smooth update of the efx properties of an OpenAL Auxiliary Effect slot using linear interpolation over several timesteps.
dt | Time since last frame in seconds |
slot_id | ID of the AuxiliaryEffectSlot which should be updated |
target_efx_properties | EFX Reverb properties to update to |
Definition at line 620 of file SoundManager.cpp.
void SoundManager::Update | ( | const float | dt | ) |
Does the per-frame update of sounds and listener environment.
With the help of other functions it determines and then submits the current state of the audio world to OpenAL.
dt | Time since last frame in seconds |
Definition at line 403 of file SoundManager.cpp.
|
private |
Updates the listener's position, orientation and velocity vectors in OpenAL.
Definition at line 534 of file SoundManager.cpp.
|
private |
Updates the Cone properties for the hardware source.
source | The AL source of which the cone properties will be modified. |
cone_direction | The direction the cone will face. |
cone_inner_angle | Angle for the inner zone. |
cone_outer_angle | Angle that marks the border between transitional and outside zone of the cone |
cone_outer_gain | Gain for the outside zone. |
cone_outer_gain_hf | High-frequency gain for the outside zone. |
Definition at line 1306 of file SoundManager.cpp.
|
private |
Updates AL Cones for sources of directed sound emissions (exhausts, turboprops and turbojets).
Definition at line 1160 of file SoundManager.cpp.
void SoundManager::UpdateEfxSpecificProperties | ( | const float | dt | ) |
Updates properties of OpenAL facilities that are only available with EFX.
dt | Time since last frame in seconds |
Definition at line 436 of file SoundManager.cpp.
void SoundManager::UpdateGlobalDopplerFactor | ( | ) | const |
Updates the global Doppler factor based on CVar settings and the state of the physics simulation.
Definition at line 418 of file SoundManager.cpp.
|
private |
Dynamically adjusts some parameters of the currently active reverb preset based on the current environment of the listener.
It works on the AL effect correspondig to a reverb preset, i.e. the original preset in m_efx_properties_map remains unchanged. Finally, it updates the AL listener's effect slot with the adjusted preset.
dt | Time since last frame in seconds |
Definition at line 593 of file SoundManager.cpp.
|
private |
Determines several properties of the environment of the listener and updates OpenAL to use them.
Definition at line 505 of file SoundManager.cpp.
|
private |
Applies an obstruction filter to the provided hardware source.
hardware_index | The index of the hardware source. |
enable_obstruction_filter | Whether the obstruction filter should be enabled for the hardware source or not. |
Definition at line 1121 of file SoundManager.cpp.
|
private |
Applies an occlusion filter to the provided source if certain conditions apply.
To decide whether the filter should be applied or not, the function checks whether the reverb preset of the sound differs from that provided as a parameter.
hardware_index | The index of the hardware source. |
effect_slot_id | The id of the AL effect slot that will be used as a send target |
reference_efx_reverb_properties | The reverb preset that the reverb preset of the sound location is compared against |
Definition at line 1134 of file SoundManager.cpp.
|
private |
Helper function to call several other functions to update source filters.
hardware_index | The index of the hardware source. |
Definition at line 989 of file SoundManager.cpp.
void SoundManager::UpdateSourceSpecificDopplerFactor | ( | const int | hardware_index | ) | const |
Identifies the actor to which the sound corresponding to a hardware source belongs and updates the Doppler factor based on CVar settings and the actor's physics sim state.
hardware_index | Index of the hardware source. |
Definition at line 458 of file SoundManager.cpp.
|
friend |
Definition at line 55 of file SoundManager.h.
|
private |
Definition at line 308 of file SoundManager.h.
|
private |
Definition at line 309 of file SoundManager.h.
|
private |
Definition at line 307 of file SoundManager.h.
|
private |
Definition at line 305 of file SoundManager.h.
|
private |
Definition at line 294 of file SoundManager.h.
|
private |
Definition at line 300 of file SoundManager.h.
|
private |
Definition at line 297 of file SoundManager.h.
|
private |
Definition at line 298 of file SoundManager.h.
|
private |
Definition at line 296 of file SoundManager.h.
|
private |
Definition at line 303 of file SoundManager.h.
|
private |
Definition at line 302 of file SoundManager.h.
|
private |
Definition at line 304 of file SoundManager.h.
|
private |
Definition at line 293 of file SoundManager.h.
|
private |
Definition at line 299 of file SoundManager.h.
|
private |
Definition at line 306 of file SoundManager.h.
|
private |
Definition at line 295 of file SoundManager.h.
|
private |
Definition at line 301 of file SoundManager.h.
|
private |
Definition at line 271 of file SoundManager.h.
|
private |
Definition at line 270 of file SoundManager.h.
|
private |
Definition at line 269 of file SoundManager.h.
|
private |
Definition at line 279 of file SoundManager.h.
|
private |
Definition at line 264 of file SoundManager.h.
|
private |
Definition at line 266 of file SoundManager.h.
|
private |
Definition at line 260 of file SoundManager.h.
|
private |
Definition at line 258 of file SoundManager.h.
|
private |
maps from the index of a hardware source to the index of the audio source currently assigned to the corresponding hardware source. -1 = unmapped
Definition at line 259 of file SoundManager.h.
|
private |
total number of allocated hardware sources (<= MAX_HARDWARE_SOURCES)
Definition at line 257 of file SoundManager.h.
|
private |
Definition at line 288 of file SoundManager.h.
|
private |
Definition at line 263 of file SoundManager.h.
|
private |
Definition at line 292 of file SoundManager.h.
|
private |
Definition at line 283 of file SoundManager.h.
|
private |
Definition at line 287 of file SoundManager.h.
|
private |
Definition at line 286 of file SoundManager.h.
|
private |
Definition at line 285 of file SoundManager.h.
|
private |
Definition at line 291 of file SoundManager.h.
|
private |
Definition at line 289 of file SoundManager.h.
|
private |
Definition at line 275 of file SoundManager.h.
|
private |
Definition at line 290 of file SoundManager.h.
|
private |
Definition at line 273 of file SoundManager.h.
|
private |
Definition at line 274 of file SoundManager.h.
|
private |
Definition at line 284 of file SoundManager.h.
|
private |
Definition at line 276 of file SoundManager.h.
|
private |
Definition at line 277 of file SoundManager.h.
|
static |
Definition at line 208 of file SoundManager.h.
|
static |
Definition at line 204 of file SoundManager.h.
|
static |
Definition at line 207 of file SoundManager.h.
|
static |
Definition at line 206 of file SoundManager.h.
|
static |
Definition at line 205 of file SoundManager.h.
|
private |
Definition at line 280 of file SoundManager.h.