Functions
Music.h File Reference
#include <SFML/Audio/Export.h>
#include <SFML/Audio/SoundStatus.h>
#include <SFML/Audio/Types.h>
#include <SFML/System/InputStream.h>
#include <SFML/System/Time.h>
#include <SFML/System/Vector3.h>
#include <stddef.h>

Go to the source code of this file.

Functions

CSFML_AUDIO_API sfMusicsfMusic_createFromFile (const char *filename)
 Create a new music and load it from a file. More...
 
CSFML_AUDIO_API sfMusicsfMusic_createFromMemory (const void *data, size_t sizeInBytes)
 Create a new music and load it from a file in memory. More...
 
CSFML_AUDIO_API sfMusicsfMusic_createFromStream (sfInputStream *stream)
 Create a new music and load it from a custom stream. More...
 
CSFML_AUDIO_API void sfMusic_destroy (sfMusic *music)
 Destroy a music. More...
 
CSFML_AUDIO_API void sfMusic_setLoop (sfMusic *music, sfBool loop)
 Set whether or not a music should loop after reaching the end. More...
 
CSFML_AUDIO_API sfBool sfMusic_getLoop (const sfMusic *music)
 Tell whether or not a music is in loop mode. More...
 
CSFML_AUDIO_API sfTime sfMusic_getDuration (const sfMusic *music)
 Get the total duration of a music. More...
 
CSFML_AUDIO_API void sfMusic_play (sfMusic *music)
 Start or resume playing a music. More...
 
CSFML_AUDIO_API void sfMusic_pause (sfMusic *music)
 Pause a music. More...
 
CSFML_AUDIO_API void sfMusic_stop (sfMusic *music)
 Stop playing a music. More...
 
CSFML_AUDIO_API unsigned int sfMusic_getChannelCount (const sfMusic *music)
 Return the number of channels of a music. More...
 
CSFML_AUDIO_API unsigned int sfMusic_getSampleRate (const sfMusic *music)
 Get the sample rate of a music. More...
 
CSFML_AUDIO_API sfSoundStatus sfMusic_getStatus (const sfMusic *music)
 Get the current status of a music (stopped, paused, playing) More...
 
CSFML_AUDIO_API sfTime sfMusic_getPlayingOffset (const sfMusic *music)
 Get the current playing position of a music. More...
 
CSFML_AUDIO_API void sfMusic_setPitch (sfMusic *music, float pitch)
 Set the pitch of a music. More...
 
CSFML_AUDIO_API void sfMusic_setVolume (sfMusic *music, float volume)
 Set the volume of a music. More...
 
CSFML_AUDIO_API void sfMusic_setPosition (sfMusic *music, sfVector3f position)
 Set the 3D position of a music in the audio scene. More...
 
CSFML_AUDIO_API void sfMusic_setRelativeToListener (sfMusic *music, sfBool relative)
 Make a musics's position relative to the listener or absolute. More...
 
CSFML_AUDIO_API void sfMusic_setMinDistance (sfMusic *music, float distance)
 Set the minimum distance of a music. More...
 
CSFML_AUDIO_API void sfMusic_setAttenuation (sfMusic *music, float attenuation)
 Set the attenuation factor of a music. More...
 
CSFML_AUDIO_API void sfMusic_setPlayingOffset (sfMusic *music, sfTime timeOffset)
 Change the current playing position of a music. More...
 
CSFML_AUDIO_API float sfMusic_getPitch (const sfMusic *music)
 Get the pitch of a music. More...
 
CSFML_AUDIO_API float sfMusic_getVolume (const sfMusic *music)
 Get the volume of a music. More...
 
CSFML_AUDIO_API sfVector3f sfMusic_getPosition (const sfMusic *music)
 Get the 3D position of a music in the audio scene. More...
 
CSFML_AUDIO_API sfBool sfMusic_isRelativeToListener (const sfMusic *music)
 Tell whether a music's position is relative to the listener or is absolute. More...
 
CSFML_AUDIO_API float sfMusic_getMinDistance (const sfMusic *music)
 Get the minimum distance of a music. More...
 
CSFML_AUDIO_API float sfMusic_getAttenuation (const sfMusic *music)
 Get the attenuation factor of a music. More...
 

Function Documentation

◆ sfMusic_createFromFile()

CSFML_AUDIO_API sfMusic* sfMusic_createFromFile ( const char *  filename)

Create a new music and load it from a file.

This function doesn't start playing the music (call sfMusic_play to do so). Here is a complete list of all the supported audio formats: ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.

Parameters
filenamePath of the music file to open
Returns
A new sfMusic object (NULL if failed)

◆ sfMusic_createFromMemory()

CSFML_AUDIO_API sfMusic* sfMusic_createFromMemory ( const void *  data,
size_t  sizeInBytes 
)

Create a new music and load it from a file in memory.

This function doesn't start playing the music (call sfMusic_play to do so). Here is a complete list of all the supported audio formats: ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.

Parameters
dataPointer to the file data in memory
sizeInBytesSize of the data to load, in bytes
Returns
A new sfMusic object (NULL if failed)

◆ sfMusic_createFromStream()

CSFML_AUDIO_API sfMusic* sfMusic_createFromStream ( sfInputStream stream)

Create a new music and load it from a custom stream.

This function doesn't start playing the music (call sfMusic_play to do so). Here is a complete list of all the supported audio formats: ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.

Parameters
streamSource stream to read from
Returns
A new sfMusic object (NULL if failed)

◆ sfMusic_destroy()

CSFML_AUDIO_API void sfMusic_destroy ( sfMusic music)

Destroy a music.

Parameters
musicMusic to destroy

◆ sfMusic_getAttenuation()

CSFML_AUDIO_API float sfMusic_getAttenuation ( const sfMusic music)

Get the attenuation factor of a music.

Parameters
musicMusic object
Returns
Attenuation factor of the music

◆ sfMusic_getChannelCount()

CSFML_AUDIO_API unsigned int sfMusic_getChannelCount ( const sfMusic music)

Return the number of channels of a music.

1 channel means a mono sound, 2 means stereo, etc.

Parameters
musicMusic object
Returns
Number of channels

◆ sfMusic_getDuration()

CSFML_AUDIO_API sfTime sfMusic_getDuration ( const sfMusic music)

Get the total duration of a music.

Parameters
musicMusic object
Returns
Music duration

◆ sfMusic_getLoop()

CSFML_AUDIO_API sfBool sfMusic_getLoop ( const sfMusic music)

Tell whether or not a music is in loop mode.

Parameters
musicMusic object
Returns
sfTrue if the music is looping, sfFalse otherwise

◆ sfMusic_getMinDistance()

CSFML_AUDIO_API float sfMusic_getMinDistance ( const sfMusic music)

Get the minimum distance of a music.

Parameters
musicMusic object
Returns
Minimum distance of the music

◆ sfMusic_getPitch()

CSFML_AUDIO_API float sfMusic_getPitch ( const sfMusic music)

Get the pitch of a music.

Parameters
musicMusic object
Returns
Pitch of the music

◆ sfMusic_getPlayingOffset()

CSFML_AUDIO_API sfTime sfMusic_getPlayingOffset ( const sfMusic music)

Get the current playing position of a music.

Parameters
musicMusic object
Returns
Current playing position

◆ sfMusic_getPosition()

CSFML_AUDIO_API sfVector3f sfMusic_getPosition ( const sfMusic music)

Get the 3D position of a music in the audio scene.

Parameters
musicMusic object
Returns
Position of the music in the world

◆ sfMusic_getSampleRate()

CSFML_AUDIO_API unsigned int sfMusic_getSampleRate ( const sfMusic music)

Get the sample rate of a music.

The sample rate is the number of audio samples played per second. The higher, the better the quality.

Parameters
musicMusic object
Returns
Sample rate, in number of samples per second

◆ sfMusic_getStatus()

CSFML_AUDIO_API sfSoundStatus sfMusic_getStatus ( const sfMusic music)

Get the current status of a music (stopped, paused, playing)

Parameters
musicMusic object
Returns
Current status

◆ sfMusic_getVolume()

CSFML_AUDIO_API float sfMusic_getVolume ( const sfMusic music)

Get the volume of a music.

Parameters
musicMusic object
Returns
Volume of the music, in the range [0, 100]

◆ sfMusic_isRelativeToListener()

CSFML_AUDIO_API sfBool sfMusic_isRelativeToListener ( const sfMusic music)

Tell whether a music's position is relative to the listener or is absolute.

Parameters
musicMusic object
Returns
sfTrue if the position is relative, sfFalse if it's absolute

