Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::audio::Volumes Struct Reference

Positions of the three volume sliders of a settings menu, from 0 (silent) to 1. More...

#include <aegis2d/audio/volume.hpp>

Public Member Functions

float slider (Channel channel) const noexcept
 Slider of a channel.
 
float gain (Channel channel) const noexcept
 Gain applied to the samples of a channel.
 
Volumes clamped () const noexcept
 The same volumes, each one brought into [0, 1]; not-a-number becomes 1.
 
void save (core::Config &settings, std::string_view section) const
 Writes the sliders into the player's settings.
 
void load (const core::Config &settings, std::string_view section)
 Reads the sliders written by save().
 

Public Attributes

float master = 1.0F
 Every sound.
 
float music = 1.0F
 Sounds of Channel::Music.
 
float effects = 1.0F
 Sounds of Channel::Effects.
 

Detailed Description

Positions of the three volume sliders of a settings menu, from 0 (silent) to 1.

The master slider scales every sound; the music and effects sliders scale only their own channel, so a player can turn the music down to hear the effects better, or mute it. Positions are mapped to a gain by gain(), whose curve makes equal slider steps sound like equal changes of loudness.

Member Function Documentation

◆ clamped()

Volumes aegis2d::audio::Volumes::clamped ( ) const
noexcept

The same volumes, each one brought into [0, 1]; not-a-number becomes 1.

Returns
The clamped volumes.

◆ gain()

float aegis2d::audio::Volumes::gain ( Channel  channel) const
noexcept

Gain applied to the samples of a channel.

master² × channel²: half way down is about a quarter of the amplitude (-12 dB), which sounds about half as loud. Positions outside [0, 1] count as the nearest bound.

Parameters
channelChannel of the sound.
Returns
From 0 (silent) to 1 (as recorded).

◆ load()

void aegis2d::audio::Volumes::load ( const core::Config &  settings,
std::string_view  section 
)

Reads the sliders written by save().

A slider missing from the settings, or which is not a number, keeps its value (logged as a warning when it is not a number); values outside [0, 1] are clamped.

Parameters
settingsSettings read with platform::read_settings() or core::Config.
sectionDotted path given to save().

◆ save()

void aegis2d::audio::Volumes::save ( core::Config &  settings,
std::string_view  section 
) const

Writes the sliders into the player's settings.

{"audio": {"master": 1.0, "music": 0.5, "effects": 1.0}} for the section "audio"; other settings are left as they are.

Parameters
settingsSettings to update, then saved with core::Config::save().
sectionDotted path of the object holding the sliders; empty for the root.

◆ slider()

float aegis2d::audio::Volumes::slider ( Channel  channel) const
noexcept

Slider of a channel.

Parameters
channelChannel to read.
Returns
music or effects.

Member Data Documentation

◆ effects

float aegis2d::audio::Volumes::effects = 1.0F

Sounds of Channel::Effects.

◆ master

float aegis2d::audio::Volumes::master = 1.0F

Every sound.

◆ music

float aegis2d::audio::Volumes::music = 1.0F

Sounds of Channel::Music.


The documentation for this struct was generated from the following file: