Untitled
Loading...
Searching...
No Matches
AudioProbe System

All of the required structures for the path traced AudioProbe system. More...

Data Structures

struct  AudioProbeWeights
 Weights used for interpolating between audio probes. More...
struct  HRTFThreadData
 The data for the thread that prepares IRs by rotating then convolving them with an HRTF before it presents it to the audio thread. More...
struct  AudioScratchBuffers
 Scratch buffers and dimensions used for audio convolution FFTs. More...
struct  ConvolverNode
 The IR CONVOLVER_NODE used to process frames in the audio thread. More...
struct  AudioProbe
 Baked IR samples loaded in from binary into APVs from ProbeVolumes. More...
struct  AudioProbeGPU
 Simply stores the positions for audio probes during the bake. More...
struct  AudioSampleGPU
 Each ray's samples when baking AudioProbes, padded for GPU. More...
struct  ProbeVolume
 The ProbeVolumes for APVs and LPVs, controlled by OBBs. More...
struct  APV
 A ProbeVolume for AudioProbes. More...

Macros

#define MAX_INTERP_APROBES   4
 Max AudioProbes that can be sampled at once.
#define SAMPLE_RATE   48000
 Audio sample rate.
#define IR_SAMPLE_RATE   48000
 Sample rate for baked audio IRs.
#define EDC_SAMPLE_RATE   48000
 EDC sample rate for schroeder integration.
#define SPEED_OF_SOUND   343.0f
 Speed of sound constant.
#define MAX_APROBE_SECONDS   1
 Longest amount of AudioProbe samples when baking.
#define MAX_IR_SAMPLES   (IR_SAMPLE_RATE * MAX_APROBE_SECONDS)
 Maximum IR sample length.
#define MAX_EDC_SAMPLES   (EDC_SAMPLE_RATE * MAX_APROBE_SECONDS)
 Maximum EDC sample length.
#define MAX_SAMPLES   (SAMPLE_RATE * MAX_APROBE_SECONDS)
 Max samples for runtime convolution.
#define AUDIO_PROBE_BINS   48000
 The amount of bins (to reduce max sample size).
#define AUDIO_KERNEL_SIZE   31
 Frequency kernel size for distributing samples during audio bake.
#define AUDIO_KERNEL_CENTER   15
 Center of the kernel for distributing samples during audio bake.
#define AUDIO_NUM_BANDS   6
 The amount of bands to use for audio probe baking.
#define NUM_PARTITIONS_MAX   96
 Amount of max partitions to be used for overlap-add for audio probes + 1 for the tail trick.
#define NUM_PARTITIONS   95
 Amount of max partitions to be used for overlap-add.
#define SH_MAX   9

Typedefs

typedef fftwf_complex * PartitionTableChannel[95]
 Type for one FFT partiton for overlap-add.
typedef PartitionTableChannel PartitionTable[2]
 Type for two channels (stereo) for overlap-add.

Functions

vec3 pos_to_pv_local (OBB *obb, vec3 pos)
 Converts a position to local OBB space.
int query_probe_volume (vec3 pos)
 Checks which ProbeVolume a position is inside.
void remove_audio_pv (APV *apv, bool *apb)
 Frees an APV from its slot.
void load_audio_pv (APV *apv, ProbeVolume *pv)
 Loads an APV into a slot.
void interpolate_nearest_aprobes (vec3 pos, AudioProbeWeights *out_w)
 Interpolates between 4 closest AudioProbes within one singular ProbeVolume and weighs them based on distance.
float process_biquad (Biquad *filter, float in_sample)
 Processes a biquad filter over a sample.
void init_bandpass (Biquad *filter, float sample_rate, float center_freq, float q)
 Initializes a bandpass filter for the synthetic IR.
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 compute_schroeder_edc (float *energy_histogram, float *edc_out)
 Generates an Energy Decay Curve for input IR samples.
float extract_rms (AudioProbe *probe, int fade_start, int window_size)
 Extracts the RMS from a certain sample range before 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.
void process_probe_chunk (int start, int count)
 Path traces from AudioProbes within a certain chunk of a ProbeVolume and processes samples per AudioProbe, forming a synthetic IR from the RT60.
void bake_audio_probe_volume (ProbeVolume *pv)
 Bakes an audio probe volume.
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 frameCountInBytes)
 Passes frames to miniaudio in the audio thread.
int query_audio_probe (ProbeVolume *pv, vec3 pos, ivec3 *out_local)
 Queries which audio probe is closest to given position.
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[AUDIO_NUM_BANDS][AUDIO_KERNEL_SIZE])
 Initializes kernels used for IR sample filtering.
void check_audio_pv ()
 Finds the closest audio PVs to the player and loads the closest ones into open slots based on distance.
void reset_audio_pvs ()
 Reset audio pvs, frees each slot in the global audio pv slots.
void allocate_audio_scratch_hrtf (int hrtf_length)
 Allocates AUDIO_SCRATCH based on HRTF size.
void update_player_ir (PartitionTable *OUT)
 Rotates neighboring IRs to the Player and then partitions them for convolution in the audio thread.
int SDLCALL hrtf_worker (void *params)
 Main thread loop for HRTFThreadData.
void rotate_sh (float *OUT, float SH[SH_MAX], mat3 rot)
 Converts a position to local OBB space and returns the coord as if it was a texture from \(0 \rightarrow 1\).
void fft_channels (ConvolverNode *node, bool crossfading)
 FFTs the newest audio chunk with the partitioned overlap-add buffer.
void evaluate_sh (vec3 dir, float SH[SH_MAX])
 Evaluates 9 spherical harmonics based on direction.
void load_hrtf_from_binary (const char *filename)
 Loads a stored HRTF from engine binary.
void init_hrtf_worker_thread (HRTFThreadData *td)
 Initializes the worker thread that convolves the audio probes with the HRTF.
void delete_hrtf_worker_thread (HRTFThreadData *td)
 Cleans up the worker thread that convolves the audio probes with the HRTF.

Variables

const float AUDIO_BAND_FREQ [] = {125.0f, 250.0f, 500.0f, 1000.0f, 2000.0f, 4000.0f}
 Audio frequencies for each band for audio probe baking.

Detailed Description

All of the required structures for the path traced AudioProbe system.

Required defines for the AudioProbe system.


Data Structure Documentation

◆ AudioProbeWeights

struct AudioProbeWeights

Weights used for interpolating between audio probes.

See also
interpolate_nearest_aprobes()

Definition at line 381 of file engine_types.h.

Data Fields
int count The amount of probes that were sampled.
int APV_id Which APV these probes belong to.
int probes[4] The indices of the AudioProbes.
float weights[4] The weights that correspond to each probe's value.

◆ HRTFThreadData

struct HRTFThreadData

The data for the thread that prepares IRs by rotating then convolving them with an HRTF before it presents it to the audio thread.

See also
audio_ir.c

Definition at line 414 of file engine_types.h.

Data Fields
SDL_Thread * t The thread object.
SDL_mutex * mutex The mutex used when signalling a job.
SDL_cond * work_cond The job signal.
SDL_SpinLock ir_swap_lock The spinlock used when presenting an IR to the audio thread.
vec3 last_pos The last job's position.
vec3 last_fwd The last job's direction.
bool stop_requested Used to quit gracefully.
bool new_probe_ready If a new job is ready.
AudioProbeWeights w Current job's weights.
PartitionTable tables[4] The partitions for overlap-add quad-buffered.

Writes into the empty one.

PartitionTable * FRONT The current partition presented to the audio thread.

◆ AudioScratchBuffers

struct AudioScratchBuffers

Scratch buffers and dimensions used for audio convolution FFTs.

See also
init_audio_scratch_buffers()
allocate_audio_scratch_hrtf()

Definition at line 443 of file engine_types.h.

Data Fields
SDL_mutex * aprobe_mutex Used when loading new APVs to avoid concurrency with the HRTF thread.
int block_size Currently 512.
int padded_len Currently 1024.
int complex_len (padded_len / 2) + 1
int final_ir_len MAX_SAMPLES + hrtf_length - 1.
int ir_len MAX_IR_SAMPLES + hrtf_length - 1 and rounded up to next power of 2.
int complex_ir_len (padded_len / 2) + 1
float * HRTF_IR_IN Buffer used when splitting IR into partitions.
fftwf_plan fwd_plan The plan used when splitting IR into partitions.
fftwf_plan static_fwd_plan Unusued - was used when parsing in sofas.
fftwf_plan IR_fwd_plan Forward plan used when convolving IR with HRTF.
fftwf_plan IR_bwd_plan Inverse plan used when convolving IR with HRTF.
fftwf_plan bwd_plan Unusued - was used when parsing in sofas.
float * IR_SUM_L Used to hold the output of the inverse FFT of the IR with the HRTF.
float * IR_SUM_R Used to hold the output of the inverse FFT of the IR with the HRTF.
fftwf_complex * IR_SUM_L_FWD Used to accumulate the complex multiply of IR with the HRTF.
fftwf_complex * IR_SUM_R_FWD Used to accumulate the complex multiply of IR with the HRTF.
float * STATIC_HRTF_L[9] The static HRTF loaded from HRTF.bin.
float * STATIC_HRTF_R[9] The static HRTF loaded from HRTF.bin.
fftwf_complex * STATIC_HRTF_L_FWD[9] The forward FFT of the static HRTF loaded from HRTF.bin.
fftwf_complex * STATIC_HRTF_R_FWD[9] The forward FFT of the static HRTF loaded from HRTF.bin.
float * IR_ROT[9] The IR with rotated SH.
fftwf_complex * IR_ROT_FWD[9] The forward FFT of the rotated IR.

◆ ConvolverNode

struct ConvolverNode

The IR CONVOLVER_NODE used to process frames in the audio thread.

See also
init_audio_scratch_buffers()
convolver_node_process_pcm_frames()

Definition at line 482 of file engine_types.h.

Data Fields
ma_node_base base miniaudio node base.
ma_mutex lock Unused mutex for the audio thread.
int block_size Currently 512.
int padded_len Currently 1024.
int complex_len (padded_len / 2) + 1
int tail_len Currently: = block_size.
PartitionTable * ir The pointer to the new IR to convolve with.
PartitionTable * prev_ir The pointer to the previous IR we were convolving with.
fftwf_plan fwd_plan Forward plan used when convolving IR with current audio stream.
fftwf_plan bwd_plan Inverse plan used when convolving IR with current audio stream.
fftwf_complex * MONO_FWD Contains the output of the forward FFT of IR with current audio stream.
fftwf_complex * AUDIO_HISTORY[96] Contains the history of MONO_FWD up to NUM_PARTITIONS_MAX.
fftwf_complex * PREV_SUM_L The complex multiply of the previous IR with the partitions.
fftwf_complex * PREV_SUM_R The complex multiply of the previous IR with the partitions.
fftwf_complex * SUM_L The complex multiply of the new IR with the partitions.
fftwf_complex * SUM_R The complex multiply of the new IR with the partitions.
int history_head Contains the current position in the audio history buffer.
float * PREV_LEFT_OUT Contains the output of the inverse FFT of the previous IR with current audio stream.
float * PREV_RIGHT_OUT Contains the output of the inverse FFT of the previous IR with current audio stream.
float * LEFT_OUT Contains the output of the inverse FFT of the new IR with current audio stream.
float * RIGHT_OUT Contains the output of the inverse FFT of the new IR with current audio stream.
float * PREV_TAIL_LEFT Contains the tail of the previous IR.
float * PREV_TAIL_RIGHT Contains the tail of the previous IR.
float * TAIL_LEFT Contains the tail of the new IR.
float * TAIL_RIGHT Contains the tail of the new IR.
int crossfade_pos The amount of samples crossfaded so far.
bool crossfading Indicates if it is still crossfading between an old and new IR.

◆ AudioProbe

struct AudioProbe

Baked IR samples loaded in from binary into APVs from ProbeVolumes.

See also
bake_audio_probe_volume()

Definition at line 156 of file audio_probe_bake.comp.

Data Fields
vec3 pos The world position of this probe.
uint pad0
size_t ir_length The amount of IR samples for this probe.
float rt60[6] The RT60 from schroeder integration.
float slope[6] The slope from EDC.
float(* final_ir)[9] The baked IR samples by 9 SH.

◆ AudioProbeGPU

struct AudioProbeGPU

Simply stores the positions for audio probes during the bake.

See also
bake_audio_probe_volume()

Definition at line 1413 of file engine_types.h.

Data Fields
vec3 pos
uint32_t pad0

◆ AudioSampleGPU

struct AudioSampleGPU

Each ray's samples when baking AudioProbes, padded for GPU.

See also
audio/audio_probe_bake.comp

Definition at line 1424 of file engine_types.h.

Data Fields
vec3 arrival_dir The direction the ray was traveling to this position.
float time_of_flight The time that it takes for the sample to reach this position in total dist + dist to probe.
vec3 pos The hit position.
uint32_t valid If it is occluded then it is not valid.

Also, empty samples after the ray dies out are not valid.

float energy[6] The energy per band.
uint32_t pad0
uint32_t pad1
float abs_energy[6] The energy per band with only absorption and no scattering.
uint32_t pad4
uint32_t pad5

◆ ProbeVolume

struct ProbeVolume

The ProbeVolumes for APVs and LPVs, controlled by OBBs.

See also
load_audio_pv()
APV
LPV

Definition at line 3073 of file engine_types.h.

Data Fields
size_t byte_offset The byte offset into the binary file storing this volume.
size_t size The byte size of this volume.
OBB obb The OBB that defines the size.
ivec3 resolution The resolution in X, Y, Z.

◆ APV

struct APV

A ProbeVolume for AudioProbes.

See also
load_audio_pv()
AudioProbe

Definition at line 3089 of file engine_types.h.

Data Fields
int pv_id Which ProbeVolume in SceneData.audio_probe_volumes.
AudioProbe * audio_probes The probes in the volume, loaded in from binary.

Macro Definition Documentation

◆ MAX_INTERP_APROBES

#define MAX_INTERP_APROBES   4

Max AudioProbes that can be sampled at once.

Definition at line 80 of file engine_types.h.

Referenced by interpolate_nearest_aprobes().

◆ SAMPLE_RATE

#define SAMPLE_RATE   48000

Audio sample rate.

Definition at line 81 of file engine_types.h.

◆ IR_SAMPLE_RATE

#define IR_SAMPLE_RATE   48000

Sample rate for baked audio IRs.

Definition at line 83 of file engine_types.h.

Referenced by generate_synthetic_IR_tail(), and process_probe_chunk().

◆ EDC_SAMPLE_RATE

#define EDC_SAMPLE_RATE   48000

EDC sample rate for schroeder integration.

Definition at line 84 of file engine_types.h.

Referenced by process_probe_chunk().

◆ SPEED_OF_SOUND

#define SPEED_OF_SOUND   343.0f

Speed of sound constant.

Definition at line 86 of file engine_types.h.

◆ MAX_APROBE_SECONDS

#define MAX_APROBE_SECONDS   1

Longest amount of AudioProbe samples when baking.

Definition at line 87 of file engine_types.h.

◆ MAX_IR_SAMPLES

#define MAX_IR_SAMPLES   (IR_SAMPLE_RATE * MAX_APROBE_SECONDS)

Maximum IR sample length.

Definition at line 88 of file engine_types.h.

Referenced by allocate_audio_scratch_hrtf(), generate_synthetic_IR_tail(), and process_probe_chunk().

◆ MAX_EDC_SAMPLES

#define MAX_EDC_SAMPLES   (EDC_SAMPLE_RATE * MAX_APROBE_SECONDS)

Maximum EDC sample length.

Definition at line 89 of file engine_types.h.

Referenced by compute_schroeder_edc(), and process_probe_chunk().

◆ MAX_SAMPLES

#define MAX_SAMPLES   (SAMPLE_RATE * MAX_APROBE_SECONDS)

Max samples for runtime convolution.

Definition at line 90 of file engine_types.h.

◆ AUDIO_PROBE_BINS

#define AUDIO_PROBE_BINS   48000

The amount of bins (to reduce max sample size).

Definition at line 91 of file engine_types.h.

Referenced by process_probe_chunk(), and update_player_ir().

◆ AUDIO_KERNEL_SIZE

#define AUDIO_KERNEL_SIZE   31

Frequency kernel size for distributing samples during audio bake.

Definition at line 92 of file engine_types.h.

Referenced by init_band_kernels(), init_band_kernels(), init_normalized_lpf(), and process_probe_chunk().

◆ AUDIO_KERNEL_CENTER

#define AUDIO_KERNEL_CENTER   15

Center of the kernel for distributing samples during audio bake.

Definition at line 93 of file engine_types.h.

Referenced by init_band_kernels(), init_normalized_lpf(), and process_probe_chunk().

◆ AUDIO_NUM_BANDS

#define AUDIO_NUM_BANDS   6

◆ NUM_PARTITIONS_MAX

#define NUM_PARTITIONS_MAX   96

Amount of max partitions to be used for overlap-add for audio probes + 1 for the tail trick.

Definition at line 96 of file engine_types.h.

Referenced by convolver_node_process_pcm_frames(), fft_channels(), and init_audio_scratch_buffers().

◆ NUM_PARTITIONS

#define NUM_PARTITIONS   95

Amount of max partitions to be used for overlap-add.

Definition at line 97 of file engine_types.h.

Referenced by convolver_node_process_pcm_frames(), delete_hrtf_worker_thread(), fft_channels(), init_hrtf_worker_thread(), and update_player_ir().

◆ SH_MAX

Typedef Documentation

◆ PartitionTableChannel

typedef fftwf_complex* PartitionTableChannel[95]

Type for one FFT partiton for overlap-add.

Definition at line 368 of file engine_types.h.

◆ PartitionTable

typedef PartitionTableChannel PartitionTable[2]

Type for two channels (stereo) for overlap-add.

Definition at line 374 of file engine_types.h.

Function Documentation

◆ pos_to_pv_local()

vec3 pos_to_pv_local ( OBB * obb,
vec3 pos )

Converts a position to local OBB space.

\begin{align} p &= \mathrm{Position} \\ c &= \mathrm{Center} \\ l &= \mathrm{Length} \\ \Delta &= p - c \\ n &= \mathbf{M^r}\mathbf{\Delta} \\ &= (\frac{n}{l}) * 0.5 \end{align}

Parameters
obbThe OBB to transform into.
posThe world space position.
Returns
The resultingcoord as if it was a texture from \(0 \rightarrow 1\).

Definition at line 920 of file audio.c.

References OBB::center, OBB::extents, mat3_mul_vec3(), mat3_transpose(), pos_to_pv_local(), OBB::rot, vec3_add(), vec3_div(), vec3_scale(), and vec3_sub().

Referenced by main(), pos_to_pv_local(), pos_to_pv_local(), and query_audio_probe().

◆ query_probe_volume()

int query_probe_volume ( vec3 pos)

Checks which ProbeVolume a position is inside.

Todo
Handle multiple ProbeVolumes and bordering ProbeVolumes.
Parameters
posThe position to check.
Returns
The index to the ProbeVolume inside of SceneData.audio_probe_volumes.

Definition at line 938 of file audio.c.

References SceneData::audio_probe_volumes, CAST_VEC, Vector::count, GLOBALS, ProbeVolume::obb, point_in_obb(), query_probe_volume(), and Globals::scene_data.

Referenced by check_audio_pv(), interpolate_nearest_aprobes(), and query_probe_volume().

◆ remove_audio_pv()

void remove_audio_pv ( APV * apv,
bool * apb )

Frees an APV from its slot.

Parameters
apvThe APV to free.
apbThe pointer to the boolean that checks if the APV is loaded.

Definition at line 953 of file audio.c.

References APV::audio_probes, APV::pv_id, and remove_audio_pv().

Referenced by check_audio_pv(), remove_audio_pv(), and reset_audio_pvs().

◆ load_audio_pv()

void load_audio_pv ( APV * apv,
ProbeVolume * pv )

Loads an APV into a slot.

Parameters
apvThe APV slot to load into.
pvThe ProbeVolume that describes the offset and size of the probe data inside of SceneData.APV_FILE.

<

<

Definition at line 972 of file audio.c.

References SceneData::APV_FILE, APV::audio_probes, ProbeVolume::byte_offset, AudioProbe::final_ir, GLOBALS, AudioProbe::ir_length, load_audio_pv(), ProbeVolume::resolution, Globals::scene_data, SH_MAX, ivec3::x, ivec3::y, and ivec3::z.

Referenced by check_audio_pv(), and load_audio_pv().

◆ interpolate_nearest_aprobes()

void interpolate_nearest_aprobes ( vec3 pos,
AudioProbeWeights * out_w )

Interpolates between 4 closest AudioProbes within one singular ProbeVolume and weighs them based on distance.

Parameters
posThe pos to interpolate around.
out_wPointer to the resulting weights.

<Max AudioProbes that can be sampled at once

<Max AudioProbes that can be sampled at once

<Max AudioProbes that can be sampled at once

Definition at line 1098 of file audio.c.

References SceneData::audio_probe_volumes, APV::audio_probes, CAST_VEC, DEBUG_CURRENT_APROBE, GLOBALS, hit, RayHit::hit, interpolate_nearest_aprobes(), SceneData::LOADED_AUDIO_PV, SceneData::LOADED_AUDIO_PV_FLAG, MAX_AUDIO_PROBE_VOLUMES, MAX_INTERP_APROBES, AudioProbe::pos, APV::pv_id, query_audio_probe(), query_probe_volume(), raycast_scene(), ProbeVolume::resolution, Globals::scene_data, RayHit::t, vec3_length(), vec3_normalize(), vec3_sub(), weights, ivec3::x, ivec3::y, and ivec3::z.

Referenced by interpolate_nearest_aprobes(), and update_player_audio_probe().

◆ process_biquad()

float process_biquad ( Biquad * filter,
float in_sample )

Processes a biquad filter over a sample.

\(y_b[n] = b_{0,b} \cdot (w[n] E_b[n]) + b_{1,b} \cdot x_b[n-1] + b_{2,b} \cdot x_b[n-2] - a_{1,b} \cdot y_b[n-1] - a_{2,b} \cdot y_b[n-2]\)

Parameters
filterThe Biquad.
in_sampleThe sample.
Returns
The filtered sample.

Definition at line 1232 of file audio.c.

References Biquad::a1, Biquad::a2, Biquad::b0, Biquad::b1, Biquad::b2, process_biquad(), Biquad::x1, Biquad::x2, Biquad::y1, and Biquad::y2.

Referenced by generate_synthetic_IR_tail(), and process_biquad().

◆ init_bandpass()

void init_bandpass ( Biquad * filter,
float sample_rate,
float center_freq,
float q )

Initializes a bandpass filter for the synthetic IR.

Parameters
filterThe Biquad.
sample_rateThe sample rate to divide by.
center_freqWhat frequency the bandpass centers around.
qThe Q of the filter.

Definition at line 1249 of file audio.c.

References Biquad::a0, Biquad::a1, Biquad::a2, Biquad::b0, Biquad::b1, Biquad::b2, init_bandpass(), and M_PI.

Referenced by generate_synthetic_IR_tail(), and init_bandpass().

◆ generate_synthetic_IR_tail()

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.

\begin{align} E_b &= \mathrm{Envelope} \\ f &= \mathrm{Fade\ Start} \\ s &= \mathrm{IR\ Samples} \\ B &= \mathrm{Band\ Count} \\ H_b &= \mathrm{Biquad\ Filter} \\ d_b &= \mathrm{Decay} \\ y &= \mathrm{Output\ Samples} \\ & \textbf{for } n \in{}[f,s) \textbf{ do}\\ & \quad \omega[n] = \gamma \cdot \mathcal{U}(-1, 1) \\ & \quad \text{where } \gamma = \frac{1}{0.577350268} \\ & \quad y_b[n] = b_{0,b} \cdot (w[n] E_b[n]) + b_{1,b} \cdot x_b[n-1] + b_{2,b} \cdot x_b[n-2] - a_{1,b} \cdot y_b[n-1] - a_{2,b} \cdot y_b[n-2] \\ & \quad E_b[n] = E_b[n-1] \cdot d_b \\ & \quad y[n] = \sum_{b=0}^{B-1}H_b(\omega[n] \cdot E_b[n]) \\ \end{align}

Parameters
out_tailThe samples to write to.
fade_startThe first sample to begin writing to.
probeThe AudioProbe to generate samples for.
rmsThe RMS of the early reflections that we match our gain to.

<The amount of bands to use for audio probe baking

<The amount of bands to use for audio probe baking

<The amount of bands to use for audio probe baking

<The amount of bands to use for audio probe baking

<Sample rate for baked audio IRs

<Sample rate for baked audio IRs

<The amount of bands to use for audio probe baking

<Sample rate for baked audio IRs

<Longest amount of AudioProbe samples when baking

<Maximum IR sample length

<The amount of bands to use for audio probe baking

Definition at line 1266 of file audio.c.

References AUDIO_BAND_FREQ, AUDIO_NUM_BANDS, generate_synthetic_IR_tail(), init_bandpass(), IR_SAMPLE_RATE, MAX, MAX_IR_SAMPLES, process_biquad(), rand(), AudioProbe::rt60, and SAMPLE_RATE.

Referenced by generate_synthetic_IR_tail(), and process_probe_chunk().

◆ compute_schroeder_edc()

void compute_schroeder_edc ( float * energy_histogram,
float * edc_out )

Generates an Energy Decay Curve for input IR samples.

\begin{align} Y_k &= \sum_{i=0}^{k}X_i \\ E_{\text{max}} &= \max(Y_k[0], 1\cdot10^{-12}) \\ \textbf{for } i &= 0 \text{ to } N_{\text{max}} - 1: \\ & \quad Y_k[i] = \begin{cases} 10 \cdot \log_{10}\left(\frac{Y_k[i]}{E_{\text{max}}}\right), & \text{if } Y_k[i] > 0 \\ -120, & \text{otherwise} \end{cases} \end{align}

