|
Untitled
|
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. | |
All of the required structures for the AudioEmitter system.
| struct AudioPortal |
AudioPortals used for determining paths to transmit sound when emitter and listener are occluded.
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. |
| struct AudioEmitter |
An AudioEmitter that plays audio possibily from a certain position or at a certain time.
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. |
| #define MAX_AUDIO_EMITTERS 1024 |
The maximum amount of AudioEmitters.
Definition at line 37 of file engine_types.h.
Referenced by audio_update(), init_emitter(), init_globals(), process_sdl_event(), render(), render_audio_menu(), and update_audio_occlusion().
| #define MAX_AUDIO_EMITTERS_PER_ENTITY 24 |
How many AudioEmitters an entity can have attached.
Definition at line 38 of file engine_types.h.
| #define LPF_ORDER 2 |
Used for miniaudio low pass filters.
Definition at line 39 of file engine_types.h.
Swaps A and B.
Definition at line 511 of file audio.c.
References heap_swap().
Referenced by heap_pop(), heap_push(), and heap_swap().
| void heap_push | ( | Vector * | h | ) |
After a node has been pushed to the top of the stack, we reorder by f score.
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().
Pops the bottommost root off of the OpenNode Vector and then places the topmost node onto the bottom and resorts.
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().
| void reconstruct_path_aportal | ( | AStarWorkspace * | WS, |
| int | start, | ||
| int | end ) |
Traverses the AStarStateStack and backtracks to find the entire path.
| WS | The AStarWorkspace that conducted the search. |
| start | The beginning index of the portal path. |
| end | The 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().
| int a_star_aportal | ( | AStarWorkspace * | WS, |
| int | start, | ||
| int | end ) |
Conducts AStar between a start and end point in AudioPortals.
| WS | The AStarWorkspace that conducted the search. |
| start | The beginning index of the portal path. |
| end | The end index of the portal path. |
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().
| float calculate_path_volume_equal_power | ( | float | path_distance, |
| float | min_distance, | ||
| float | max_distance ) |
Calculates volume over a path.
| path_distance | The total distance of the entire path. |
| min_distance | The minimum distance clamp. |
| max_distance | The maximum distance clamp. |
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().
| 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.
| listener_pos | The position of the Player. |
| closest_l | Closest AudioPortal to the player. |
| emitter_pos | The position of the AudioEmitter. |
| out_pos | Pointer to the position that will be filled in with the closest visible AudioPortal to the listener. |
| out_volume | Pointer to the out volume. |
| distance | Pointer to the entire distance of the resulting path. |
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().
| void update_audio_occlusion | ( | Player * | player | ) |
Raycasts from player to audio sources to determine occlusion and performs a star if necessary.
| player | The player |
<The maximum amount of AudioEmitters
Definition at line 1791 of file audio.c.
References AUDIO_EMITTERS, AudioEmitter::base_volume, calculate_path_volume_equal_power(), AudioEmitter::current_distance, AudioEmitter::current_volume, find_closest_visible_aportal(), AudioEmitter::free, hit, RayHit::hit, AudioEmitter::is_occludable, MAX_AUDIO_EMITTERS, Skeleton::neck, pathfind_audio_occlusion(), player, AudioEmitter::pos, Spring::pos, raycast_scene(), Player::skeleton, AudioEmitter::sound_obj, RayHit::t, update_audio_occlusion(), vec3_length(), vec3_normalize(), vec3_sub(), AudioEmitter::virtual_pos, vec3::x, vec3::y, and vec3::z.
Referenced by main(), and update_audio_occlusion().
| int find_closest_visible_aportal | ( | vec3 | pos | ) |
Finds the closest audio portal for a star to travel through.
| pos | The position to search from. |
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().
| void recalculate_audio_portal_paths | ( | ) |
Recalculates the adjacency map of portals between each other.
Definition at line 418 of file audio.c.
References AudioPortal::adjacent_portals, Globals::audio_portals, Vector::buffer, CAST_VEC, Vector::count, GLOBALS, hit, RayHit::hit, init_vector(), AudioPortal::pos, PRINT_VEC3N, raycast_scene(), recalculate_audio_portal_paths(), RayHit::t, vec3_length(), vec3_scale(), vec3_sub(), and vector_expand().
Referenced by recalculate_audio_portal_paths(), and render_audio_menu().
| void init_new_audio_portal | ( | vec3 | pos | ) |
Creates an audio portal by expanding the vector.
| pos | The 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().
| void remove_audio_portal | ( | int | id | ) |
Removes an audio portal from the vector.
| id | The 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().
| 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.
| filepath | The file to open. |
| is_loop | If the sound is a loop. |
| is_occludable | If the sound should be muffled or occluded through walls. |
| base_volume | The overall volume of the sound. |
<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().
| void load_emitter | ( | AudioEmitter * | emitter, |
| const char * | filepath, | ||
| bool | is_loop, | ||
| bool | is_occludable, | ||
| float | base_volume ) |
Loads an existing emitter into miniaudio.
| emitter | The emitter to load. |
| filepath | The file to open. |
| is_loop | If the sound is a loop. |
| is_occludable | If the sound should be muffled or occluded through walls. |
| base_volume | The 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().
| void play_emitter | ( | AudioEmitter * | emitter, |
| vec3 | pos ) |
Starts playing an emitter.
| emitter | The emitter to play. |
| pos | The 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().
| void end_emitter | ( | AudioEmitter * | e | ) |
Stops playing an emitter.
| e | The 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().
| void audio_update | ( | Player * | player | ) |
Spatializes the audio from the player's position.
Used after determining audio occlusion.
| player | The 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().
| void unload_emitter | ( | int | id | ) |
Unloads an emitter from miniaudio.
| id | The 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().
| void destroy_emitter | ( | int | id | ) |
Unloads an emitter from miniaudio and frees the emitter as well.
| id | The 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().