1.8
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Sound Class Reference

Simple class to manage playing raw or WAV PCM sound files. More...

Public Member Functions

 Sound (const Sound &)=delete
 
 Sound (const std::string &uri, const std::string &device="default")
 
 Sound (const std::string &uri, unsigned int rate, int channels, const std::string &device="default")
 
 Sound (Sound &&) noexcept
 
virtual ~Sound () noexcept
 
void media (const std::string &uri)
 Sets the WAV file to play. More...
 
Soundoperator= (const Sound &)=delete
 
Soundoperator= (Sound &&) noexcept
 
void play (bool repeat=false)
 Play the sound. More...
 
void stop ()
 

Static Public Member Functions

static std::vector< std::string > enumerate_pcm_devices ()
 Enumerate PCM devices. More...
 

Protected Attributes

std::unique_ptr< detail::soundimpl > m_impl
 Implementation pointer. More...
 
std::string m_uri
 Sound file. More...
 

Detailed Description

Simple class to manage playing raw or WAV PCM sound files.

The default sound card is used by default, but another one can be specified.

Sound sound("file:myfile.wav", "1:0")
Sound(const std::string &uri, const std::string &device="default")

Another way to configure the default sound card is at the system level.

List available sound cards:

cat /proc/asound/cards

Then, add the following to /etc/asound.conf

defaults.pcm.card 1
defaults.ctl.card 1

Constructor & Destructor Documentation

◆ Sound() [1/4]

Sound ( const std::string &  uri,
const std::string &  device = "default" 
)
explicit
Parameters
uriThe WAV file to play.
deviceALSA sound device.

◆ Sound() [2/4]

Sound ( const std::string &  uri,
unsigned int  rate,
int  channels,
const std::string &  device = "default" 
)
explicit
Parameters
uriThe WAV file to play.
rateRate of the sound file, i.e. 44100.
channelsThe number of channels in the sound file.
deviceALSA sound device.

◆ Sound() [3/4]

Sound ( const Sound )
delete

◆ Sound() [4/4]

Sound ( Sound &&  )
noexcept

◆ ~Sound()

virtual ~Sound ( )
virtualnoexcept

Member Function Documentation

◆ enumerate_pcm_devices()

static std::vector<std::string> enumerate_pcm_devices ( )
static

Enumerate PCM devices.

Enumerate PCM devices and fill the vector with their names. These names can be used for the device parameter of the constructors.

◆ media()

void media ( const std::string &  uri)

Sets the WAV file to play.

Parameters
urithe WAV file URI

◆ operator=() [1/2]

Sound& operator= ( const Sound )
delete

◆ operator=() [2/2]

Sound& operator= ( Sound &&  )
noexcept

◆ play()

void play ( bool  repeat = false)

Play the sound.

This will immediately cancel any existing playback happening of this Sound.

Parameters
repeatShould the sound keep repeating?

◆ stop()

void stop ( )

Member Data Documentation

◆ m_impl

std::unique_ptr<detail::soundimpl> m_impl
protected

Implementation pointer.

◆ m_uri

std::string m_uri
protected

Sound file.