Parameters
energy_histogramThe incoming energy samples (may be binned).
edc_outThe resulting EDC.

<EDC sample rate for schroeder integration

<Longest amount of AudioProbe samples when baking

<Maximum EDC sample length

<EDC sample rate for schroeder integration

<Longest amount of AudioProbe samples when baking

<Maximum EDC sample length

Definition at line 1312 of file audio.c.

References compute_schroeder_edc(), and MAX_EDC_SAMPLES.

Referenced by compute_schroeder_edc(), and process_probe_chunk().

◆ extract_rms()

float extract_rms ( AudioProbe * probe,
int fade_start,
int window_size )

Extracts the RMS from a certain sample range before the synthetic IR.

\begin{align} S &= \text{Start} \\ F &= \text{Fade Start} \\ X &= \text{IR Samples} \\ &= \sqrt{\frac{\sum_{i=S}^{F-1}X^2}{F-S}} \\ \end{align}

Parameters
probeThe AudioProbe with samples.
fade_startWhere we will start fading into the synthetic IR.
window_sizeHow large of a window of samples to average.
Returns
The RMS.

Definition at line 1342 of file audio.c.

References extract_rms(), and AudioProbe::final_ir.

Referenced by extract_rms(), and process_probe_chunk().

◆ extract_t60()

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.

Todo
Write otherwise case for the end.

\begin{align} L_{\text{max}} &= \text{Last Sample} \\ E &= \text{EDC} \\ R_{\text{t60}} &= \text{RT60} \\ S &= \text{Slope} \\ B &= \text{Bin Duration} \\ s_i &= -1 \\ e_i &= -1 \\ & \textbf{for } i = 0 \text{ to } L_{\text{max}} - 1: \\ & \qquad \left\lbrace s_i = i, \right. & \text{if } s_i = -1 \text{ and } E[i] \le -5 \\ & \qquad \left\lbrace \begin{aligned} e_i &= i, \\ &\text{Break,} \end{aligned} \right. & \text{if } e_i = -1 \text{ and } E[i] \le -35 \\ & \left\lbrace \begin{aligned} R_{\text{t60}} &= 0, \\ S &= 0, \\ &\text{Return,} \end{aligned} \right. & \text{if } s_i = -1 \text{ and } e_i = -1 \\ f(i) &= i \cdot B \\ x &= \sum_{i=s_i}^{e_i}(i \cdot B) \\ y &= \sum_{i=s_i}^{e_i}E[i] \\ x_y &= \sum_{i=s_i}^{e_i}(i \cdot B \cdot E[i]) \\ x_x &= \sum_{i=s_i}^{e_i}(i \cdot B)^2 \\ n &= e_i - s_i + 1 \\ D &= (n \cdot x_x) - (x^2) \\ & \left\lbrace \begin{aligned} S &= \frac{(n \cdot x_y) - (x \cdot y)}{D}, \\ R_{\text{t60}} &= \frac{-60}{slope}, \end{aligned} \right. & \text{if } D \neq 0 \\ \end{align}

