Untitled
Loading...
Searching...
No Matches
Audio System

All of the required structures for the AudioEmitter system. More...

Data Structures

struct  AudioPortal
 AudioPortals used for determining paths to transmit sound when emitter and listener are occluded. More...
struct  AudioEmitter
 An AudioEmitter that plays audio possibily from a certain position or at a certain time. More...

Macros

#define MAX_AUDIO_EMITTERS   1024
 The maximum amount of AudioEmitters.
#define MAX_AUDIO_EMITTERS_PER_ENTITY   24
 How many AudioEmitters an entity can have attached.
#define LPF_ORDER   2
 Used for miniaudio low pass filters.

Functions

void heap_swap (OpenNode *a, OpenNode *b)
 Swaps A and B.
void heap_push (Vector *h)
 After a node has been pushed to the top of the stack, we reorder by f score.
OpenNode heap_pop (Vector *h)
 Pops the bottommost root off of the OpenNode Vector and then places the topmost node onto the bottom and resorts.
void reconstruct_path_aportal (AStarWorkspace *WS, int start, int end)
 Traverses the AStarStateStack and backtracks to find the entire path.
int a_star_aportal (AStarWorkspace *WS, int start, int end)
 Conducts AStar between a start and end point in AudioPortals.
float calculate_path_volume_equal_power (float path_distance, float min_distance, float max_distance)
 Calculates volume over a path.
bool pathfind_audio_occlusion (vec3 listener_pos, int closest_l, vec3 emitter_pos, vec3 *out_pos, float *out_volume, float *distance)
 Finds closest AudioPortal to the AudioEmitter and calls AStar to pathfind, then calulcates the volume.
void update_audio_occlusion (Player *player)
 Raycasts from player to audio sources to determine occlusion and performs a star if necessary.
int find_closest_visible_aportal (vec3 pos)
 Finds the closest audio portal for a star to travel through.
void recalculate_audio_portal_paths ()
 Recalculates the adjacency map of portals between each other.
void init_new_audio_portal (vec3 pos)
 Creates an audio portal by expanding the vector.
void remove_audio_portal (int id)
 Removes an audio portal from the vector.
AudioEmitter * init_emitter (const char *filepath, bool is_loop, bool is_occludable, float base_volume)
 Initialized an audio emitter and sets up its audio object in miniaudio.
void load_emitter (AudioEmitter *emitter, const char *filepath, bool is_loop, bool is_occludable, float base_volume)
 Loads an existing emitter into miniaudio.
void play_emitter (AudioEmitter *emitter, vec3 pos)
 Starts playing an emitter.
void end_emitter (AudioEmitter *e)
 Stops playing an emitter.
void audio_update (Player *player)
 Spatializes the audio from the player's position.
void unload_emitter (int id)
 Unloads an emitter from miniaudio.
void destroy_emitter (int id)
 Unloads an emitter from miniaudio and frees the emitter as well.

Detailed Description

All of the required structures for the AudioEmitter system.


Data Structure Documentation

◆ AudioPortal

struct AudioPortal

AudioPortals used for determining paths to transmit sound when emitter and listener are occluded.

Remarks
Located in Globals.audio_portals
See also
GLOBALS

Definition at line 397 of file engine_types.h.

Data Fields
vec3 pos The position of the AudioPortal.
Vector adjacent_portals int - Vector of AudioPortals that can be seen from this one.

◆ AudioEmitter

struct AudioEmitter

An AudioEmitter that plays audio possibily from a certain position or at a certain time.

See also
audio/audio.c
AUDIO_EMITTERS

Definition at line 530 of file engine_types.h.

Data Fields
char path[256] The path to the sound.
uint32_t id The static ID of the AudioEmitter inside of AUDIO_EMITTERS.
ma_sound sound_obj The miniaudio sound obj.
ma_lpf_node lpf_node The low pass filter for this emitter.
float current_cutoff The current low pass cutoff.
float base_volume The starting volume.
float current_volume The current volume.
float current_distance The current distance from listener.
vec3 pos The position of the AudioEmitter .
vec3 virtual_pos The position that we spatialize the emitter at (for example: at the corner instead of behind the wall).
bool is_loaded If the emitter is loaded in miniaudio.
bool is_occludable If the AudioEmitter can be occluded and needs to go through the AudioPortal system.
bool is_loop If the AudioEmitter loops.
bool free Indicates if this AudioEmitter is empty or can be replaced.

Macro Definition Documentation

◆ MAX_AUDIO_EMITTERS

#define MAX_AUDIO_EMITTERS   1024

◆ MAX_AUDIO_EMITTERS_PER_ENTITY

#define MAX_AUDIO_EMITTERS_PER_ENTITY   24

How many AudioEmitters an entity can have attached.

Definition at line 38 of file engine_types.h.

◆ LPF_ORDER

#define LPF_ORDER   2

Used for miniaudio low pass filters.

Definition at line 39 of file engine_types.h.

Function Documentation

◆ heap_swap()

void heap_swap ( OpenNode * a,
OpenNode * b )

Swaps A and B.

Definition at line 511 of file audio.c.

References heap_swap().

