22enum class Bus : uint8_t {
125 void stop(
float fade_out_s = 0.0F)
const;
227 const asw::Sample& sample,
float volume = 1.0F,
float pan = 0.0F,
bool loop =
false);
235SoundHandle
play(
const asw::Sample& sample,
const PlayOptions& options);
277void set_listener(
const Vec2<float>& position,
const Vec2<float>& velocity = { 0.0F, 0.0F });
297void set_doppler(
float factor,
float speed_of_sound = 3000.0F);
322void duck(
Bus bus,
float gain,
float hold_s,
float fade_s = 0.2F);
A handle to a playing sound, used to change it while it plays.
void set_occlusion(float amount) const
Muffle the sound, as if heard through a wall.
void set_velocity(const Vec2< float > &velocity) const
Set how fast the sound is moving, for doppler pitch shift.
void set_attenuation(const Attenuation &attenuation) const
Change the distance fall off.
void set_position(const Vec2< float > &position) const
Set where the sound is in the world. Makes the sound positional.
bool is_playing() const
Check if the sound is still playing or paused.
void stop(float fade_out_s=0.0F) const
Stop the sound.
void set_pitch(float pitch) const
Set the playback speed and pitch.
SoundHandle()=default
Create a handle that refers to nothing.
void pause() const
Pause the sound.
void set_pan(float pan) const
Set the panning. Makes a positional sound non positional.
void resume() const
Resume a paused sound.
void set_volume(float volume) const
Set the volume.
bool is_music_paused()
Check if music is paused.
void set_doppler(float factor, float speed_of_sound=3000.0F)
Set how strong doppler pitch shift is.
void pause_music()
Pause the currently playing music.
float get_master_volume()
Get the current master volume multiplier.
void play_music(const asw::Music &sample, float volume=1.0F, float fade_in_s=0.0F)
Play a music sample.
bool is_music_playing()
Check if music is currently playing.
void set_sfx_volume(float volume)
Set the SFX volume multiplier. Same as the Sfx bus volume.
float get_music_volume()
Get the current music volume multiplier.
void resume_music()
Resume paused music.
Bus
Mix buses. Each sound plays on one bus, and each bus has its own volume and can be ducked.
void _shutdown()
Shut down the sound module. Called automatically by asw::core::shutdown().
MIX_Mixer * get_mixer()
Get the SDL mixer device.
float get_sfx_volume()
Get the current SFX volume multiplier.
void 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.
void set_music_volume(float volume)
Set the music volume multiplier. Same as the Music bus volume.
void set_master_volume(float volume)
Set the master volume multiplier (affects all audio).
void set_bus_volume(Bus bus, float volume)
Set a bus volume.
void stop_music(float fade_out_s=0.0F)
Stop the currently playing music.
SoundHandle play(const asw::Sample &sample, float volume=1.0F, float pan=0.0F, bool loop=false)
Play a sample.
bool _init()
Initialize the sound module. Called automatically by asw::core::init().
SpatialMode
How positional sounds are placed on the speakers.
@ Stereo
Left/right panning. Best for headphones and side on games.
Vec2< float > get_listener()
Get the listener position.
void 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....
Rolloff
How volume falls off with distance for positional sounds.
@ Linear
Straight line from full volume at min_distance to silent at max_distance.
@ Inverse
Natural sounding, loud close up and a long quiet tail.
@ InverseSquare
Like Inverse but drops faster.
float get_bus_volume(Bus bus)
Get a bus volume.
uint32_t _get_session()
Get the number of times the sound module has been shut down.
void set_spatial_mode(SpatialMode mode)
Choose how positional sounds are placed on the speakers.
SoundHandle 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 ...
SoundHandle 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...
void _update()
Update fades, ducking and positional sounds. Called automatically by asw::core::update().
std::shared_ptr< MIX_Audio > Sample
Alias for a shared pointer to an MIX_Audio.
std::shared_ptr< MIX_Audio > Music
Alias for a shared pointer to an MIX_Audio.
Distance settings for positional sounds, in world units (pixels).
float min_distance
Full volume at this distance or closer.
float max_distance
Silent at this distance or further.
Rolloff rolloff
Shape of the fall off between the two.
Options for playing a sound.
float fade_in_s
Fade in time in seconds.
float pitch
Playback speed and pitch. 1.0 is normal, 2.0 is an octave up.
float volume_variation
Random volume change per play, as a fraction.
float pan
Panning (-1.0 left - 1.0 right). Ignored for positional sounds.
float volume
Playback volume (0.0 - 1.0).
Attenuation attenuation
Distance fall off, used by positional sounds.
Types used throughout the ASW library.