Parameters
edc_dbThe EDC.
probeThe AudioProbe that is computing the IR.
bandThe band to compute.
bin_duration_seconds(for bins - unused so it's 1 / SAMPLE_RATE).
last_sampleThe index of the sample binned at the furthest index.
Todo
Make sure it's safe to return early.

Definition at line 1363 of file audio.c.

References extract_t60(), n, AudioProbe::rt60, and AudioProbe::slope.

Referenced by extract_t60(), and process_probe_chunk().

◆ process_probe_chunk()

void process_probe_chunk ( int start,
int count )

Path traces from AudioProbes within a certain chunk of a ProbeVolume and processes samples per AudioProbe, forming a synthetic IR from the RT60.

See also
extract_t60()
compute_schroeder_edc()
generate_synthetic_ir_tail()

\begin{align} I &= \text{Iterations} \\ P &= \text{Probe Array} \\ p &= \text{Probe} \\ B &= \text{Bounces} \\ M &= \text{Material} \\ S_{\text{rate}} &= \text{Sample Rate} \\ S_{\text{max}} &= \text{Maximum Samples} \\ Z &= \text{Bands} \\ G &= \text{Audio Kernel} \\ L &= \text{Synthetic IR} \\ \delta &= \text{Slope} \\ \Upsilon &= \text{Speed of Sound} \\ \chi &= \text{Band Impulses} \\ F &= \text{Fade} \\ & \textbf{for } i = 0 \text{ to } I - 1: \\ & \quad \textbf{for } j = 0 \text{ to } P_{\text{count}} - 1: \\ & \qquad p = P[j] \\ & \qquad \phi = \pi \cdot (3 - \sqrt 5) \\ & \qquad y = 1 - \frac{2 \cdot (i + 0.5)}{I} \\ & \qquad r = \sqrt{1 - y^2} \\ & \qquad \theta = \phi \cdot i \\ & \qquad \vec v = \begin{bmatrix} \cos{\theta} \cdot r \\ y \\ \sin{\theta} \cdot r \end{bmatrix} \\ & \qquad O = p_{\text{pos}} \\ & \qquad \textbf{for } k = 0 \text{ to } B - 1: \\ & \qquad \quad R(t) = O + t\vec v \\ & \qquad \quad t_{\text{hit}} = \left\lbrace \begin{aligned} & min({t \ge 0 | R(t) \in \mathcal S }), & \text{if }R(t) \text{ hits }\mathcal S\\ & \infty, & \text{otherwise} \end{aligned} \right. \\ & \qquad \quad \text{Break}, \text{if } t_{\text{hit}} = \infty \\ & \qquad \quad x = R(t_{\text{hit}}) \\ & \qquad \quad t_n = \text{Normal} (\mathcal S) \\ & \qquad \quad M = \text{Material} (\mathcal S) \\ & \qquad \quad S = p_{\text{sample}}[i, k]\\ & \qquad \quad S_{\text{pos}} = x \\ & \qquad \quad S_{\text{dir}} = \vec v \\ & \qquad \quad \vec v_x = || p_{\text{pos}} - x || \\ & \qquad \quad S_{\text{tof}} = \frac{(\sum_{o=0}^{k}t_{\text{hit}}) + \vec v_x}{\Upsilon} \\ & \qquad \quad R(t) = O + t\vec v_x \\ & \qquad \quad t_{\text{hit}} = \left\lbrace \begin{aligned} & min({t \ge 0 | R(t) \in \mathcal S }), & \text{if }R(t) \text{ hits }\mathcal S\\ & \infty, & \text{otherwise} \end{aligned} \right. \\ & \qquad \quad S_{\text{valid}} = 0, \text{if } t_{\text{hit}} \lt \vec v_x\\ & \qquad \quad E_b = E_b \cdot (1 - M_{\text{abs}}) \\ & \qquad \quad S_{\text{energy}} = E_b * \gamma \\ & \qquad \quad V(N) = \left\lbrace \begin{aligned} & \tau_1, \tau_2 \in \sim \mathcal U [0, 1] \\ & \phi = 2 \pi \cot \tau_1 \\ & \vec v = \left\lbrack \begin{aligned} & \cos(\phi) \cdot \sqrt{\tau_2}\\ & \sin(\phi) \cdot \sqrt{\tau_2}\\ & \sqrt{1 - \tau_2} \\ \end{aligned} \right\rbrack \\ & \left\lbrace \begin{aligned} & \begin{aligned} & T = \begin{bmatrix} 0 \\ -1 \\ 0 \end{bmatrix}\\ & B = \begin{bmatrix} -1 \\ 0 \\ 0 \end{bmatrix}\\ \end{aligned}, & \text{if } N_z < -0.99998796 \\ \\ & \begin{aligned} & \alpha = \frac{1}{1+N_z}\\ & \beta = -N_x \cdot N_y \cdot \alpha \\ & T = \begin{bmatrix} 1 - N_x^2\alpha \\ \beta \\ -N_x \end{bmatrix}\\ & B = \begin{bmatrix} \beta \\ 1 - N_y^2\alpha \\ -N_y \end{bmatrix}\\ \end{aligned}, & \text{otherwise} \\ \end{aligned} \right. \\ & M_n = \begin{bmatrix} T_x & B_x & N_x \\ T_y & B_y & N_y \\ T_z & B_z & N_z \end{bmatrix}\\ & \vec v = M_n \cdot \vec v \\ & \frac{\vec v}{||\vec v||} \end{aligned} \right. \\ & \qquad \quad \mu \in \sim \mathcal U [0, 1] \\ & \qquad \quad \left\lbrace \begin{aligned} & \vec v = V(t_n), & \text{if } \mu \lt M_{\text{scattering}}\\ & \vec v = \vec v - 2(\vec v \cdot t_n)t_n, & otherwise \end{aligned} \right. \\ & \textbf{for } j = 0 \text{ to } P_{\text{count}} - 1: \\ & \quad p = P[j] \\ & \quad \textbf{for } i = 0 \text{ to } I - 1: \\ & \qquad \textbf{for } k = 0 \text{ to } B - 1: \\ & \qquad \quad S = p_{\text{sample}}[i, k]\\ & \qquad \quad T = S_{\text{tof}} \cdot S_{\text{rate}} \\ & \qquad \quad \text{continue, }\text{if } S_{\text{valid}} = 0 \text{ or } T \geq S_{\text{max}} - 1 \text{ or } T \lt 0\\ & \qquad \quad H = \text{SH} (S_{\text{dir}}) \\ & \qquad \quad p_{\text{ir}}[T, o, f] = H[o] \cdot S_{\text{energy}}[f] \cdot \frac{4\pi}{I} \text{ for } o \in \lbrace0, ..., 8\rbrace \text{ and for } f \in \lbrace0, ..., Z_{\text{max}} - 1\rbrace \\ & \qquad \quad E_0[T, b] = E_0[T, b] + S_{\text{abs energy}} \cdot \frac{4\pi}{I}\text{ for } b \in \lbrace 0, ..., B_{\text{max}} - 1 \rbrace \\ & \quad \textbf{for } b = 0 \text{ to } B_{\text{max}} - 1: \\ & \qquad E_1 = \text{EDC}(E_0) \\ & \qquad (R_{\text{t60}}, \delta) = \text{RT60}(E_1) \\ & \quad \textbf{for } k = 0 \text{ to } S_{\text{max}} - 1: \\ & \qquad \textbf{let } \sigma \in -1, 1 \text{ be chosen uniformly at random}\\ & \qquad \textbf{for } b = 0 \text{ to } B_{\text{max}} - 1: \\ & \qquad \quad S_0 = p_{\text{ir}}[k, 0, b] \\ & \qquad \quad \text{continue, if } S_0 \leq 0.000001 \\ & \qquad \quad E_{\text{total}} = \frac{S_0}{Y_00} \\ & \qquad \quad B_{\text{amp}} = \sqrt{E_{\text{total}}} * \sigma \\ & \qquad \quad S_r[n] = \frac{p_{\text{ir}}[k, n, b]}{S_0} \text{ for n } \in \lbrace 0, ..., 8\rbrace\\ & \qquad \quad \text{for } m = 0 \text{ to } G_{\text{size}} - 1: \\ & \qquad \qquad X_i = k + m - G_{\text{center}} \\ & \qquad \qquad \left\lbrace \begin{aligned} & \text{continue}, X_i \lt 0\\ & \text{break}, X_i \geq S_{\text{max}} - 1 \\ \end{aligned} \right. \\ & \qquad \qquad p_{\text{fir}}[X_i, n] = p_{\text{fir}}[X_i, n] + \chi[b, m] \cdot B_{\text{amp}} \cdot S_r[n] \text { for n } \in \lbrace 0, ..., 8\rbrace\\ & \quad R = \text{RMS}(p) \\ & \quad L = \text{SYNTHETIC}(p, RMS) \\ & \quad \text{for }x = F_{\text{start}} \text{ to } S_{\text{max}} - 1: \\ & \qquad \alpha = \min(\frac{x - F_{\text{start}}}{F_{\text{end}} - F_{\text{start}}}, 1) \\ & \qquad e = \cos(\alpha \cdot 0.5 \cdot \pi) \\ & \qquad l = \sin(\alpha \cdot 0.5 \cdot \pi) \\ & \qquad p_{\text{fir}}[x, 0] = p_{\text{fir}}[x, 0] \cdot e + L[x] \cdot l \\ & \qquad d \in \sim \mathcal U [-0.2, 0.2] \\ & \qquad p_{\text{fir}}[x, g] = p_{\text{fir}}[x, g] \cdot e + L[x] \cdot d \cdot l \text{ for } g \in \lbrace1, ..., 8\rbrace \\ \end{align}

Parameters
startThe first AudioProbe to process.
countThe amount of AudioProbes to process.

<The amount of bands to use for audio probe baking

<EDC sample rate for schroeder integration

<Longest amount of AudioProbe samples when baking

<Maximum EDC sample length

<EDC sample rate for schroeder integration

<Longest amount of AudioProbe samples when baking

<Maximum EDC sample length

<Sample rate for baked audio IRs

<Longest amount of AudioProbe samples when baking

<Maximum IR sample length

<Sample rate for baked audio IRs

<Longest amount of AudioProbe samples when baking

<Maximum IR sample length

<

<The amount of bands to use for audio probe baking

<Sample rate for baked audio IRs

<Longest amount of AudioProbe samples when baking

<Maximum IR sample length

<

<The amount of bands to use for audio probe baking

<The amount of bands to use for audio probe baking

<EDC sample rate for schroeder integration

<Longest amount of AudioProbe samples when baking

<Maximum EDC sample length

<EDC sample rate for schroeder integration

<Longest amount of AudioProbe samples when baking

<Maximum EDC sample length

<Sample rate for baked audio IRs

<Longest amount of AudioProbe samples when baking

<Maximum IR sample length

<Longest amount of AudioProbe samples when baking

<Max samples for runtime convolution

<The amount of bands to use for audio probe baking

<Sample rate for baked audio IRs

<Sample rate for baked audio IRs

<Longest amount of AudioProbe samples when baking

<Maximum IR sample length

<

<

<The amount of bands to use for audio probe baking

<

<The amount of bands to use for audio probe baking

<The amount of bands to use for audio probe baking

<EDC sample rate for schroeder integration

<EDC sample rate for schroeder integration

<Longest amount of AudioProbe samples when baking

<Maximum EDC sample length

<The amount of bands to use for audio probe baking

<The amount of bands to use for audio probe baking

<Longest amount of AudioProbe samples when baking

<Max samples for runtime convolution

<Longest amount of AudioProbe samples when baking

<Max samples for runtime convolution

<

<

<Longest amount of AudioProbe samples when baking

<Max samples for runtime convolution

<The amount of bins (to reduce max sample size)

<The amount of bins (to reduce max sample size)

<The amount of bands to use for audio probe baking

<

<The amount of bands to use for audio probe baking

<The amount of bands to use for audio probe baking

<

<

<

<The amount of bands to use for audio probe baking

<The amount of bands to use for audio probe baking

<Frequency kernel size for distributing samples during audio bake

<Center of the kernel for distributing samples during audio bake

<

<

<The amount of bands to use for audio probe baking

Definition at line 1411 of file audio.c.

References AudioSampleGPU::abs_energy, AudioSampleGPU::arrival_dir, AUDIO_KERNEL_CENTER, AUDIO_KERNEL_SIZE, AUDIO_NUM_BANDS, AUDIO_PROBE_BAKE_SHADER, AUDIO_PROBE_BINS, EditorSettings::audio_probe_bounces, EditorSettings::audio_probe_iterations, Globals::audio_probes, BAND_IMPULSES, compute_schroeder_edc(), DEBUG_APROBE_RAY_COUNT, DEBUG_LINE_COUNT, EDC_SAMPLE_RATE, EDITOR_SETTINGS, end_timer(), AudioSampleGPU::energy, evaluate_sh(), extract_rms(), extract_t60(), AudioProbe::final_ir, generate_synthetic_IR_tail(), GLOBALS, AudioProbe::ir_length, IR_SAMPLE_RATE, M_PI, MAX, MAX_EDC_SAMPLES, MAX_IR_SAMPLES, MAX_SAMPLES, MIN, process_probe_chunk(), rand(), SAMPLE_IDX, SAMPLE_RATE, samples, SH_MAX, start_timer(), AudioSampleGPU::time_of_flight, AudioSampleGPU::valid, vec3::x, vec3::y, Y_00, and vec3::z.

Referenced by bake_audio_probe_volume(), and process_probe_chunk().

◆ bake_audio_probe_volume()

◆ update_player_audio_probe()

◆ SDLAudioCallback()

void SDLAudioCallback ( void * pUserData,
Uint8 * pStream,
int frameCountInBytes )

Passes frames to miniaudio in the audio thread.

See also
init.c.

Definition at line 908 of file audio.c.

References SDLAudioCallback().

Referenced by init_sdl_audio(), and SDLAudioCallback().

◆ query_audio_probe()

int query_audio_probe ( ProbeVolume * pv,
vec3 pos,
ivec3 * out_local )

Queries which audio probe is closest to given position.

Parameters
pvThe volume to check.
posThe position to check.
out_localPointer to integer index of returned probe in xyz.
Returns
Probe index.

Definition at line 929 of file audio.c.

References clamp(), ProbeVolume::obb, pos_to_pv_local(), query_audio_probe(), ProbeVolume::resolution, ivec3::x, vec3::x, ivec3::y, vec3::y, ivec3::z, and vec3::z.

Referenced by interpolate_nearest_aprobes(), and query_audio_probe().

◆ init_band_kernels()

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[AUDIO_NUM_BANDS][AUDIO_KERNEL_SIZE] )

Initializes kernels used for IR sample filtering.

Parameters
sample_rateThe sample rate of audio.

References AUDIO_KERNEL_SIZE, AUDIO_NUM_BANDS, check_audio_pv(), init_band_kernels(), and reset_audio_pvs().

◆ check_audio_pv()

◆ reset_audio_pvs()

void reset_audio_pvs ( )

Reset audio pvs, frees each slot in the global audio pv slots.

Definition at line 964 of file audio.c.

References GLOBALS, SceneData::LOADED_AUDIO_PV, SceneData::LOADED_AUDIO_PV_FLAG, MAX_AUDIO_PROBE_VOLUMES, remove_audio_pv(), reset_audio_pvs(), and Globals::scene_data.

Referenced by init_band_kernels(), load_aprobes(), render_audio_menu(), and reset_audio_pvs().

◆ allocate_audio_scratch_hrtf()

◆ update_player_ir()

void update_player_ir ( PartitionTable * OUT)

Rotates neighboring IRs to the Player and then partitions them for convolution in the audio thread.

\begin{align} X_i &= \mathrm{IR[]} \\ l &= \mathrm{IR\ Length} \\ c_l &= \mathrm{Complex\ Length} \\ M^r &= \mathrm{Player\ Rotation} \\ b &= \mathrm{Block\ Size} \\ p &= \mathrm{Partiton\ Count} \\ P_o &= \mathrm{Partitions\ Out} \\ X_r &= \sum_{i=0}^{l}(D^\ell(M^r)X_i)\\ X_f &= \mathrm{FFT}(X_r) \\ X_t &= \sum_{s=0}^{c_l}(a + bi)(c + di) = (ac - bd) + (ad + bc)i \\ X_o &= ||\mathrm{IFFT}(X_t)|| \\ & \textbf{for } i \in{}[0,p) \textbf{ do}\\ & \quad \textbf{for } k \in{}[0,b) \textbf{ do}\\ & \qquad Y_i[k] = X_o[i * b + k] \\ & \quad P_o = \mathrm{FFT}(Y_i) \\ \end{align}

