8#include "SDL2/SDL_mutex.h"
9#include "SDL2/SDL_thread.h"
13#include "miniaudio/miniaudio.h"
282static void extract_t60(
float * edc_db,
AudioProbe * probe,
int band,
float bin_duration_seconds,
int last_sample);
412#define SAMPLE_IDX(i, sh, b) \
413 (((i) * SH_MAX * AUDIO_NUM_BANDS) + ((sh) * AUDIO_NUM_BANDS) + (b)) \
415#define Y_00 0.28209479177387814f
465 printf(
"Portal %d Adjacent to %d\n", i, adj[j]);
473#define APORTAL_VISIBILITY_RADIUS 1.0f
479 float closest_dist = INFINITY;
480 int closest_index = -1;
498 if (closest_dist > dist)
506 return closest_index;
512 OpenNode tmp = *a; *a = *b; *b = tmp;
516 int i = h->
count - 1;
520 int parent = (i - 1) / 2;
521 if (buf[parent].f <= buf[i].f)
break;
531 buf[0] = buf[--h->
count];
534 int left = 2*i + 1, right = 2*i + 2, smallest = i;
535 if (left < h->count && buf[left].f < buf[smallest].f) smallest = left;
536 if (right < h->count && buf[right].f < buf[smallest].f) smallest = right;
537 if (smallest == i)
break;
549 while (current != start)
557 printf(
"NO PARENT %d\n", current);
564 for (
int i = 0; i < WS->
path_count / 2; i++) {
565 int tmp = WS->
path[i];
591 start_node->
i = start;
594 WS->
stack[start].
g = 0.0f;
605 if (current.
i == end)
617 int neighbor = adj[i];
619 AudioPortal * neighbor_portal = &portals[neighbor];
621 float old_g = WS->
stack[neighbor].
g;
624 if (!did_search || tenative_g < old_g)
629 neighbor_node->
i = neighbor;
630 neighbor_node->
g = tenative_g;
631 neighbor_node->
f = f;
632 neighbor_node->
parent = current.
i;
635 WS->
stack[neighbor].
f = f;
636 WS->
stack[neighbor].
g = tenative_g;
651 if (path_distance <= min_distance)
return 1.0f;
652 if (path_distance >= max_distance)
return 0.0f;
654 float norm = (path_distance - min_distance) / (max_distance - min_distance);
655 float linear_factor = 1.0f - norm;
657 return linear_factor * linear_factor;
670 if (closest_l == -1 || closest_e == -1)
return false;
687 int final_path_pos = 0;
688 int actual_path_start = 0;
704 final_path_pos =
AW.
path[i];
705 actual_path_start = i;
712 for (
int i = actual_path_start; i <
AW.
path_count-1; i++)
720 if (final_path_pos < 0)
722 printf(
"Somehow the final path pos was less than zero which means that the original aportal thats visible is not visible.\n");
726 *out_pos = portals[final_path_pos].
pos;
729 double res_time2 =
end_timer(&res_timer);
761 ma_sound_config sound_config = ma_sound_config_init();
763 sound_config.pFilePath = filepath;
764 sound_config.channelsIn = 1;
765 sound_config.channelsOut = 0;
767 ma_result res = ma_sound_init_from_file(&
AUDIO_ENGINE, filepath, 0, NULL, NULL, &emitter->
sound_obj);
769 if (res != MA_SUCCESS)
777 strcpy(emitter->
path, filepath);
778 ma_uint32 channels = ma_engine_get_channels(&
AUDIO_ENGINE);
779 ma_uint32 sampleRate = ma_engine_get_sample_rate(&
AUDIO_ENGINE);
783 if (res2 != MA_SUCCESS)
785 printf(
"COULDNT BIND\n");
786 if (res2 == MA_INVALID_OPERATION)
792 ma_sound_set_spatialization_enabled(&emitter->
sound_obj, MA_TRUE);
826 load_emitter(emitter, filepath, is_loop, is_occludable, base_volume);
827 emitter->
free =
false;
858 ma_sound_set_position(&emitter->
sound_obj, pos.
x, pos.
y, pos.
z);
862 if (ma_sound_is_looping(&emitter->
sound_obj))
869 ma_sound_set_looping(&emitter->
sound_obj, MA_TRUE);
875 ma_sound_seek_to_pcm_frame(&emitter->
sound_obj, 0);
883 ma_sound_seek_to_pcm_frame(&e->
sound_obj, 0);
895 if (emitter->
free)
continue;
896 if (!ma_sound_is_playing(&emitter->
sound_obj))
continue;
901 ma_sound_set_min_distance(&emitter->
sound_obj, 100000.0f);
902 ma_sound_set_max_distance(&emitter->
sound_obj, 100000.0f);
910 ma_engine* pEngine = (ma_engine*)pUserData;
912 ma_uint64 frames_to_read = len / (
sizeof(float) * 2);
913 memset(pStream, 0, len);
915 ma_engine_read_pcm_frames(pEngine, pStream, frames_to_read, NULL);
934 *out_local = pv_index;
1004 if (current == -1)
return;
1006 bool loaded =
false;
1023 float farthest_dist = -INFINITY;
1024 int farthest_index = -1;
1038 if (dist > farthest_dist)
1041 farthest_dist = dist;
1047 empty = farthest_index;
1060 apv->
pv_id = current;
1104 float weight_sum = 0.0f;
1135 for (
int z = -1; z <= 1; z++)
1136 for (
int y = -1; y <= 1; y++)
1137 for (
int x = -1; x <= 1; x++)
1140 int idx_x = local.
x + x;
1141 int idx_y = local.
y + y;
1142 int idx_z = local.
z + z;
1143 if (idx_x < 0 || idx_x >= pv->
resolution.
x)
continue;
1144 if (idx_y < 0 || idx_y >= pv->
resolution.
y)
continue;
1145 if (idx_z < 0 || idx_z >= pv->
resolution.
z)
continue;
1147 ivec3 probe_local = {local.
x + x, local.
y + y, local.
z + z};
1161 float w = 1.0f / powf(dist + 0.05f, 2.0f);
1175 float lowest_w = INFINITY;
1179 if (
weights.weights[i] < lowest_w)
1181 lowest_w =
weights.weights[i];
1189 weights.probes[lowest] = current_index;
1190 weight_sum -=
weights.weights[lowest];
1198 float inv_w = 1.0f / weight_sum;
1234 float out_sample = (filter->
b0 * in_sample
1235 + filter->
b1 * filter->
x1
1236 + filter->
b2 * filter->
x2
1237 - filter->
a1 * filter->
y1
1238 - filter->
a2 * filter->
y2) ;
1240 filter->
x2 = filter->
x1;
1241 filter->
x1 = in_sample;
1242 filter->
y2 = filter->
y1;
1243 filter->
y1 = out_sample;
1252 memset(filter, 0,
sizeof(
Biquad));
1253 float w0 = 2.0f *
M_PI * center_freq / sample_rate;
1254 float alpha = sinf(w0) / (2.0f * q);
1256 float a0 = 1.0f + alpha;
1258 filter->
b0 = alpha / a0;
1260 filter->
b2 = -alpha / a0;
1261 filter->
a1 = -2.0f * cosf(w0) / a0;
1262 filter->
a2 = (1.0f - alpha) / a0;
1274 const float RT60_DECAY_CONST = -6.907755278982137f;
1283 decay[b] = expf(RT60_DECAY_CONST / rt60_samples);
1289 float unit_noise_scaler = 1.0f / 0.577350269f;
1293 float raw = ((float)
rand() / RAND_MAX) * 2.0f - 1.0f;
1294 raw *= unit_noise_scaler;
1295 float combined = 0.0f;
1301 envelope[b] *= decay[b];
1304 out_tail[i] = combined;
1314 float accumulated_energy = 0.0f;
1317 accumulated_energy += energy_histogram[i];
1318 edc_out[i] = accumulated_energy;
1321 float max_energy = edc_out[0];
1323 if (max_energy <= 0.0f) max_energy = 1e-12f;
1327 if (edc_out[i] > 0.0f) {
1329 edc_out[i] = 10.0f * log10f(edc_out[i] / max_energy);
1333 edc_out[i] = -120.0f;
1345 int start = fade_start - window_size;
1348 for (
int i = start; i < fade_start; i++)
1356 return (sqrtf(sum / count));
1368 for (
int i = 0; i < last_sample; i++) {
1369 if (start_idx == -1 && edc_db[i] <= -5.0f) {
1372 if (end_idx == -1 && edc_db[i] <= -35.0f) {
1378 if (start_idx == -1 || end_idx == -1) {
1379 probe->
rt60[band] = 0.0f;
1380 probe->
slope[band] = 0.0f;
1384 float sum_x = 0.0f, sum_y = 0.0f, sum_xy = 0.0f, sum_xx = 0.0f;
1385 for (
int i = start_idx; i <= end_idx; i++) {
1386 float x = i * bin_duration_seconds;
1387 float y = edc_db[i];
1395 int n = end_idx - start_idx + 1;
1396 float denominator = (
n * sum_xx) - (sum_x * sum_x);
1400 if (denominator != 0.0f) {
1401 slope = ((
n * sum_xy) - (sum_x * sum_y)) / denominator;
1403 t60 = -60.0f / slope;
1405 probe->
rt60[band] = t60;
1406 probe->
slope[band] = slope;
1415 int BOUNCE_SSBO_SIZE = count * MAX_SAMPLES_PER_PROBE;
1419 glGenBuffers(1, &bounce_ssbo);
1420 glBindBuffer(GL_SHADER_STORAGE_BUFFER, bounce_ssbo);
1421 glBufferStorage(GL_SHADER_STORAGE_BUFFER,
sizeof(
AudioSampleGPU) * BOUNCE_SSBO_SIZE, samples_init_data, GL_MAP_READ_BIT);
1422 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10, bounce_ssbo);
1423 free(samples_init_data);
1427 const int AUDIO_BATCHES = 256;
1445 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
1451 double gpu_time =
end_timer(&gpu_timer);
1459 glBindBuffer(GL_SHADER_STORAGE_BUFFER, bounce_ssbo);
1460 AudioSampleGPU * asample_gpu = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);
1463 printf(
"NO SAMPLES\n");
1485 for (
int i = 0; i < count; i++)
1512 if (!sample->
valid)
continue;
1514 int i0 = (int)floorf(sample_index);
1515 float frac = sample_index - (float)i0;
1524 for (
int sh = 0; sh <
SH_MAX; sh++)
1534 if (edc_sample_index < 0 || edc_sample_index >=
MAX_EDC_SAMPLES)
continue;
1537 edc_in[band][edc_sample_index] += sample->
abs_energy[band] * norm;
1538 if (edc_sample_index > last_sample[band])
1540 last_sample[band] = edc_sample_index;
1556 if (last <= 0)
continue;
1563 int fade_start = 800;
1564 int fade_end = 1200;
1570 for (
int k = 0; k < last; k++)
1572 int bin_center_sample = k;
1574 if (
rand() % 2 == 0) sign = -1;
1579 if (sh0_energy <= 0.000001f)
continue;
1581 float total_energy = sh0_energy /
Y_00;
1583 float band_amplitude = sqrtf(total_energy) * sign;
1587 for (
int sh = 0; sh <
SH_MAX; sh++)
1595 if (target_sample < 0)
continue;
1596 if (target_sample >= last)
break;
1598 float filtered_sample =
BAND_IMPULSES[b][m] * band_amplitude;
1600 for (
int sh = 0; sh <
SH_MAX; sh++)
1602 aprobe->
final_ir[target_sample][sh] += filtered_sample * sh_ratios[sh];
1612 for (
int i = fade_start; i < last; i++)
1617 alpha = (float)(i - fade_start) / (fade_end - fade_start);
1621 float er = cosf(alpha * 0.5 *
M_PI);
1622 float lr = sinf(alpha * 0.5 *
M_PI);
1624 aprobe->
final_ir[i][0] = (aprobe->
final_ir[i][0] * er) + (late_reverb[i] * lr);
1626 for (
int sh = 1; sh <
SH_MAX; sh++)
1629 float sh_decorrelated_noise = (((float)
rand() / (float)RAND_MAX) * 2.0f - 1.0f) * 0.2f;
1630 float late_sh = late_reverb[i] * sh_decorrelated_noise;
1653 glDeleteBuffers(1, &bounce_ssbo);
1654 double cpu_time =
end_timer(&cpu_timer);
1656 printf(
"CPU: %f GPU: %f\n", cpu_time, gpu_time);
1666 printf(
"NO APV FILE OPEN TO BAKE INTO\n");
1671 if (byte_size > pv->
size && pv->
size > 0)
1673 printf(
"PV SIZE GREW, SKIPPING WRITE\n");
1685 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 7,
INSTANCE_SSBO);
1686 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 8,
TEXT_BOX_SSBO);
1687 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10,
RPROBE_SSBO);
1698 vec3 step_x, step_y, step_z;
1703 vec3 current_pos = pos;
1712 current_pos.
x = pos.
x + x * step_x.
x + y * step_y.
x + z * step_z.
x;
1713 current_pos.
y = pos.
y + x * step_x.
y + y * step_y.
y + z * step_z.
y;
1714 current_pos.
z = pos.
z + x * step_x.
z + y * step_y.
z + z * step_z.
z;
1724 glGenBuffers(1, &aprobe_ssbo);
1725 glBindBuffer(GL_SHADER_STORAGE_BUFFER, aprobe_ssbo);
1726 glBufferStorage(GL_SHADER_STORAGE_BUFFER,
sizeof(
AudioProbeGPU) * APROBE_COUNT, aprobe_init_data, GL_MAP_READ_BIT);
1727 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9, aprobe_ssbo);
1728 free(aprobe_init_data);
1731 int BOUNCE_SSBO_SIZE = APROBE_COUNT * MAX_SAMPLES_PER_PROBE;
1732 size_t BOUNCE_SSBO_BYTE_SIZE = BOUNCE_SSBO_SIZE *
sizeof(
AudioSampleGPU);
1733 const size_t SAMPLE_SSBO_CHUNK_SIZE = 400000000;
1734 int chunk_count =
MAX(BOUNCE_SSBO_BYTE_SIZE / SAMPLE_SSBO_CHUNK_SIZE, 1);
1735 int probes_per_chunk = APROBE_COUNT / chunk_count;
1736 for (
int i = 0; i < chunk_count; i++)
1738 size_t current_byte_size = SAMPLE_SSBO_CHUNK_SIZE;
1739 if (i == chunk_count - 1)
1741 current_byte_size = BOUNCE_SSBO_BYTE_SIZE - chunk_count * SAMPLE_SSBO_CHUNK_SIZE;
1743 int start = i * probes_per_chunk;
1749 glDeleteBuffers(1, &aprobe_ssbo);
1753 size_t byte_offset = 0;
1797 if (emitter->
free)
continue;
1798 if (!ma_sound_is_playing(&emitter->
sound_obj))
continue;
1814 vec3 inv_dir = (
vec3){1.0f/dir.
x, 1.0f/dir.
y, 1.0f/dir.
z};
1861 out_kernel[
n] = (2.0f * cutoff_hz / sample_rate) * w;
1865 float x = 2.0f *
M_PI * cutoff_hz * (float)k / sample_rate;
1866 out_kernel[
n] = (sinf(x) / (
M_PI * (float)k)) * w;
1869 sum += out_kernel[
n];
1876 out_kernel[
n] /= sum;
1897 out_kernels[0][
n] = lpf1[
n];
1899 out_kernels[1][
n] = lpf2[
n] - lpf1[
n];
1901 out_kernels[2][
n] = lpf3[
n] - lpf2[
n];
1903 out_kernels[3][
n] = lpf4[
n] - lpf3[
n];
1904 out_kernels[4][
n] = lpf5[
n] - lpf4[
n];
1907 out_kernels[5][
n] = delta - lpf5[
n];
RayHit raycast_scene(vec3 start, vec3 dir, float initial_t, bool check_normal)
Raycasts through the scene and finds closest intersection to meshes.
Acceleration structure generation and how we traverse them.
void init_normalized_lpf(float cutoff_hz, float sample_rate, float *out_kernel)
void init_band_kernels(float sample_rate, float f1_hz, float f2_hz, float f3_hz, float f4_hz, float f5_hz, float out_kernels[6][31])
float BAND_IMPULSES[6][31]
#define SAMPLE_IDX(i, sh, b)
Audio probe baking, portal creation, probe volumes, and emitter functions.
Audio IR processing, hrtf loading and parsing, and audio threading.
Engine specific types and defines.
Spring neck
Neck Spring (target based on pelvis).
FILE * APV_FILE
FILE pointer to the opened binary file.
#define MAX_PORTALS
The maximum amount of portals that are allocated to AStarWorkspace.path.
SceneData scene_data
SceneData that is more-so scene specific.
int i
The index into the array of whatever is being traversed.
#define MAX_AUDIO_PROBE_VOLUMES
int came_from
The index into the array of traversed items that this node came from.
int run_id
Makes sure that no old stack items are used.
Skeleton skeleton
Player Skeleton.
float g
The g score: current score of the path.
bool LOADED_AUDIO_PV_FLAG[4]
Flags that indicate if the slot is loaded.
Vector audio_portals
AudioPortals.
AudioProbe * audio_probes
A scratch buffer used when baking AudioProbes.
int parent
The index of the parent of this neighbor.
Globals GLOBALS
Engine Globals.
APV LOADED_AUDIO_PV[4]
Load slots for Audio ProbeVolumes.
int path_count
The final path count.
Vector audio_probe_volumes
All of the AudioProbe% volumes, regardless of if they have been loaded yet.
float g
The g score: current score of the path.
Vector min_heap
OpenNode - the heap of nodes that are pushed and popped until there are none left or it reaches the e...
int current_run
The current run indicates what AStarStateStack entries we can use.
int * path
The path indices that are returned.
vec3 pos
Position of the spring.
float f
The f score: score from neighbor to end.
Camera * cam
Player Camera.
AStarStateStack * stack
The stack that tracks where each node connects so that it can be backtracked.
float f
The f score: score from neighbor to end.
The workspace for conducting a-star pathfinding/.
A node inside of the min_heap of an AStarWorkspace.
double end_timer(Timer *t)
void start_timer(Timer *t)
void PV_step_size(ProbeVolume *pv, vec3 *step_x, vec3 *step_y, vec3 *step_z)
float abs_energy[6]
The energy per band with only absorption and no scattering.
float time_of_flight
The time that it takes for the sample to reach this position in total dist + dist to probe.
vec3 last_pos
The last job's position.
AudioProbe * audio_probes
The probes in the volume, loaded in from binary.
bool new_probe_ready
If a new job is ready.
float(* final_ir)[9]
The baked IR samples by 9 SH.
vec3 arrival_dir
The direction the ray was traveling to this position.
float rt60[6]
The RT60 from schroeder integration.
ivec3 resolution
The resolution in X, Y, Z.
size_t size
The byte size of this volume.
size_t byte_offset
The byte offset into the binary file storing this volume.
float energy[6]
The energy per band.
SDL_mutex * mutex
The mutex used when signalling a job.
int pv_id
Which ProbeVolume in SceneData.audio_probe_volumes.
OBB obb
The OBB that defines the size.
float slope[6]
The slope from EDC.
uint32_t valid
If it is occluded then it is not valid.
size_t ir_length
The amount of IR samples for this probe.
SDL_mutex * aprobe_mutex
Used when loading new APVs to avoid concurrency with the HRTF thread.
vec3 last_fwd
The last job's direction.
vec3 pos
The world position of this probe.
AudioProbeWeights w
Current job's weights.
SDL_cond * work_cond
The job signal.
#define AUDIO_PROBE_BINS
The amount of bins (to reduce max sample size).
#define MAX_IR_SAMPLES
Maximum IR sample length.
#define IR_SAMPLE_RATE
Sample rate for baked audio IRs.
int query_probe_volume(vec3 pos)
Checks which ProbeVolume a position is inside.
void reset_audio_pvs()
Reset audio pvs, frees each slot in the global audio pv slots.
void evaluate_sh(vec3 dir, float SH[SH_MAX])
Evaluates 9 spherical harmonics based on direction.
vec3 pos_to_pv_local(OBB *obb, vec3 pos)
Converts a position to local OBB space.
void load_audio_pv(APV *apv, ProbeVolume *pv)
Loads an APV into a slot.
void init_bandpass(Biquad *filter, float sample_rate, float center_freq, float q)
Initializes a bandpass filter for the synthetic IR.
void extract_t60(float *edc_db, AudioProbe *probe, int band, float bin_duration_seconds, int last_sample)
Extracts the RT60 from an EDC for computing a synthetic IR.
#define MAX_INTERP_APROBES
Max AudioProbes that can be sampled at once.
int query_audio_probe(ProbeVolume *pv, vec3 pos, ivec3 *out_local)
Queries which audio probe is closest to given position.
void bake_audio_probe_volume(ProbeVolume *pv)
Bakes an audio probe volume.
float extract_rms(AudioProbe *probe, int fade_start, int window_size)
Extracts the RMS from a certain sample range before the synthetic IR.
#define AUDIO_KERNEL_SIZE
Frequency kernel size for distributing samples during audio bake.
void update_player_audio_probe()
Determines if a new IR needs to be signaled from the background thread.
void SDLAudioCallback(void *pUserData, Uint8 *pStream, int len)
Passes frames to miniaudio in the audio thread.
#define MAX_EDC_SAMPLES
Maximum EDC sample length.
void generate_synthetic_IR_tail(float *out_tail, float fade_start, AudioProbe *probe, float rms)
Generates a synthetic IR tail for a given AudioProbe based on its RT60.
void remove_audio_pv(APV *apv, bool *apb)
Frees an APV from its slot.
void check_audio_pv()
Finds the closest audio PVs to the player and loads the closest ones into open slots based on distanc...
void compute_schroeder_edc(float *energy_histogram, float *edc_out)
Generates an Energy Decay Curve for input IR samples.
void interpolate_nearest_aprobes(vec3 pos, AudioProbeWeights *out_w)
Interpolates between 4 closest AudioProbes within one singular ProbeVolume and weighs them based on d...
#define AUDIO_NUM_BANDS
The amount of bands to use for audio probe baking.
const float AUDIO_BAND_FREQ[]
Audio frequencies for each band for audio probe baking.
#define EDC_SAMPLE_RATE
EDC sample rate for schroeder integration.
void process_probe_chunk(int start, int count)
Path traces from AudioProbes within a certain chunk of a ProbeVolume and processes samples per AudioP...
#define AUDIO_KERNEL_CENTER
Center of the kernel for distributing samples during audio bake.
float process_biquad(Biquad *filter, float in_sample)
Processes a biquad filter over a sample.
A ProbeVolume for AudioProbes.
Baked IR samples loaded in from binary into APVs from ProbeVolumes.
Simply stores the positions for audio probes during the bake.
Weights used for interpolating between audio probes.
Each ray's samples when baking AudioProbes, padded for GPU.
The ProbeVolumes for APVs and LPVs, controlled by OBBs.
bool is_occludable
If the AudioEmitter can be occluded and needs to go through the AudioPortal system.
Vector adjacent_portals
int - Vector of AudioPortals that can be seen from this one.
float current_distance
The current distance from listener.
float current_cutoff
The current low pass cutoff.
bool is_loop
If the AudioEmitter loops.
float current_volume
The current volume.
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...
char path[256]
The path to the sound.
float base_volume
The starting volume.
vec3 pos
The position of the AudioPortal.
ma_sound sound_obj
The miniaudio sound obj.
bool is_loaded
If the emitter is loaded in miniaudio.
bool free
Indicates if this AudioEmitter is empty or can be replaced.
void end_emitter(AudioEmitter *e)
Stops playing an 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.
int find_closest_visible_aportal(vec3 pos)
Finds the closest audio portal for a star to travel through.
void heap_swap(OpenNode *a, OpenNode *b)
Swaps A and B.
void play_emitter(AudioEmitter *emitter, vec3 pos)
Starts playing an emitter.
void audio_update(Player *player)
Spatializes the audio from the player's position.
float calculate_path_volume_equal_power(float path_distance, float min_distance, float max_distance)
Calculates volume over a path.
void heap_push(Vector *h)
After a node has been pushed to the top of the stack, we reorder by f score.
void reconstruct_path_aportal(AStarWorkspace *WS, int start, int end)
Traverses the AStarStateStack and backtracks to find the entire path.
OpenNode heap_pop(Vector *h)
Pops the bottommost root off of the OpenNode Vector and then places the topmost node onto the bottom ...
void unload_emitter(int id)
Unloads an emitter from miniaudio.
#define MAX_AUDIO_EMITTERS
The maximum amount of AudioEmitters.
int a_star_aportal(AStarWorkspace *WS, int start, int end)
Conducts AStar between a start and end point in AudioPortals.
void load_emitter(AudioEmitter *emitter, const char *filepath, bool is_loop, bool is_occludable, float base_volume)
Loads an existing emitter into miniaudio.
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 destroy_emitter(int id)
Unloads an emitter from miniaudio and frees the emitter as well.
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.
void update_audio_occlusion(Player *player)
Raycasts from player to audio sources to determine occlusion and performs a star if necessary.
void recalculate_audio_portal_paths()
Recalculates the adjacency map of portals between each other.
An AudioEmitter that plays audio possibily from a certain position or at a certain time.
AudioPortals used for determining paths to transmit sound when emitter and listener are occluded.
int audio_probe_iterations
The amount of iterations (sample rays) to bake per AudioProbe.
int audio_probe_bounces
The amount of bounces to accept per AudioProbe iteration.
Important globals for the entire engine and initialization functions that are mainly called on engine...
AudioScratchBuffers AUDIO_SCRATCH
GLuint GLOBAL_INSTANCE_SSBO
int DEBUG_APROBE_RAY_COUNT
AudioEmitter AUDIO_EMITTERS[1024]
ConvolverNode CONVOLVER_NODE
EditorSettings EDITOR_SETTINGS
GLuint AUDIO_PROBE_BAKE_SHADER
audio/audio_probe_bake.comp
Player player
The Player data.
float vec3_dist(vec3 a, vec3 b)
vec3 vec3_normalize(vec3 v)
vec3 vec3_scale(vec3 a, float b)
vec3 vec3_div(vec3 a, vec3 b)
vec3 vec3_sub(vec3 a, vec3 b)
vec3 vec3_add(vec3 a, vec3 b)
float clamp(float a, float b, float c)
float vec3_length(vec3 v)
void bind_baking_ssbos()
Binds SSBOs required for baking.
void unbind_baking_ssbos()
Unbinds SSBOs required for baking.
The main render pass, data GPU uploads, and SSBO management.
void init_vector(Vector *v, size_t i, size_t type_size)
void * vector_expand(Vector *v, size_t i)
vec3 mat3_mul_vec3(mat3 m, vec3 v)
#define CAST_VEC(vec, type)
#define REMOVE_FROM_VEC(vec, index, type)
vec3 OBB_min_corner(OBB *obb)
mat3 mat3_transpose(mat3 in)
bool point_in_obb(OBB *obb, vec3 pos)