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

Audio subsystem. More...

#include <audio.hpp>

Inheritance diagram for brenta::audio:
brenta::subsystem

Data Structures

class  builder
 

Public Types

enum class  error : int {
  init_from_file , stream_not_found , sound_not_found , stream_init ,
  stream_stop , stream_start
}
 
- Public Types inherited from brenta::subsystem
using error = std::string
 

Public Member Functions

std::expected< void, subsystem::error > initialize () override
 Initialize the audio subsystem.
 
std::expected< void, subsystem::error > terminate () override
 Terminate the audio system.
 
std::string name () override
 Returns the name of the sybsystem.
 
bool is_initialized () override
 Returns true if the subsystem is initialized.
 
- Public Member Functions inherited from brenta::subsystem

Static Public Member Functions

static audioinstance ()
 
static std::expected< void, audio::error > load (const types::sound_id_t &sound_id, const std::string &path, const types::stream_id_t &stream_id="default")
 Load a sound from path on a stream.
 
static std::expected< void, audio::error > play (const types::sound_id_t &id)
 Play a sound on its stream.
 
static std::expected< void, audio::error > create_stream (const types::stream_id_t &id)
 
static types::stream_t * get_stream (const types::stream_id_t &id)
 
static std::expected< void, audio::error > stream_stop (const types::stream_id_t &id)
 
static std::expected< void, audio::error > stream_start (const types::stream_id_t &id)
 
static std::expected< void, audio::error > stream_set_volume (const types::stream_id_t &id, float volume)
 Set the volume of a stream.
 

Static Public Attributes

static std::unordered_map< types::sound_id_t, types::sound_t > sounds
 Map of sound files.
 
static std::unordered_map< types::stream_id_t, types::stream_t > streams
 Map of audio streams.
 
static const std::string subsystem_name = "audio"
 

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, start and stop streams. The audio subsystem needs to be initialized and destroyed via initialize() and terminate(). Audio files and streams are stored in maps and are identified by a string id.

Definition at line 43 of file audio.hpp.

Member Enumeration Documentation

◆ error

enum class brenta::audio::error : int
strong

Definition at line 181 of file audio.hpp.

Member Function Documentation

◆ create_stream()

std::expected< void, audio::error > audio::create_stream ( const types::stream_id_t & id)
static

Definition at line 150 of file audio.cpp.

◆ get_stream()

types::stream_t * audio::get_stream ( const types::stream_id_t & id)
static

Definition at line 170 of file audio.cpp.

◆ initialize()

std::expected< void, subsystem::error > audio::initialize ( )
overridevirtual

Initialize the audio subsystem.

This function initializes the audio subsystem of the engine. It creates a default stream called "default".

Implements brenta::subsystem.

Definition at line 28 of file audio.cpp.

◆ instance()

audio & audio::instance ( )
static

Definition at line 96 of file audio.cpp.

◆ is_initialized()

bool audio::is_initialized ( )
overridevirtual

Returns true if the subsystem is initialized.

Implements brenta::subsystem.

Definition at line 87 of file audio.cpp.

◆ load()

std::expected< void, audio::error > audio::load ( const types::sound_id_t & sound_id,
const std::string & path,
const types::stream_id_t & stream_id = "default" )
static

Load a sound from path on a stream.

Automatically creates the stream if it does not exist.

Definition at line 103 of file audio.cpp.

◆ name()

std::string audio::name ( )
overridevirtual

Returns the name of the sybsystem.

Implements brenta::subsystem.

Definition at line 82 of file audio.cpp.

◆ play()

std::expected< void, audio::error > audio::play ( const types::sound_id_t & id)
static

Play a sound on its stream.

Definition at line 136 of file audio.cpp.

◆ stream_set_volume()

std::expected< void, audio::error > audio::stream_set_volume ( const types::stream_id_t & id,
float volume )
static

Set the volume of a stream.

1.0 is default, 2.0 is double, 0.5 is half.

Definition at line 180 of file audio.cpp.

◆ stream_start()

std::expected< void, audio::error > audio::stream_start ( const types::stream_id_t & id)
static

Definition at line 220 of file audio.cpp.

◆ stream_stop()

std::expected< void, audio::error > audio::stream_stop ( const types::stream_id_t & id)
static

Definition at line 198 of file audio.cpp.

◆ terminate()

std::expected< void, subsystem::error > audio::terminate ( )
overridevirtual

Terminate the audio system.

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

Implements brenta::subsystem.

Definition at line 65 of file audio.cpp.

Field Documentation

◆ sounds

std::unordered_map< types::sound_id_t, types::sound_t > audio::sounds
static

Map of sound files.

This map contains all the sound files loaded by the engine. The key is the id of the sound file, the value is the struct sound_t.

Definition at line 53 of file audio.hpp.

◆ streams

std::unordered_map< types::stream_id_t, types::stream_t > audio::streams
static

Map of audio streams.

This map contains all the audio streams created by the engine. The key is the id of the stream, the value is a stream type. The engine creates a default stream called "default".

Definition at line 62 of file audio.hpp.

◆ subsystem_name

const std::string audio::subsystem_name = "audio"
static

Definition at line 64 of file audio.hpp.


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