◆ sfMusic_pause()

CSFML_AUDIO_API void sfMusic_pause ( sfMusic music)

Pause a music.

This function pauses the music if it was playing, otherwise (music already paused or stopped) it has no effect.

Parameters
musicMusic object

◆ sfMusic_play()

CSFML_AUDIO_API void sfMusic_play ( sfMusic music)

Start or resume playing a music.

This function starts the music if it was stopped, resumes it if it was paused, and restarts it from beginning if it was it already playing. This function uses its own thread so that it doesn't block the rest of the program while the music is played.

Parameters
musicMusic object

◆ sfMusic_setAttenuation()

CSFML_AUDIO_API void sfMusic_setAttenuation ( sfMusic music,
float  attenuation 
)

Set the attenuation factor of a music.

The attenuation is a multiplicative factor which makes the music more or less loud according to its distance from the listener. An attenuation of 0 will produce a non-attenuated music, i.e. its volume will always be the same whether it is heard from near or from far. On the other hand, an attenuation value such as 100 will make the music fade out very quickly as it gets further from the listener. The default value of the attenuation is 1.

Parameters
musicMusic object
attenuationNew attenuation factor of the music

◆ sfMusic_setLoop()

CSFML_AUDIO_API void sfMusic_setLoop ( sfMusic music,
sfBool  loop 
)

Set whether or not a music should loop after reaching the end.

If set, the music will restart from beginning after reaching the end and so on, until it is stopped or sfMusic_setLoop(music, sfFalse) is called. The default looping state for musics is false.

Parameters
musicMusic object
loopsfTrue to play in loop, sfFalse to play once

◆ sfMusic_setMinDistance()

CSFML_AUDIO_API void sfMusic_setMinDistance ( sfMusic music,
float  distance 
)

Set the minimum distance of a music.

The "minimum distance" of a music is the maximum distance at which it is heard at its maximum volume. Further than the minimum distance, it will start to fade out according to its attenuation factor. A value of 0 ("inside the head of the listener") is an invalid value and is forbidden. The default value of the minimum distance is 1.

Parameters
musicMusic object
distanceNew minimum distance of the music

◆ sfMusic_setPitch()

CSFML_AUDIO_API void sfMusic_setPitch ( sfMusic music,
float  pitch 
)

Set the pitch of a music.

The pitch represents the perceived fundamental frequency of a sound; thus you can make a music more acute or grave by changing its pitch. A side effect of changing the pitch is to modify the playing speed of the music as well. The default value for the pitch is 1.

Parameters
musicMusic object
pitchNew pitch to apply to the music

◆ sfMusic_setPlayingOffset()

CSFML_AUDIO_API void sfMusic_setPlayingOffset ( sfMusic music,
sfTime  timeOffset 
)

Change the current playing position of a music.

The playing position can be changed when the music is either paused or playing.

Parameters
musicMusic object
timeOffsetNew playing position

◆ sfMusic_setPosition()

CSFML_AUDIO_API void sfMusic_setPosition ( sfMusic music,
sfVector3f  position 
)

Set the 3D position of a music in the audio scene.

Only musics with one channel (mono musics) can be spatialized. The default position of a music is (0, 0, 0).

Parameters
musicMusic object
positionPosition of the music in the scene

◆ sfMusic_setRelativeToListener()

CSFML_AUDIO_API void sfMusic_setRelativeToListener ( sfMusic music,
sfBool  relative 
)

Make a musics's position relative to the listener or absolute.

Making a music relative to the listener will ensure that it will always be played the same way regardless the position of the listener. This can be useful for non-spatialized musics, musics that are produced by the listener, or musics attached to it. The default value is false (position is absolute).

Parameters
musicMusic object
relativesfTrue to set the position relative, sfFalse to set it absolute

◆ sfMusic_setVolume()

CSFML_AUDIO_API void sfMusic_setVolume ( sfMusic music,
float  volume 
)

Set the volume of a music.

The volume is a value between 0 (mute) and 100 (full volume). The default value for the volume is 100.

Parameters
musicMusic object
volumeVolume of the music

◆ sfMusic_stop()

CSFML_AUDIO_API void sfMusic_stop ( sfMusic music)

Stop playing a music.

This function stops the music if it was playing or paused, and does nothing if it was already stopped. It also resets the playing position (unlike sfMusic_pause).

Parameters
musicMusic object