Gosu
Public Member Functions | List of all members
Gosu::Sample Class Reference

A sample is a short sound that is completely loaded in memory, can be played multiple times at once and offers very flexible playback parameters. More...

Public Member Functions

 Sample ()
 Constructs an empty sample that acts as if the song had a length of 0. More...
 
 Sample (const std::string &filename)
 Constructs a sample that can be played on the specified audio system and loads the sample from a file. More...
 
 Sample (Reader reader)
 Constructs a sample that can be played on the specified audio system and loads the sample data from a stream. More...
 
Channel play (double volume=1, double speed=1, bool looping=false) const
 Plays the sample without panning. More...
 
Channel play_pan (double pan, double volume=1, double speed=1, bool looping=false) const
 Plays the sample with panning. More...
 

Detailed Description

A sample is a short sound that is completely loaded in memory, can be played multiple times at once and offers very flexible playback parameters.

Use samples for everything that's not music.

Definition at line 47 of file Audio.hpp.

Constructor & Destructor Documentation

◆ Sample() [1/3]

Gosu::Sample::Sample ( )

Constructs an empty sample that acts as if the song had a length of 0.

◆ Sample() [2/3]

Gosu::Sample::Sample ( const std::string &  filename)
explicit

Constructs a sample that can be played on the specified audio system and loads the sample from a file.

◆ Sample() [3/3]

Gosu::Sample::Sample ( Reader  reader)
explicit

Constructs a sample that can be played on the specified audio system and loads the sample data from a stream.

Member Function Documentation

◆ play()

Channel Gosu::Sample::play ( double  volume = 1,
double  speed = 1,
bool  looping = false 
) const

Plays the sample without panning.

Parameters
volumeCan be anything from 0.0 (silence) to 1.0 (full volume).
speedPlayback speed is only limited by the underlying audio library, and can accept very high or low values. Use 1.0 for normal playback speed.

◆ play_pan()

Channel Gosu::Sample::play_pan ( double  pan,
double  volume = 1,
double  speed = 1,
bool  looping = false 
) const

Plays the sample with panning.

Even if pan is 0.0, the sample will not be as loud as if it were played by calling play() due to the way the panning works.

Parameters
panCan be anything from -1.0 (left) to 1.0 (right).
volumeCan be anything from 0.0 (silence) to 1.0 (full volume).
speedPlayback speed is only limited by by the underlying audio library, and can accept very high or low values. Use 1.0 for normal playback speed.

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