Skip to content

Audio

Functions

Audio Ready

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()

Close Audio

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

Signatures:

void close_audio()

Open Audio

Starts the SplashKit audio system working.

Signatures:

void open_audio()

Fade Music In

Fade Music In

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)

Fade Music In

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)

Fade Music In

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)

Fade Music In

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)

Fade Music Out

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)

Free All Music

Releases all of the music files that have been loaded.

Signatures:

void free_all_music()

Free Music

Releases the SplashKit resources associated with music.

Parameters:

NameTypeDescription
effectMusicThe music file whose resources should be released.

Signatures:

void free_music(music effect)

Has Music

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)

Load Music

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)

Music Filename

Returns the filename the of the music data

Parameters:

NameTypeDescription
dataMusicThe music resource

Return Type: String

Signatures:

string music_filename(music data)

Music Name

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)

Music Named

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)

Music Playing

Checks whether music is currently playing.

Return Type: Boolean

Signatures:

bool music_playing()

Music Valid

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)

Music Volume

Returns the volume of the currently playing Music.

Return Type: Float

Signatures:

float music_volume()

Pause Music

Pauses currently playing music - see resume_music to continue playing.

Signatures:

void pause_music()

Play Music

Play 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)

Play Music

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)

Play Music

Plays a music file once at full volume.

Parameters:

NameTypeDescription
dataMusicThe name of the Music to play.

Signatures:

void play_music(music data)

Play Music

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)

Play Music

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.
volumeFloatIndicates 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, float volume)

Resume Music

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

Signatures:

void resume_music()

Set Music Volume

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

Parameters:

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

Signatures:

void set_music_volume(float volume)

Stop Music

Stops currently playing music.

Signatures:

void stop_music()

Fade All Sound Effects Out

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)

Fade Sound Effect Out

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)

Free All Sound Effects

Releases all of the sound effects that have been loaded.

Signatures:

void free_all_sound_effects()

Free Sound Effect

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)

Has Sound 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)

Load Sound Effect

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)

Play Sound Effect

Play Sound Effect

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)

Play Sound Effect

Plays a sound effect once at full volume.

Parameters:

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

Signatures:

void play_sound_effect(const string &name, float volume)

Play Sound Effect

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)

Play Sound Effect

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.
volumeFloatIndicates 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, float volume)

Play Sound Effect

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)

Play Sound Effect

Plays a sound effect once at playback volume.

Parameters:

NameTypeDescription
effectSound EffectThe effect indicates which sound effect to start playing.
volumeFloatIndicates 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, float volume)

Play Sound Effect

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)

Play Sound Effect

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.
volumeFloatIndicates 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, float volume)

Sound Effect Filename

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)

Sound Effect Name

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)

Sound Effect Named

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)

Sound Effect Playing

Sound Effect Playing

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)

Sound Effect Playing

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)

Sound Effect Valid

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)

Stop Sound Effect

Stop Sound 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)

Stop Sound Effect

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)

Types

Music

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.


Sound Effect

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.