Referenced by heap_pop(), heap_push(), and heap_swap().

◆ heap_push()

void heap_push ( Vector * h)

After a node has been pushed to the top of the stack, we reorder by f score.

Parameters
hThe OpenNode Vector.

Definition at line 515 of file audio.c.

References CAST_VEC, Vector::count, heap_push(), and heap_swap().

Referenced by a_star_aportal(), and heap_push().

◆ heap_pop()

OpenNode heap_pop ( Vector * h)

Pops the bottommost root off of the OpenNode Vector and then places the topmost node onto the bottom and resorts.

Parameters
hThe OpenNode Vector.
Returns
The root node.

Definition at line 527 of file audio.c.

References CAST_VEC, Vector::count, heap_pop(), and heap_swap().

Referenced by a_star_aportal(), and heap_pop().

◆ reconstruct_path_aportal()

void reconstruct_path_aportal ( AStarWorkspace * WS,
int start,
int end )

Traverses the AStarStateStack and backtracks to find the entire path.

Warning
MAX_PORTALS may cause issues with larger paths.
High Priority Todo
The prev index here looks very suspicious, it should not be tied to end, as end should be an index into the array of portals.
Parameters
WSThe AStarWorkspace that conducted the search.
startThe beginning index of the portal path.
endThe end index of the portal path.

<The maximum amount of portals that are allocated to AStarWorkspace.path

<The maximum amount of portals that are allocated to AStarWorkspace.path

Definition at line 545 of file audio.c.

References AStarStateStack::came_from, MAX_PORTALS, AStarWorkspace::path, AStarWorkspace::path_count, reconstruct_path_aportal(), and AStarWorkspace::stack.

Referenced by a_star_aportal(), and reconstruct_path_aportal().

◆ a_star_aportal()

int a_star_aportal ( AStarWorkspace * WS,
int start,
int end )

Conducts AStar between a start and end point in AudioPortals.

Parameters
WSThe AStarWorkspace that conducted the search.
startThe beginning index of the portal path.
endThe end index of the portal path.
Returns
End of the portal path if found. -1 if none found.
Note
Returns -1 if none found.

Definition at line 576 of file audio.c.

References a_star_aportal(), AudioPortal::adjacent_portals, Globals::audio_portals, Vector::buffer, AStarStateStack::came_from, CAST_VEC, Vector::count, AStarWorkspace::current_run, AStarStateStack::f, OpenNode::f, AStarStateStack::g, OpenNode::g, GLOBALS, heap_pop(), heap_push(), OpenNode::i, init_vector(), AStarWorkspace::min_heap, OpenNode::parent, AStarWorkspace::path_count, AudioPortal::pos, reconstruct_path_aportal(), AStarStateStack::run_id, AStarWorkspace::stack, vec3_length(), vec3_sub(), and vector_expand().

Referenced by a_star_aportal(), and pathfind_audio_occlusion().

◆ calculate_path_volume_equal_power()

float calculate_path_volume_equal_power ( float path_distance,
float min_distance,
float max_distance )

Calculates volume over a path.

Parameters
path_distanceThe total distance of the entire path.
min_distanceThe minimum distance clamp.
max_distanceThe maximum distance clamp.
Returns
The volume.

Definition at line 650 of file audio.c.

References calculate_path_volume_equal_power().

Referenced by calculate_path_volume_equal_power(), pathfind_audio_occlusion(), and update_audio_occlusion().

◆ pathfind_audio_occlusion()

bool pathfind_audio_occlusion ( vec3 listener_pos,
int closest_l,
vec3 emitter_pos,
vec3 * out_pos,
float * out_volume,
float * distance )

Finds closest AudioPortal to the AudioEmitter and calls AStar to pathfind, then calulcates the volume.

See also
Globals.audio_portals
Parameters
listener_posThe position of the Player.
closest_lClosest AudioPortal to the player.
emitter_posThe position of the AudioEmitter.
out_posPointer to the position that will be filled in with the closest visible AudioPortal to the listener.
out_volumePointer to the out volume.
distancePointer to the entire distance of the resulting path.
Returns
If path was found.

Definition at line 661 of file audio.c.

References a_star_aportal(), Globals::audio_portals, AW, calculate_path_volume_equal_power(), CAST_VEC, end_timer(), find_closest_visible_aportal(), GLOBALS, hit, RayHit::hit, AStarWorkspace::path, AStarWorkspace::path_count, pathfind_audio_occlusion(), AudioPortal::pos, raycast_scene(), start_timer(), RayHit::t, vec3_length(), vec3_scale(), and vec3_sub().

Referenced by pathfind_audio_occlusion(), and update_audio_occlusion().

◆ update_audio_occlusion()

◆ find_closest_visible_aportal()

int find_closest_visible_aportal ( vec3 pos)

Finds the closest audio portal for a star to travel through.

Parameters
posThe position to search from.
Returns
Index of the closest portal.

Definition at line 475 of file audio.c.

References Globals::audio_portals, CAST_VEC, Vector::count, find_closest_visible_aportal(), GLOBALS, hit, RayHit::hit, AudioPortal::pos, raycast_scene(), RayHit::t, vec3_length(), vec3_scale(), and vec3_sub().

