Brenta Engine 1.1
Loading...
Searching...
No Matches
brenta::audio Class Reference

Audio subsystem. More...

#include <engine_audio.hpp>

Static Public Member Functions

static void init ()
 Initialize the audio system.
 
static void destroy ()
 Destroy the audio system.
 
static types::audio_file_t get_audio_file (types::audio_name_t name)
 Get an audio file.
 
static SDL_AudioStream * get_stream (types::stream_name_t name)
 Get an audio stream.
 
static void load_audio (types::audio_name_t name, std::string path)
 Load an audio file.
 
static void create_stream (types::stream_name_t)
 Create an audio stream.
 
static void play_audio (types::audio_name_t, types::stream_name_t="default")
 Play an audio file.
 
static void set_volume (types::stream_name_t name, int volume)
 Set the volume of a stream.
 
static void pause_stream (types::stream_name_t name)
 Pause a stream.
 
static void resume_stream (types::stream_name_t name)
 Resume a stream.
 
static void clear_stream (types::stream_name_t name)
 Stop a stream.
 

Static Public Attributes

static std::unordered_map< types::audio_name_t, types::audio_file_taudio_files
 Map of audio files.
 
static std::unordered_map< types::stream_name_t, SDL_AudioStream * > streams
 Map of audio streams.
 

Detailed Description

Audio subsystem.

This class contains the audio subsystem of the engine. It is used to load audio files, create audio streams, play audio files on streams, set the volume of streams, pause, resume and stop streams. The audio system needs to be initialized and destroyed by the engine. Audio files and streamd are stored in maps and are identified by this name.

Definition at line 93 of file engine_audio.hpp.

Member Function Documentation

◆ clear_stream()

void audio::clear_stream ( types::stream_name_t name)
static

Stop a stream.

This function stops the stream with the given name. If the stream does not exist, it does nothing.

Parameters
nameThe name of the stream

Definition at line 156 of file engine_audio.cpp.

◆ create_stream()

void audio::create_stream ( types::stream_name_t name)
static

Create an audio stream.

This function creates an audio stream with the given name. If a stream with the same name already exists, it does nothing.

Parameters
nameThe name of the stream

Definition at line 100 of file engine_audio.cpp.

◆ destroy()

void audio::destroy ( )
static

Destroy the audio system.

This function frees all audio streams and audio files, and closes the audio system.

Definition at line 52 of file engine_audio.cpp.

◆ get_audio_file()

types::audio_file_t audio::get_audio_file ( types::audio_name_t name)
static

Get an audio file.

This function returns the audio file with the given name. If the audio file does not exist, it returns an empty AudioFile.

Parameters
nameThe name of the audio file
Returns
The audio file

Definition at line 116 of file engine_audio.cpp.

◆ get_stream()

SDL_AudioStream * audio::get_stream ( types::stream_name_t name)
static

Get an audio stream.

This function returns the audio stream with the given name. If the audio stream does not exist, it returns nullptr.

Parameters
nameThe name of the audio stream
Returns
The audio stream

Definition at line 126 of file engine_audio.cpp.

◆ init()

void audio::init ( )
static

Initialize the audio system.

This function initializes the audio system of the engine. It is called automatically by the engine when the game is started. It creates a default stream called "default".

Definition at line 39 of file engine_audio.cpp.

◆ load_audio()

void audio::load_audio ( types::audio_name_t name,
std::string path )
static

Load an audio file.

This function loads an audio file from the given path and stores it in the audiofiles map with the given name.

Parameters
nameThe name of the audio file
pathThe path to the audio file

Definition at line 66 of file engine_audio.cpp.

◆ pause_stream()

void audio::pause_stream ( types::stream_name_t name)
static

Pause a stream.

This function pauses the stream with the given name. If the stream does not exist, it does nothing.

Parameters
nameThe name of the stream

Definition at line 170 of file engine_audio.cpp.

◆ play_audio()

void audio::play_audio ( types::audio_name_t audio_name,
types::stream_name_t stream_name = "default" )
static

Play an audio file.

This function plays the audio file with the given name on the stream with the given name. If the stream does not exist, it creates a new stream with the given name. If the audio file does not exist, it does nothing.

Parameters
audio_nameThe name of the audio file
stream_nameThe name of the stream

Definition at line 83 of file engine_audio.cpp.

◆ resume_stream()

void audio::resume_stream ( types::stream_name_t name)
static

Resume a stream.

This function resumes the stream with the given name. If the stream does not exist, it does nothing.

Parameters
nameThe name of the stream

Definition at line 184 of file engine_audio.cpp.

◆ set_volume()

void audio::set_volume ( types::stream_name_t name,
int volume )
static

Set the volume of a stream.

This function sets the volume of the stream with the given name. If the stream does not exist, it does nothing.

Parameters
nameThe name of the stream
volumeThe volume of the stream

Definition at line 136 of file engine_audio.cpp.

Field Documentation

◆ audio_files

std::unordered_map< types::audio_name_t, types::audio_file_t > audio::audio_files
static

Map of audio files.

This map contains all the audio files loaded by the engine. The key is the name of the audio file provided by the user, the value is the struct AudioFile containing the path to the audio file, the audio buffer, the length of the audio buffer and the audio format.

Definition at line 106 of file engine_audio.hpp.

◆ streams

std::unordered_map< types::stream_name_t, SDL_AudioStream * > audio::streams
static

Map of audio streams.

This map contains all the audio streams created by the engine. The key is the name of the stream provided by the user, the value is the SDL_AudioStream pointer. A stream can only play one audio file at a time, so multiple streams need to be created to play multiple audio files at the same time. The engine creates a default stream called "default", the handling of the streams is left to the programmer.

Definition at line 118 of file engine_audio.hpp.


The documentation for this class was generated from the following files: