Kohi Game Engine
audio_system.h File Reference
#include "audio/audio_types.h"
#include "defines.h"

Go to the source code of this file.

Data Structures

struct  audio_system_config
 

Macros

#define MAX_AUDIO_CHANNELS   16
 

Typedefs

typedef struct audio_system_config audio_system_config
 

Functions

KAPI b8 audio_system_initialize (u64 *memory_requirement, void *state, void *config)
 Initializes the audio system. Should be called twice; once to get the memory requirement (passing state=0), and a second time passing an allocated block of memory to actually initialize the system. More...
 
KAPI void audio_system_shutdown (void *state)
 Shuts down the audio system. More...
 
KAPI b8 audio_system_update (void *state, struct frame_data *p_frame_data)
 Updates the audio system. Should happen once an update cycle. More...
 
KAPI b8 audio_system_listener_orientation_set (vec3 position, vec3 forward, vec3 up)
 
KAPI struct audio_fileaudio_system_chunk_load (const char *path)
 Attempts to load a sound chunk at the given path. Returns a pointer to a loaded sound. This dynamically allocates memory, so make sure to call audio_system_close() on it when done. More...
 
KAPI struct audio_fileaudio_system_stream_load (const char *path)
 Attempts to load a audio stream file at the given path. Returns a pointer to a loaded music. This dynamically allocates memory, so make sure to call audio_system_close() on it when done. More...
 
KAPI void audio_system_close (struct audio_file *file)
 Closes the given sound, releasing all internal resources. More...
 
KAPI void audio_system_master_volume_set (f32 volume)
 Sets the master volume level. This affects all channels overall. More...
 
KAPI void audio_system_master_volume_query (f32 *out_volume)
 Queries the master volume. More...
 
KAPI b8 audio_system_channel_volume_set (i8 channel_id, f32 volume)
 Sets the volume for the given channel id. More...
 
KAPI b8 audio_system_channel_volume_query (i8 channel_id, f32 *out_volume)
 Queries the given channel's volume volume. More...
 
KAPI b8 audio_system_channel_play (i8 channel_id, struct audio_file *file, b8 loop)
 
KAPI b8 audio_system_channel_emitter_play (i8 channel_id, struct audio_emitter *emitter)
 
KAPI void audio_system_channel_stop (i8 channel_id)
 
KAPI void audio_system_channel_pause (i8 channel_id)
 
KAPI void audio_system_channel_resume (i8 channel_id)
 

Macro Definition Documentation

◆ MAX_AUDIO_CHANNELS

#define MAX_AUDIO_CHANNELS   16

The maximum number of individually-controlled channels of audio available, each with separate volume control. These are all nested under a master audio volume.

Typedef Documentation

◆ audio_system_config

Function Documentation

◆ audio_system_channel_emitter_play()

KAPI b8 audio_system_channel_emitter_play ( i8  channel_id,
struct audio_emitter emitter 
)

Plays spatially-oriented 3d sound from the context of an audio_emitter. The emitter should already have a loaded sound associated with it. In addition, if the emitter is moving, it should be updated per frame with a call to audio_system_emitter_update().

Parameters
channel_idThe id of the channel to play through.
emitterA pointer to an emitter to use for playback.
Returns
True on success; otherwise false.

◆ audio_system_channel_pause()

KAPI void audio_system_channel_pause ( i8  channel_id)

◆ audio_system_channel_play()

KAPI b8 audio_system_channel_play ( i8  channel_id,
struct audio_file file,
b8  loop 
)

Plays the provided sound on the channel with the given id. Note that this is effectively "2d" sound, meant for sounds which don't exist in the world and should be played globally (i.e. UI sound effects).

Parameters
channel_idThe id of the channel to play the sound on.
soundThe sound to be played.
loopIndicates if the sound should loop.
Returns
True on success; otherwise false.

◆ audio_system_channel_resume()

KAPI void audio_system_channel_resume ( i8  channel_id)

◆ audio_system_channel_stop()

KAPI void audio_system_channel_stop ( i8  channel_id)

Stops the given channel id.

Parameters
channel_idThe id of the channel to be stopped. If -1 is passed, all channels are stopped.
Returns
True on success; otherwise false.

◆ audio_system_channel_volume_query()

KAPI b8 audio_system_channel_volume_query ( i8  channel_id,
f32 out_volume 
)

Queries the given channel's volume volume.

Parameters
channel_idThe id of the channel to query. -1 cannot be used here.
volumeA pointer to hold the volume.
Returns
True on success; otherwise false.

◆ audio_system_channel_volume_set()

KAPI b8 audio_system_channel_volume_set ( i8  channel_id,
f32  volume 
)

Sets the volume for the given channel id.

Parameters
channel_idThe id of the channel to adjust volume for. @volume The volume to set. Clamped to a range of [0.0-1.0].
Returns
True on success; otherwise false.

◆ audio_system_chunk_load()

KAPI struct audio_file* audio_system_chunk_load ( const char *  path)

Attempts to load a sound chunk at the given path. Returns a pointer to a loaded sound. This dynamically allocates memory, so make sure to call audio_system_close() on it when done.

Parameters
pathThe full path to the asset to be loaded.
Returns
A pointer to an audio_sound one success; otherwise null/0.

◆ audio_system_close()

KAPI void audio_system_close ( struct audio_file file)

Closes the given sound, releasing all internal resources.

Parameters
fileA pointer to the sound file to be closed.

◆ audio_system_initialize()

KAPI b8 audio_system_initialize ( u64 memory_requirement,
void *  state,
void *  config 
)

Initializes the audio system. Should be called twice; once to get the memory requirement (passing state=0), and a second time passing an allocated block of memory to actually initialize the system.

Parameters
memory_requirementA pointer to hold the memory requirement as it is calculated.
stateA block of memory to hold the state or, if gathering the memory requirement, 0.
configThe configuration (audio_system_config) for this system.
Returns
True on success; otherwise false.

◆ audio_system_listener_orientation_set()

KAPI b8 audio_system_listener_orientation_set ( vec3  position,
vec3  forward,
vec3  up 
)

Sets the orientation of the listener. Typically linked to the current camera in the world.

Parameters
positionThe position of the listener.
forwardThe listener's forward vector.
upThe listener's up vector.
Returns
True on success; otherwise false.

◆ audio_system_master_volume_query()

KAPI void audio_system_master_volume_query ( f32 out_volume)

Queries the master volume.

Parameters
volumeA pointer to hold the volume.

◆ audio_system_master_volume_set()

KAPI void audio_system_master_volume_set ( f32  volume)

Sets the master volume level. This affects all channels overall.

Parameters
volumeThe volume to set. Clamed to a range of [0.0-1.0].

◆ audio_system_shutdown()

KAPI void audio_system_shutdown ( void *  state)

Shuts down the audio system.

Parameters
stateThe state block of memory.

◆ audio_system_stream_load()

KAPI struct audio_file* audio_system_stream_load ( const char *  path)

Attempts to load a audio stream file at the given path. Returns a pointer to a loaded music. This dynamically allocates memory, so make sure to call audio_system_close() on it when done.

Parameters
pathThe full path to the asset to be loaded.
Returns
A pointer to an audio_music one success; otherwise null/0.

◆ audio_system_update()

KAPI b8 audio_system_update ( void *  state,
struct frame_data p_frame_data 
)

Updates the audio system. Should happen once an update cycle.