Referenced by find_closest_visible_aportal(), pathfind_audio_occlusion(), and update_audio_occlusion().

◆ recalculate_audio_portal_paths()

◆ init_new_audio_portal()

void init_new_audio_portal ( vec3 pos)

Creates an audio portal by expanding the vector.

Parameters
posThe position of the portal

Definition at line 737 of file audio.c.

References AudioPortal::adjacent_portals, Globals::audio_portals, GLOBALS, init_new_audio_portal(), init_vector(), AudioPortal::pos, and vector_expand().

Referenced by init_new_audio_portal(), and render_audio_menu().

◆ remove_audio_portal()

void remove_audio_portal ( int id)

Removes an audio portal from the vector.

Parameters
idThe id to remove.

Definition at line 745 of file audio.c.

References AudioPortal::adjacent_portals, Globals::audio_portals, Vector::buffer, CAST_VEC, GLOBALS, remove_audio_portal(), and REMOVE_FROM_VEC.

Referenced by execute_aportal_undo(), remove_audio_portal(), and render_audio_menu().

◆ init_emitter()

AudioEmitter * init_emitter ( const char * filepath,
bool is_loop,
bool is_occludable,
float base_volume )

Initialized an audio emitter and sets up its audio object in miniaudio.

Parameters
filepathThe file to open.
is_loopIf the sound is a loop.
is_occludableIf the sound should be muffled or occluded through walls.
base_volumeThe overall volume of the sound.
Returns
Pointer to the new emitter.

<The maximum amount of AudioEmitters

Definition at line 814 of file audio.c.

References AUDIO_EMITTERS, AudioEmitter::free, init_emitter(), load_emitter(), and MAX_AUDIO_EMITTERS.

Referenced by init(), init_emitter(), and render_audio_menu().

◆ load_emitter()

void load_emitter ( AudioEmitter * emitter,
const char * filepath,
bool is_loop,
bool is_occludable,
float base_volume )

Loads an existing emitter into miniaudio.

Parameters
emitterThe emitter to load.
filepathThe file to open.
is_loopIf the sound is a loop.
is_occludableIf the sound should be muffled or occluded through walls.
base_volumeThe overall volume of the sound.

Definition at line 759 of file audio.c.

References AUDIO_ENGINE, AudioEmitter::base_volume, CONVOLVER_NODE, AudioEmitter::current_cutoff, AudioEmitter::is_loaded, AudioEmitter::is_loop, AudioEmitter::is_occludable, load_emitter(), AudioEmitter::path, and AudioEmitter::sound_obj.

Referenced by execute_aemitter_undo(), init_emitter(), load_emitter(), and render_audio_menu().

◆ play_emitter()

void play_emitter ( AudioEmitter * emitter,
vec3 pos )

Starts playing an emitter.

Parameters
emitterThe emitter to play.
posThe position to play the emitter at.

Definition at line 853 of file audio.c.

References AudioEmitter::is_loaded, AudioEmitter::is_loop, play_emitter(), AudioEmitter::pos, AudioEmitter::sound_obj, vec3::x, vec3::y, and vec3::z.

Referenced by execute_aemitter_undo(), init(), play_emitter(), render_audio_menu(), and update_leg().

◆ end_emitter()

void end_emitter ( AudioEmitter * e)

Stops playing an emitter.

Parameters
eThe emitter to stop.

Definition at line 881 of file audio.c.

References end_emitter(), and AudioEmitter::sound_obj.

Referenced by end_emitter(), execute_aemitter_undo(), and render_audio_menu().

◆ audio_update()

void audio_update ( Player * player)

Spatializes the audio from the player's position.

Used after determining audio occlusion.

Parameters
playerThe player to update audio for.

<The maximum amount of AudioEmitters

Definition at line 886 of file audio.c.

References AUDIO_EMITTERS, AUDIO_ENGINE, audio_update(), Player::cam, AudioEmitter::current_volume, Camera::forward, AudioEmitter::free, MAX_AUDIO_EMITTERS, Skeleton::neck, player, Spring::pos, Player::skeleton, AudioEmitter::sound_obj, Camera::up, AudioEmitter::virtual_pos, vec3::x, vec3::y, and vec3::z.

Referenced by audio_update(), and main().

◆ unload_emitter()

void unload_emitter ( int id)

Unloads an emitter from miniaudio.

Parameters
idThe emitter to unload.

Definition at line 831 of file audio.c.

References AUDIO_EMITTERS, AudioEmitter::is_loaded, AudioEmitter::sound_obj, and unload_emitter().

Referenced by execute_aemitter_undo(), and unload_emitter().

◆ destroy_emitter()

void destroy_emitter ( int id)

Unloads an emitter from miniaudio and frees the emitter as well.

Parameters
idThe emitter to destroy.

Definition at line 841 of file audio.c.

References AUDIO_EMITTERS, destroy_emitter(), AudioEmitter::free, and AudioEmitter::sound_obj.

Referenced by destroy_emitter(), execute_aemitter_undo(), and render_audio_menu().