WHY_CPP  0.1
Functions

Functions to play some sound and music. More...

Functions

void ImportMusic (Context &context, const std::string &path, const std::string &name)
 
void ImportSFX (Context &context, const std::string &path, const std::string &name)
 
void PlayMusic (const Context &context, const std::string &name, i32 loops=-1)
 
void PlaySFX (const Context &context, const std::string &name, i32 loops=0, i32 ticks=-1)
 
void StopMusic (const Context &context, const std::string &name)
 
void StopSFX (const Context &context, const std::string &name)
 

Detailed Description

Functions to play some sound and music.

You need sdl2_mixer library to be installed. https://www.libsdl.org/projects/SDL_mixer/

Function Documentation

void ImportMusic ( Context context,
const std::string &  path,
const std::string &  name 
)

Loads audio file in memory. Setup an association between sound and name.

Parameters
pathMusic file path
nameName to reference this music from the PlayMusic() function

Definition at line 8 of file sound.cpp.

void ImportSFX ( Context context,
const std::string &  path,
const std::string &  name 
)

Loads audio file in memory. Setup an association between sound and name.

Parameters
pathSound effect file path
nameName to reference this sound effect from the PlaySFX() function

Definition at line 11 of file sound.cpp.

void PlayMusic ( const Context context,
const std::string &  name,
i32  loops = -1 
)
Parameters
nameName of the music to play.
loopsNumber of loops, -1 is infinite loops. Passing one here plays the sample twice (1 loop).

Definition at line 14 of file sound.cpp.

void PlaySFX ( const Context context,
const std::string &  name,
i32  loops = 0,
i32  ticks = -1 
)
Parameters
nameName of the music to play.
loopsNumber of loops, -1 is infinite loops. Passing one here plays the sample twice (1 loop).
ticksMillisecond limit to play sample, at most. If not enough loops or the sample chunk is not long enough, then the sample may stop before this timeout occurs. -1 means play forever.

Definition at line 17 of file sound.cpp.

void StopMusic ( const Context context,
const std::string &  name 
)

Stop the music. Next PlayMusic call starts playing from the beginning.

Parameters
context
nameunique music name which was set by ImportMusic

Definition at line 20 of file sound.cpp.

void StopSFX ( const Context context,
const std::string &  name 
)

Stop the sound effect. Next PlaySFX call starts playing from the beginning.

Parameters
context
nameunique sound effect name which was set by ImportSFX

Definition at line 23 of file sound.cpp.