Music#
Functions
-
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:
filename – Path of the music file to open
- Returns:
A new sfMusic object (NULL if failed)
-
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:
data – Pointer to the file data in memory
sizeInBytes – Size of the data to load, in bytes
- Returns:
A new sfMusic object (NULL if failed)
-
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:
stream – Source stream to read from
- Returns:
A new sfMusic object (NULL if failed)
-
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:
music – Music object
loop – sfTrue to play in loop, sfFalse to play once
-
sfBool sfMusic_getLoop(const sfMusic *music)#
Tell whether or not a music is in loop mode.
- Parameters:
music – Music object
- Returns:
sfTrue if the music is looping, sfFalse otherwise
-
sfTime sfMusic_getDuration(const sfMusic *music)#
Get the total duration of a music.
- Parameters:
music – Music object
- Returns:
Music duration
-
sfTimeSpan sfMusic_getLoopPoints(const sfMusic *music)#
Get the positions of the of the sound’s looping sequence.
See also
setLoopPoints
Warning
Since sfMusic_setLoopPoints() performs some adjustments on the provided values and rounds them to internal samples, a call to sfMusic_getLoopPoints() is not guaranteed to return the same times passed into a previous call to sfMusic_setLoopPoints(). However, it is guaranteed to return times that will map to the valid internal samples of this Music if they are later passed to sfMusic_setLoopPoints().
- Returns:
Loop Time position class.
-
void sfMusic_setLoopPoints(sfMusic *music, sfTimeSpan timePoints)#
Sets the beginning and end of the sound’s looping sequence using sf::Time.
Loop points allow one to specify a pair of positions such that, when the music is enabled for looping, it will seamlessly seek to the beginning whenever it encounters the end. Valid ranges for timePoints.offset and timePoints.length are [0, Dur) and (0, Dur-offset] respectively, where Dur is the value returned by sfMusic_getDuration(). Note that the EOF “loop point” from the end to the beginning of the stream is still honored, in case the caller seeks to a point after the end of the loop range. This function can be safely called at any point after a stream is opened, and will be applied to a playing sound without affecting the current playing offset.
See also
getLoopPoints
Warning
Setting the loop points while the stream’s status is Paused will set its status to Stopped. The playing offset will be unaffected.
- Parameters:
timePoints – The definition of the loop. Can be any time points within the sound’s length
-
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:
music – Music object
-
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:
music – Music object
-
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:
music – Music object
-
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:
music – Music object
- Returns:
Number of channels
-
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:
music – Music object
- Returns:
Sample rate, in number of samples per second
-
sfSoundStatus sfMusic_getStatus(const sfMusic *music)#
Get the current status of a music (stopped, paused, playing)
- Parameters:
music – Music object
- Returns:
Current status
-
sfTime sfMusic_getPlayingOffset(const sfMusic *music)#
Get the current playing position of a music.
- Parameters:
music – Music object
- Returns:
Current playing position
-
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:
music – Music object
pitch – New pitch to apply to the music
-
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:
music – Music object
volume – Volume of the music
-
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:
music – Music object
position – Position of the music in the scene
-
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:
music – Music object
relative – sfTrue to set the position relative, sfFalse to set it absolute
-
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:
music – Music object
distance – New minimum distance of the music
-
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:
music – Music object
attenuation – New attenuation factor of the music
-
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:
music – Music object
timeOffset – New playing position
-
float sfMusic_getPitch(const sfMusic *music)#
Get the pitch of a music.
- Parameters:
music – Music object
- Returns:
Pitch of the music
-
float sfMusic_getVolume(const sfMusic *music)#
Get the volume of a music.
- Parameters:
music – Music object
- Returns:
Volume of the music, in the range [0, 100]
-
sfVector3f sfMusic_getPosition(const sfMusic *music)#
Get the 3D position of a music in the audio scene.
- Parameters:
music – Music object
- Returns:
Position of the music in the world
-
sfBool sfMusic_isRelativeToListener(const sfMusic *music)#
Tell whether a music’s position is relative to the listener or is absolute.
- Parameters:
music – Music object
- Returns:
sfTrue if the position is relative, sfFalse if it’s absolute
-
struct sfTimeSpan#
- #include <Music.h>
Structure defining a time range.