Kohi Game Engine
audio_utils.h File Reference
#include "core_audio_types.h"
#include "defines.h"

Go to the source code of this file.

Functions

KAPI kaudio_space string_to_audio_space (const char *str)
 Parses the audio space from the given string. Defaults to 2D if not valid. More...
 
KAPI const char * audio_space_to_string (kaudio_space space)
 Gets the string representation of the given sound space. NOTE: string is constant and does not need to be freed. More...
 
KAPI kaudio_attenuation_model string_to_attenuation_model (const char *str)
 Parses the attenuation model from the given string. Defaults to linear if not valid. More...
 
KAPI const char * attenuation_model_to_string (kaudio_attenuation_model model)
 Gets the string representation of the given attenuation model. NOTE: string is constant and does not need to be freed. More...
 
KAPI f32 calculate_spatial_gain (f32 distance, f32 inner_radius, f32 outer_radius, f32 falloff_factor, kaudio_attenuation_model model)
 Computes spatial gain based on position, radius and attenuation model parameters. More...
 
KAPI i16kaudio_downmix_stereo_to_mono (const i16 *stereo_data, u32 sample_count)
 Downmixes the provided stereo data to mono data by averaging the left and right channels and scaling it to fit within an i16. More...
 

Function Documentation

◆ attenuation_model_to_string()

KAPI const char* attenuation_model_to_string ( kaudio_attenuation_model  model)

Gets the string representation of the given attenuation model. NOTE: string is constant and does not need to be freed.

Parameters
modelThe model to convert.
Returns
the string representation of the given attenuation model.

◆ audio_space_to_string()

KAPI const char* audio_space_to_string ( kaudio_space  space)

Gets the string representation of the given sound space. NOTE: string is constant and does not need to be freed.

Parameters
spaceThe audio space to convert.
Returns
the string representation of the given audio space.

◆ calculate_spatial_gain()

KAPI f32 calculate_spatial_gain ( f32  distance,
f32  inner_radius,
f32  outer_radius,
f32  falloff_factor,
kaudio_attenuation_model  model 
)

Computes spatial gain based on position, radius and attenuation model parameters.

Parameters
distanceThe distance between the listener and the center point of the sound in the world.
inner_radiusThe inner radius around the sound's center point. A listener inside this radius experiences the volume at 100%.
outer_radiusThe outer radius around the sound's center point. A listener outside this radius experiences the volume at 0%.
falloff_factorThe falloff factor used for exponential falloff. Ignored for other models.
modelThe model to use for the sound attenuation.
Returns
The final gain of the sound based on the supplied parameters, before being mixed with volume.

◆ kaudio_downmix_stereo_to_mono()

KAPI i16* kaudio_downmix_stereo_to_mono ( const i16 stereo_data,
u32  sample_count 
)

Downmixes the provided stereo data to mono data by averaging the left and right channels and scaling it to fit within an i16.

Parameters
stereo_dataThe raw interleaved sample data in stereo format.
sample_countThe total number of samples.
Returns
A dynamically-allocated array of downmixed mono data on success; otherwise 0/null.

◆ string_to_attenuation_model()

KAPI kaudio_attenuation_model string_to_attenuation_model ( const char *  str)

Parses the attenuation model from the given string. Defaults to linear if not valid.

Parameters
strThe string to parse.
Returns
The attenuation model.

◆ string_to_audio_space()

KAPI kaudio_space string_to_audio_space ( const char *  str)

Parses the audio space from the given string. Defaults to 2D if not valid.

Parameters
strThe string to parse.
Returns
The sound space.