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

Sound effects and music on top of SDL3 (client only). More...

Classes

class  AudioDevice
 The default audio output and the sounds it plays. More...
 
class  AudioError
 Thrown when the audio device cannot be opened or a sound cannot be loaded. More...
 
class  EventSounds
 Plays sounds when events are published on an event bus, so gameplay code never calls audio. More...
 
struct  SoundOptions
 How EventSounds plays the sound of an event. More...
 
struct  Volumes
 Positions of the three volume sliders of a settings menu, from 0 (silent) to 1. More...
 

Typedefs

using SoundId = std::size_t
 Identifier of a sound loaded by an AudioDevice, given by AudioDevice::load().
 

Enumerations

enum class  Channel : std::uint8_t { Effects , Music }
 Group of sounds whose volume is set together. More...
 

Functions

std::pair< float, float > positional (Vec2 position, Vec2 camera_center, float view_half_width) noexcept
 Stereo pan and distance gain for a world-space sound relative to a camera view.
 
std::string_view name () noexcept
 Name of the module, used to check that it is linked.
 

Detailed Description

Sound effects and music on top of SDL3 (client only).

Typedef Documentation

◆ SoundId

using aegis2d::audio::SoundId = typedef std::size_t

Identifier of a sound loaded by an AudioDevice, given by AudioDevice::load().

Enumeration Type Documentation

◆ Channel

enum class aegis2d::audio::Channel : std::uint8_t
strong

Group of sounds whose volume is set together.

Enumerator
Effects 

Short sounds of the game: shots, explosions, menus.

Music 

Background music.

Function Documentation

◆ name()

std::string_view aegis2d::audio::name ( )
noexcept

Name of the module, used to check that it is linked.

Returns
"audio", a view of a static string.

◆ positional()

std::pair< float, float > aegis2d::audio::positional ( Vec2  position,
Vec2  camera_center,
float  view_half_width 
)
inlinenoexcept

Stereo pan and distance gain for a world-space sound relative to a camera view.

The camera center and half-width define the reference: a source at the center returns {0, 1} (no pan, full volume); one at the edge returns {±1, 0} (fully panned, silent). Sources beyond the edge are clamped.

const auto [pan, gain] = audio::positional(explosion.position, camera.center(),
camera.visible().size().x * 0.5F);
audio.play(explosion_sound, Channel::Effects, pan, gain);
@ Effects
Short sounds of the game: shots, explosions, menus.
std::pair< float, float > positional(Vec2 position, Vec2 camera_center, float view_half_width) noexcept
Stereo pan and distance gain for a world-space sound relative to a camera view.
Definition audio.hpp:176
Parameters
positionWorld position of the sound.
camera_centerWorld position the camera centers on (Camera::center()).
view_half_widthHalf-width of the visible area in world units (Camera::visible() width / 2), used as the maximum range: sounds this far or more from the center are silent. Pass a larger value to hear sounds beyond the view.
Returns
{pan, gain}: pan in [-1, 1], gain in [0, 1].