Brenta Engine 1.0
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::AudioFile GetAudioFile (Types::AudioName name)
 Get an audio file.
 
static SDL_AudioStream * GetStream (Types::StreamName name)
 Get an audio stream.
 
static void LoadAudio (Types::AudioName name, std::string path)
 Load an audio file.
 
static void CreateStream (Types::StreamName)
 Create an audio stream.
 
static void PlayAudio (Types::AudioName, Types::StreamName="default")
 Play an audio file.
 
static void SetVolume (Types::StreamName name, int volume)
 Set the volume of a stream.
 
static void PauseStream (Types::StreamName name)
 Pause a stream.
 
static void ResumeStream (Types::StreamName name)
 Resume a stream.
 
static void ClearStream (Types::StreamName name)
 Stop a stream.
 

Static Public Attributes

static std::unordered_map< Types::AudioName, Types::AudioFileaudiofiles
 Map of audio files.
 
static std::unordered_map< Types::StreamName, 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

◆ ClearStream()

void Audio::ClearStream ( Types::StreamName 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 157 of file engine_audio.cpp.

◆ CreateStream()

void Audio::CreateStream ( Types::StreamName 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 101 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 53 of file engine_audio.cpp.

◆ GetAudioFile()

Types::AudioFile Audio::GetAudioFile ( Types::AudioName 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 117 of file engine_audio.cpp.

◆ GetStream()

SDL_AudioStream * Audio::GetStream ( Types::StreamName 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 127 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 40 of file engine_audio.cpp.

◆ LoadAudio()

void Audio::LoadAudio ( Types::AudioName 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 67 of file engine_audio.cpp.

◆ PauseStream()

void Audio::PauseStream ( Types::StreamName 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 171 of file engine_audio.cpp.

◆ PlayAudio()

void Audio::PlayAudio ( Types::AudioName audio_name,
Types::StreamName 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 84 of file engine_audio.cpp.

◆ ResumeStream()

void Audio::ResumeStream ( Types::StreamName 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 185 of file engine_audio.cpp.

◆ SetVolume()

void Audio::SetVolume ( Types::StreamName 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 137 of file engine_audio.cpp.

Field Documentation

◆ audiofiles

std::unordered_map< Types::AudioName, Types::AudioFile > Audio::audiofiles
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 105 of file engine_audio.hpp.

◆ streams

std::unordered_map< Types::StreamName, 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 117 of file engine_audio.hpp.


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