ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
sound.h File Reference

Sound module for the ASW library. More...

#include <cstdint>
#include "./geometry.h"
#include "./types.h"
Include dependency graph for sound.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  asw::sound::Attenuation
 Distance settings for positional sounds, in world units (pixels). More...
 
struct  asw::sound::PlayOptions
 Options for playing a sound. More...
 
class  asw::sound::SoundHandle
 A handle to a playing sound, used to change it while it plays. More...
 

Namespaces

namespace  asw
 
namespace  asw::sound
 

Enumerations

enum class  asw::sound::Bus : uint8_t {
  asw::sound::Sfx , asw::sound::Music , asw::sound::Ambient , asw::sound::Ui ,
  asw::sound::Voice , asw::sound::Count
}
 Mix buses. Each sound plays on one bus, and each bus has its own volume and can be ducked. More...
 
enum class  asw::sound::Rolloff : uint8_t { asw::sound::Linear , asw::sound::Inverse , asw::sound::InverseSquare }
 How volume falls off with distance for positional sounds. More...
 
enum class  asw::sound::SpatialMode : uint8_t { asw::sound::Stereo , asw::sound::Surround }
 How positional sounds are placed on the speakers. More...
 

Functions

bool asw::sound::_init ()
 Initialize the sound module. Called automatically by asw::core::init().
 
void asw::sound::_update ()
 Update fades, ducking and positional sounds. Called automatically by asw::core::update().
 
void asw::sound::_shutdown ()
 Shut down the sound module. Called automatically by asw::core::shutdown().
 
MIX_Mixer * asw::sound::get_mixer ()
 Get the SDL mixer device.
 
uint32_t asw::sound::_get_session ()
 Get the number of times the sound module has been shut down.
 
SoundHandle asw::sound::play (const asw::Sample &sample, float volume=1.0F, float pan=0.0F, bool loop=false)
 Play a sample.
 
SoundHandle asw::sound::play (const asw::Sample &sample, const PlayOptions &options)
 Play a sample with options.
 
SoundHandle asw::sound::play_positional (const asw::Sample &sample, const Vec2< float > &position, const PlayOptions &options={})
 Play a sample at a point in the world. It is panned, faded and pitch shifted relative to the listener, and keeps updating while it plays.
 
SoundHandle asw::sound::play_at (const asw::Sample &sample, float x, float volume=1.0F)
 Play a sample panned by where it happens on screen. Sounds pan towards the side they are on and fade out once they are off screen, going silent a full screen width past the edge.
 
SoundHandle asw::sound::play_at (const asw::Sample &sample, float x, const PlayOptions &options)
 Play a sample panned by where it happens on screen, with options. Works like play_at above, so pitch, variation, bus and priority can be set too. The pan is worked out once when the sound starts.
 
void asw::sound::set_listener (const Vec2< float > &position, const Vec2< float > &velocity={ 0.0F, 0.0F })
 Set where the listener is, usually the player or camera centre.
 
Vec2< float > asw::sound::get_listener ()
 Get the listener position.
 
void asw::sound::set_spatial_mode (SpatialMode mode)
 Choose how positional sounds are placed on the speakers.
 
void asw::sound::set_doppler (float factor, float speed_of_sound=3000.0F)
 Set how strong doppler pitch shift is.
 
void asw::sound::set_bus_volume (Bus bus, float volume)
 Set a bus volume.
 
float asw::sound::get_bus_volume (Bus bus)
 Get a bus volume.
 
void asw::sound::duck (Bus bus, float gain, float hold_s, float fade_s=0.2F)
 Turn a bus down for a while, for example music under dialogue or everything under a big explosion. Overlapping ducks keep the deepest level and the longest hold.
 
void asw::sound::play_music (const asw::Music &sample, float volume=1.0F, float fade_in_s=0.0F)
 Play a music sample.
 
void asw::sound::stop_music (float fade_out_s=0.0F)
 Stop the currently playing music.
 
void asw::sound::pause_music ()
 Pause the currently playing music.
 
void asw::sound::resume_music ()
 Resume paused music.
 
bool asw::sound::is_music_playing ()
 Check if music is currently playing.
 
bool asw::sound::is_music_paused ()
 Check if music is paused.
 
void asw::sound::set_master_volume (float volume)
 Set the master volume multiplier (affects all audio).
 
void asw::sound::set_sfx_volume (float volume)
 Set the SFX volume multiplier. Same as the Sfx bus volume.
 
void asw::sound::set_music_volume (float volume)
 Set the music volume multiplier. Same as the Music bus volume.
 
float asw::sound::get_master_volume ()
 Get the current master volume multiplier.
 
float asw::sound::get_sfx_volume ()
 Get the current SFX volume multiplier.
 
float asw::sound::get_music_volume ()
 Get the current music volume multiplier.
 

Detailed Description

Sound module for the ASW library.

Author
Allan Legemaate (alege.nosp@m.maat.nosp@m.e@gma.nosp@m.il.c.nosp@m.om)
Date
2023-09-20

Definition in file sound.h.