|
Aegis2D
Modular C++26 2D game engine for networked games
|
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. | |
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.
|
noexcept |
The same volumes, each one brought into [0, 1]; not-a-number becomes 1.
|
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.
| channel | Channel of the sound. |
| 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.
| settings | Settings read with platform::read_settings() or core::Config. |
| section | Dotted path given to 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.
| settings | Settings to update, then saved with core::Config::save(). |
| section | Dotted path of the object holding the sliders; empty for the root. |
|
noexcept |
Slider of a channel.
| channel | Channel to read. |
| float aegis2d::audio::Volumes::effects = 1.0F |
Sounds of Channel::Effects.
| float aegis2d::audio::Volumes::master = 1.0F |
Every sound.
| float aegis2d::audio::Volumes::music = 1.0F |
Sounds of Channel::Music.