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
asw::sound::SoundHandle Class Reference

A handle to a playing sound, used to change it while it plays. More...

#include <sound.h>

Public Member Functions

 SoundHandle ()=default
 Create a handle that refers to nothing.
 
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 pause () const
 Pause the sound.
 
void resume () const
 Resume a paused sound.
 
void set_volume (float volume) const
 Set the volume.
 
void set_pitch (float pitch) const
 Set the playback speed and pitch.
 
void set_pan (float pan) const
 Set the panning. Makes a positional sound non positional.
 
void set_position (const Vec2< float > &position) const
 Set where the sound is in the world. Makes the sound positional.
 
void set_velocity (const Vec2< float > &velocity) const
 Set how fast the sound is moving, for doppler pitch shift.
 
void set_occlusion (float amount) const
 Muffle the sound, as if heard through a wall.
 
void set_attenuation (const Attenuation &attenuation) const
 Change the distance fall off.
 

Private Member Functions

 SoundHandle (int voice, uint32_t generation)
 

Private Attributes

int voice { -1 }
 
uint32_t generation { 0 }
 

Friends

struct HandleAccess
 

Detailed Description

A handle to a playing sound, used to change it while it plays.

Handles are cheap to copy. Once the sound ends or its voice is given to another sound, the handle goes stale and every call on it does nothing.

Definition at line 109 of file sound.h.

Constructor & Destructor Documentation

◆ SoundHandle() [1/2]

asw::sound::SoundHandle::SoundHandle ( )
default

Create a handle that refers to nothing.

◆ SoundHandle() [2/2]

asw::sound::SoundHandle::SoundHandle ( int voice,
uint32_t generation )
private

Definition at line 329 of file sound.cpp.

Member Function Documentation

◆ is_playing()

bool asw::sound::SoundHandle::is_playing ( ) const

Check if the sound is still playing or paused.

Returns
True while the sound has not ended.

Definition at line 351 of file sound.cpp.

◆ pause()

void asw::sound::SoundHandle::pause ( ) const

Pause the sound.

Definition at line 364 of file sound.cpp.

◆ resume()

void asw::sound::SoundHandle::resume ( ) const

Resume a paused sound.

Definition at line 371 of file sound.cpp.

◆ set_attenuation()

void asw::sound::SoundHandle::set_attenuation ( const Attenuation & attenuation) const

Change the distance fall off.

Parameters
attenuationThe new settings.

Definition at line 428 of file sound.cpp.

◆ set_occlusion()

void asw::sound::SoundHandle::set_occlusion ( float amount) const

Muffle the sound, as if heard through a wall.

Parameters
amount0.0 is clear, 1.0 is fully muffled.

Definition at line 420 of file sound.cpp.

◆ set_pan()

void asw::sound::SoundHandle::set_pan ( float pan) const

Set the panning. Makes a positional sound non positional.

Parameters
panPanning (-1.0 left - 1.0 right).

Definition at line 394 of file sound.cpp.

◆ set_pitch()

void asw::sound::SoundHandle::set_pitch ( float pitch) const

Set the playback speed and pitch.

Parameters
pitch1.0 is normal.

Definition at line 386 of file sound.cpp.

◆ set_position()

void asw::sound::SoundHandle::set_position ( const Vec2< float > & position) const

Set where the sound is in the world. Makes the sound positional.

Parameters
positionThe world position.

Definition at line 403 of file sound.cpp.

◆ set_velocity()

void asw::sound::SoundHandle::set_velocity ( const Vec2< float > & velocity) const

Set how fast the sound is moving, for doppler pitch shift.

Parameters
velocityVelocity in world units per second.

Definition at line 412 of file sound.cpp.

◆ set_volume()

void asw::sound::SoundHandle::set_volume ( float volume) const

Set the volume.

Parameters
volumeVolume (0.0 - 1.0), before bus and distance.

Definition at line 378 of file sound.cpp.

◆ stop()

void asw::sound::SoundHandle::stop ( float fade_out_s = 0.0F) const

Stop the sound.

Parameters
fade_out_sFade out time in seconds.

Definition at line 356 of file sound.cpp.

Friends And Related Symbol Documentation

◆ HandleAccess

friend struct HandleAccess
friend

Definition at line 178 of file sound.h.

Member Data Documentation

◆ generation

uint32_t asw::sound::SoundHandle::generation { 0 }
private

Definition at line 183 of file sound.h.

◆ voice

int asw::sound::SoundHandle::voice { -1 }
private

Definition at line 182 of file sound.h.


The documentation for this class was generated from the following files: