Skip to content

Audio

Checks if SplashKit audio currently ready to be used. Should this return false, you may want to use Open Audio to enable audio.

Return Type: Boolean

Signatures:

bool audio_ready()

Turns off audio, stopping all current sounds effects and music.

Signatures:

void close_audio()

Starts the SplashKit audio system working.

Signatures:

void open_audio()

Fades music file matching the name to full volume over a specified number of milliseconds

Parameters:

NameTypeDescription
nameStringThe name of the Music file to play.
msIntegerHow many milliseconds it takes to fade the Music to full volume

Signatures:

void fade_music_in(const string &name, int ms)

Fades music file matching the name to full volume over a specified number of milliseconds and loops a specified number of times

Parameters:

NameTypeDescription
nameStringThe name of the Music file to play.
timesIntegerControls the number of times the music is played.
msIntegerHow many milliseconds it takes to fade the Music to full volume

Signatures:

void fade_music_in(const string &name, int times, int ms)

Fades music up to full volume over a specified number of milliseconds.

Parameters:

NameTypeDescription
dataMusicThe name of the Music to play.
msIntegerHow many milliseconds it takes to fade the Music to full volume

Signatures:

void fade_music_in(music data, int ms)

Fades music up to full volume over a specified number of milliseconds for a specified number of times.

Parameters:

NameTypeDescription
dataMusicThe name of the Music to play.
timesIntegerControls the number of times the music is played.
msIntegerHow many milliseconds it takes to fade the Music to full volume

Signatures:

void fade_music_in(music data, int times, int ms)

Fades music outover a specified number of milliseconds

Parameters:

NameTypeDescription
msIntegerHow many milliseconds it takes to fade the Music out

Signatures:

void fade_music_out(int ms)

Releases all of the music files that have been loaded.

Signatures:

void free_all_music()

Releases the SplashKit resources associated with music.

Parameters:

NameTypeDescription
effectMusicThe music file whose resources should be released.

Signatures:

void free_music(music effect)

Determines if SplashKit has a music file loaded for the supplied name. This checks against all music files loaded, those loaded without a name are assigned the filename as a default. If this returns false, you may want to use Load Music to load in a specific sound effect and give it the desired name.

Parameters:

NameTypeDescription
nameStringThe name to check if a music file is loaded.

Return Type: Boolean

Signatures:

bool has_music(const string &name)

Loads and returns a music value. The supplied filename is used to locate the music file to load. The supplied name indicates the name to use to refer to this Music value. The Music can then be retrieved by passing this name to the Music Named function.

Parameters:

NameTypeDescription
nameStringThe name of the resource for SplashKit
filenameStringThe filename to load

Return Type: Music

Signatures:

music load_music(const string &name, const string &filename)

Returns the filename the of the music data

Parameters:

NameTypeDescription
dataMusicThe music resource

Return Type: String

Signatures:

string music_filename(music data)

Returns the name that SplashKit uses to refer to this music data

Parameters:

NameTypeDescription
dataMusicThe music resource

Return Type: String

Signatures:

string music_name(music data)

Retrieves a Music that has been loaded into SplashKit.

Parameters:

NameTypeDescription
nameStringThe name of the music file to return.

Return Type: Music

Signatures:

music music_named(const string &name)

Checks whether music is currently playing.

Return Type: Boolean

Signatures:

bool music_playing()

Lets you test if music value is valid. This will return true when it is a valid music.

Parameters:

NameTypeDescription
mMusicthe music source to test

Return Type: Boolean

Signatures:

bool music_valid(music m)

Returns the volume of the currently playing Music.

Return Type: Double

Signatures:

double music_volume()

Pauses currently playing music - see resume_music to continue playing.

Signatures:

void pause_music()

Plays the music file that matches the name once at full volume.

Parameters:

NameTypeDescription
nameStringThe name of the Music to play.

Signatures:

void play_music(const string &name)

Usage:  {</>}


Plays the music file that matches the name a specified number of times at full volume.

Parameters:

NameTypeDescription
nameStringThe name of the Music to play.
timesIntegerControls the number of times the music is played.

Signatures:

void play_music(const string &name, int times)

Plays a music file once at full volume.

Parameters:

NameTypeDescription
dataMusicThe name of the Music to play.

Signatures:

void play_music(music data)

Plays a music file a specified number of times at full volume.

Parameters:

NameTypeDescription
dataMusicThe name of the Music to play.
timesIntegerControls the number of times the music is played.

Signatures:

void play_music(music data, int times)

Plays a music file for a specified number of times and playback volume.

Parameters:

NameTypeDescription
dataMusicThe name of the Music to play.
timesIntegerControls the number of times the music is played.
volumeDoubleIndicates the percentage of the original volume to play the Music at. This must be between 0 and 1.

Signatures:

void play_music(music data, int times, double volume)

Resumes currently paused music - see pause_music to pause playing music.

Signatures:

void resume_music()

Usage:  {</>}


Sets the volume of the currently playing Music. Must be between 0 and 1, e.g. 0.1 is 10%.

Parameters:

NameTypeDescription
volumeDoubleIndicates the percentage of the original volume to play the Music at. This must be between 0 and 1.

Signatures:

void set_music_volume(double volume)

Stops currently playing music.

Signatures:

void stop_music()

Fades out all Sound Effects over the specified milliseconds.

Parameters:

NameTypeDescription
msIntegerThe number of milliseconds to fade out all sound effects.

Signatures:

void fade_all_sound_effects_out(int ms)

Fades out the Sound Effect over the specified milliseconds.

Parameters:

NameTypeDescription
effectSound EffectThe Sound Effect to fade out.
msIntegerThe number of milliseconds to fade out the Sound Effect.

Signatures:

void fade_sound_effect_out(sound_effect effect, int ms)

Releases all of the sound effects that have been loaded.

Signatures:

void free_all_sound_effects()

Releases the SplashKit resources associated with the sound effect.

Parameters:

NameTypeDescription
effectSound EffectThe Sound Effect whose resources should be released.

Signatures:

void free_sound_effect(sound_effect effect)

Determines if SplashKit has a sound effect loaded for the supplied name. This checks against all sounds loaded, those loaded without a name are assigned the filename as a default. If this returns false, you may want to use Load Sound Effect to load in a specific sound effect and give it the desired name.

Parameters:

NameTypeDescription
nameStringThe name to check if a sound effect is loaded.

Return Type: Boolean

Signatures:

bool has_sound_effect(const string &name)

The supplied filename is used to locate the sound effect to load. The supplied name indicates the name to use to refer to this Sound Effect. The Sound Effect can then be retrieved by passing this name to the Sound Effect Named function.

Parameters:

NameTypeDescription
nameStringThe name used to refer to the sound effect.
filenameStringThe filename used to locate the sound effect to use.

Return Type: Sound Effect

Signatures:

sound_effect load_sound_effect(const string &name, const string &filename)

Usage:  {</>}


Plays a sound effect once at full volume.

Parameters:

NameTypeDescription
nameStringThe name of the effect to play.

Signatures:

void play_sound_effect(const string &name)

Plays a sound effect once at full volume.

Parameters:

NameTypeDescription
nameStringThe name of the effect to play.
volumeDoubleThe volume to play the Sound Effect

Signatures:

void play_sound_effect(const string &name, double volume)

Plays a sound effect for a specified number of times at full volume.

Parameters:

NameTypeDescription
nameStringThe name of the effect to play.
timesIntegerControls the number of times the sound effect is played.

Signatures:

void play_sound_effect(const string &name, int times)

Plays a sound effect for a specified number of times and playback volume.

Parameters:

NameTypeDescription
nameStringThe name of the effect to play.
timesIntegerControls the number of times the sound effect is played.
volumeDoubleIndicates the percentage of the original volume to play the Sound Effect at. This must be between 0 and 1.

Signatures:

void play_sound_effect(const string &name, int times, double volume)

Plays a sound effect once at full volume.

Parameters:

NameTypeDescription
effectSound EffectThe effect indicates which sound effect to start playing.

Signatures:

void play_sound_effect(sound_effect effect)

Usage:  {</>}


Plays a sound effect once at playback volume.

Parameters:

NameTypeDescription
effectSound EffectThe effect indicates which sound effect to start playing.
volumeDoubleIndicates the percentage of the original volume to play the Sound Effect at. This must be between 0 and 1.

Signatures:

void play_sound_effect(sound_effect effect, double volume)

Plays a sound effect once at full volume.

Parameters:

NameTypeDescription
effectSound EffectThe effect indicates which sound effect to start playing.
timesIntegerControls the number of times the sound effect is played.

Signatures:

void play_sound_effect(sound_effect effect, int times)

This version of Play Sound Effect allows you to control both the number of times the Sound Effect is repeated and its playback volume.

Parameters:

NameTypeDescription
effectSound EffectThe effect indicates which sound effect to start playing.
timesIntegerControls the number of times the sound effect is played.
volumeDoubleIndicates the percentage of the original volume to play the Sound Effect at. This must be between 0 and 1.

Signatures:

void play_sound_effect(sound_effect effect, int times, double volume)

Returns the filename of the Sound Effect that has been loaded by SplashKit

Parameters:

NameTypeDescription
effectSound EffectThe Sound Effect to check

Return Type: String

Signatures:

string sound_effect_filename(sound_effect effect)

Returns the name of the Sound Effect that has been loaded by SplashKit

Parameters:

NameTypeDescription
effectSound EffectThe Sound Effect to check

Return Type: String

Signatures:

string sound_effect_name(sound_effect effect)

Retrieves a Sound Effect that has been loaded into SplashKit. If the sound effect has not been loaded, this will attempt to use the name to locate the file for you. If a file can be found, the sound effect is loaded and returned.

Parameters:

NameTypeDescription
nameStringThe name of the sound effect to return.

Return Type: Sound Effect

Signatures:

sound_effect sound_effect_named(const string &name)

Usage:  {</>}


Checks whether the Sound Effect that matches the name is currently playing

Parameters:

NameTypeDescription
nameStringThe name of the Sound Effect

Return Type: Boolean

Signatures:

bool sound_effect_playing(const string &name)

Checks whether the Sound Effect is currently playing

Parameters:

NameTypeDescription
effectSound EffectThe Sound Effect to be tested.

Return Type: Boolean

Signatures:

bool sound_effect_playing(sound_effect effect)

Lets you test if a sound effect is valid. This will return true when it is a valid sound effect.

Parameters:

NameTypeDescription
effectSound Effectthe effect to test

Return Type: Boolean

Signatures:

bool sound_effect_valid(sound_effect effect)

Stops the Sound Effect that matches the name, if it is currently playing.

Parameters:

NameTypeDescription
nameStringThe name of the Sound Effect to stop.

Signatures:

void stop_sound_effect(const string &name)

Stops the Sound Effect if it is currently playing

Parameters:

NameTypeDescription
effectSound EffectThe Sound Effect to stop.

Signatures:

void stop_sound_effect(sound_effect effect)

The Music type is used to refer to music that can be played by SplashKit. Music files are loaded with Load Music, played using Play Music, and must be released using Free Music.

Unlike Sound Effects, there can only be one music track playing at a time. Playing an new track will stop the currently playing music and switch to the new track.


The Sound Effect type is used to refer to sound effects that can be played by the SplashKit audio code. Sound effects are:

  • loaded with Load Sound Effect,

  • played using Play Sound Effect,

  • and must be released using delete_sound_effect (to release a specific sound effect) or delete_all_sound_effects (to release all loaded sound effects).

SplashKit will mix the audio from multiple sound effects, making it possible to play multiple Sound Effects, or even to play the one Sound Effect multiple times.

You can check if a Sound Effect is currently playing using Sound Effect Playing.

To stop a Sound Effect playing use Stop Sound Effect. This will stop all instances of this one sound effect from playing.

Use Music for background music for your games.