Parameters
OUTThe PartitionTable to write into.

Definition at line 326 of file audio_ir.c.

References AudioScratchBuffers::aprobe_mutex, AudioProbeWeights::APV_id, AUDIO_PROBE_BINS, APV::audio_probes, AUDIO_SCRATCH, AudioScratchBuffers::block_size, cam, Player::cam, AudioScratchBuffers::complex_ir_len, AudioScratchBuffers::complex_len, AudioProbeWeights::count, AudioProbe::final_ir, AudioScratchBuffers::final_ir_len, Camera::forward, AudioScratchBuffers::fwd_plan, GLOBALS, AudioScratchBuffers::HRTF_IR_IN, HRTF_TD, AudioScratchBuffers::IR_bwd_plan, AudioScratchBuffers::IR_fwd_plan, AudioScratchBuffers::ir_len, AudioProbe::ir_length, AudioScratchBuffers::IR_ROT, AudioScratchBuffers::IR_ROT_FWD, AudioScratchBuffers::IR_SUM_L, AudioScratchBuffers::IR_SUM_L_FWD, AudioScratchBuffers::IR_SUM_R, AudioScratchBuffers::IR_SUM_R_FWD, HRTFThreadData::last_fwd, HRTFThreadData::last_pos, SceneData::LOADED_AUDIO_PV, SceneData::LOADED_AUDIO_PV_FLAG, MAX_SAMPLES, Skeleton::neck, NUM_PARTITIONS, AudioScratchBuffers::padded_len, player, Spring::pos, AudioProbeWeights::probes, Camera::right, rot(), rotate_sh(), rotation_matrix_r(), Globals::scene_data, SH_MAX, Player::skeleton, AudioScratchBuffers::STATIC_HRTF_L_FWD, AudioScratchBuffers::STATIC_HRTF_R_FWD, Camera::up, update_player_ir(), HRTFThreadData::w, and AudioProbeWeights::weights.

Referenced by hrtf_worker(), and update_player_ir().

◆ hrtf_worker()

◆ rotate_sh()

void rotate_sh ( float * OUT,
float SH[SH_MAX],
mat3 rot )

Converts a position to local OBB space and returns the coord as if it was a texture from \(0 \rightarrow 1\).

Rotates the SH.

\begin{align} X_i &= \mathrm{IR[]} \\ l &= \mathrm{IR\ Length} \\ c_l &= \mathrm{Complex\ Length} \\ M^r &= \mathrm{Player\ Rotation} \\ b &= \mathrm{Block\ Size} \\ p &= \mathrm{Partiton\ Count} \\ P_o &= \mathrm{Partitions\ Out} \\ X_r &= \sum_{i=0}^{l}(X_iM^r)\\ X_f &= \mathrm{FFT}(X_r) \\ X_t &= \sum_{s=0}^{c_l}(a + bi)(c + di) = (ac - bd) + (ad + bc)i \\ X_o &= ||\mathrm{IFFT}(X_t)|| \\ \end{align}

\[\begin{aligned} \textbf{for } i \in{}[0,p) \textbf{ do}\\\\ \textbf{for } k \in{}[0,b) \textbf{ do}\\\\ Y_i[k] = X_o[i * b + k] \\\\ P_o = \mathrm{FFT}(Y_i) \\\\ \end{aligned} \]

Parameters
OUTThe array of rotated SH.
SHThe input SH.
rotThe rotation matrix.
Author
John Hable.

Definition at line 234 of file audio_ir.c.

References rot(), rotate_sh(), and SH_MAX.

Referenced by rotate_sh(), and update_player_ir().

◆ fft_channels()

void fft_channels ( ConvolverNode * node,
bool crossfading )

FFTs the newest audio chunk with the partitioned overlap-add buffer.

Applies an impulse response filter via discrete convolution.

Parameters
nodeThe convolver node that is processing the audio.
crossfadingIf we are currently crossfading into a new IR this frame.

FFTs the newest audio chunk with the partitioned overlap-add buffer.

\[(x * h)[n] = \sum_{m=-\infty}^{\infty} x[m] \, h[n - m] \]

Definition at line 138 of file audio_ir.c.

References ConvolverNode::AUDIO_HISTORY, ConvolverNode::bwd_plan, ConvolverNode::complex_len, CONVOLVER_NODE, fft_channels(), ConvolverNode::fwd_plan, ConvolverNode::history_head, ConvolverNode::ir, ConvolverNode::LEFT_OUT, ConvolverNode::MONO_FWD, NUM_PARTITIONS, NUM_PARTITIONS_MAX, ConvolverNode::padded_len, ConvolverNode::prev_ir, ConvolverNode::PREV_LEFT_OUT, ConvolverNode::PREV_RIGHT_OUT, ConvolverNode::PREV_SUM_L, ConvolverNode::PREV_SUM_R, ConvolverNode::RIGHT_OUT, ConvolverNode::SUM_L, ConvolverNode::SUM_R, and X.

Referenced by convolver_node_process_pcm_frames(), and fft_channels().

◆ evaluate_sh()

void evaluate_sh ( vec3 dir,
float SH[SH_MAX] )

Evaluates 9 spherical harmonics based on direction.

Parameters
dirThe direction to evaluate.
SHThe output SH array.

Definition at line 51 of file audio_ir.c.

References evaluate_sh(), SH_MAX, vec3::x, vec3::y, and vec3::z.

Referenced by evaluate_sh(), and process_probe_chunk().

◆ load_hrtf_from_binary()

◆ init_hrtf_worker_thread()

◆ delete_hrtf_worker_thread()

void delete_hrtf_worker_thread ( HRTFThreadData * td)

Cleans up the worker thread that convolves the audio probes with the HRTF.

Parameters
tdThe worker thread data.

Definition at line 543 of file audio_ir.c.

References delete_hrtf_worker_thread(), HRTFThreadData::mutex, NUM_PARTITIONS, PARTITION_BUFFERS, HRTFThreadData::stop_requested, HRTFThreadData::t, HRTFThreadData::tables, and HRTFThreadData::work_cond.

Referenced by delete_hrtf_worker_thread(), and main().

Variable Documentation

◆ AUDIO_BAND_FREQ

const float AUDIO_BAND_FREQ[] = {125.0f, 250.0f, 500.0f, 1000.0f, 2000.0f, 4000.0f}

Audio frequencies for each band for audio probe baking.

Definition at line 101 of file engine_types.h.

Referenced by generate_synthetic_IR_tail().