#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.
Classes | |
struct | sfTimeSpan |
Structure defining a time range. More... | |
Functions | |
sfMusic * | sfMusic_createFromFile (const char *filename) |
Create a new music and load it from a file. | |
sfMusic * | sfMusic_createFromMemory (const void *data, size_t sizeInBytes) |
Create a new music and load it from a file in memory. | |
sfMusic * | sfMusic_createFromStream (sfInputStream *stream) |
Create a new music and load it from a custom stream. | |
void | sfMusic_destroy (sfMusic *music) |
Destroy a music. | |
void | sfMusic_setLoop (sfMusic *music, sfBool loop) |
Set whether or not a music should loop after reaching the end. | |
sfBool | sfMusic_getLoop (const sfMusic *music) |
Tell whether or not a music is in loop mode. | |
sfTime | sfMusic_getDuration (const sfMusic *music) |
Get the total duration of a music. | |
sfTimeSpan | sfMusic_getLoopPoints (const sfMusic *music) |
Get the positions of the of the sound's looping sequence. | |
void | sfMusic_setLoopPoints (sfMusic *music, sfTimeSpan timePoints) |
Sets the beginning and end of the sound's looping sequence using sf::Time. | |
void | sfMusic_play (sfMusic *music) |
Start or resume playing a music. | |
void | sfMusic_pause (sfMusic *music) |
Pause a music. | |
void | sfMusic_stop (sfMusic *music) |
Stop playing a music. | |
unsigned int | sfMusic_getChannelCount (const sfMusic *music) |
Return the number of channels of a music. | |
unsigned int | sfMusic_getSampleRate (const sfMusic *music) |
Get the sample rate of a music. | |
sfSoundStatus | sfMusic_getStatus (const sfMusic *music) |
Get the current status of a music (stopped, paused, playing) | |
sfTime | sfMusic_getPlayingOffset (const sfMusic *music) |
Get the current playing position of a music. | |
void | sfMusic_setPitch (sfMusic *music, float pitch) |
Set the pitch of a music. | |
void | sfMusic_setVolume (sfMusic *music, float volume) |
Set the volume of a music. | |
void | sfMusic_setPosition (sfMusic *music, sfVector3f position) |
Set the 3D position of a music in the audio scene. | |
void | sfMusic_setRelativeToListener (sfMusic *music, sfBool relative) |
Make a musics's position relative to the listener or absolute. | |
void | sfMusic_setMinDistance (sfMusic *music, float distance) |
Set the minimum distance of a music. | |
void | sfMusic_setAttenuation (sfMusic *music, float attenuation) |
Set the attenuation factor of a music. | |
void | sfMusic_setPlayingOffset (sfMusic *music, sfTime timeOffset) |
Change the current playing position of a music. | |
float | sfMusic_getPitch (const sfMusic *music) |
Get the pitch of a music. | |
float | sfMusic_getVolume (const sfMusic *music) |
Get the volume of a music. | |
sfVector3f | sfMusic_getPosition (const sfMusic *music) |
Get the 3D position of a music in the audio scene. | |
sfBool | sfMusic_isRelativeToListener (const sfMusic *music) |
Tell whether a music's position is relative to the listener or is absolute. | |
float | sfMusic_getMinDistance (const sfMusic *music) |
Get the minimum distance of a music. | |
float | sfMusic_getAttenuation (const sfMusic *music) |
Get the attenuation factor of a music. | |
Function Documentation
◆ sfMusic_createFromFile()
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, mp3, 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_createFromMemory()
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, mp3, 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_createFromStream()
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, mp3, 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)
◆ sfMusic_destroy()
void sfMusic_destroy | ( | sfMusic * | music | ) |
Destroy a music.
- Parameters
-
music Music to destroy
◆ sfMusic_getAttenuation()
float sfMusic_getAttenuation | ( | const sfMusic * | music | ) |
Get the attenuation factor of a music.
- Parameters
-
music Music object
- Returns
- Attenuation factor of the music
◆ sfMusic_getChannelCount()
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
◆ sfMusic_getDuration()
Get the total duration of a music.
- Parameters
-
music Music object
- Returns
- Music duration
◆ sfMusic_getLoop()
Tell whether or not a music is in loop mode.
- Parameters
-
music Music object
- Returns
- sfTrue if the music is looping, sfFalse otherwise
◆ sfMusic_getLoopPoints()
sfTimeSpan sfMusic_getLoopPoints | ( | const sfMusic * | music | ) |
Get the positions of the of the sound's looping sequence.
- Returns
- Loop Time position class.
- 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().
- See also
- setLoopPoints
◆ sfMusic_getMinDistance()
float sfMusic_getMinDistance | ( | const sfMusic * | music | ) |
Get the minimum distance of a music.
- Parameters
-
music Music object
- Returns
- Minimum distance of the music
◆ sfMusic_getPitch()
float sfMusic_getPitch | ( | const sfMusic * | music | ) |
Get the pitch of a music.
- Parameters
-
music Music object
- Returns
- Pitch of the music
◆ sfMusic_getPlayingOffset()
Get the current playing position of a music.
- Parameters
-
music Music object
- Returns
- Current playing position
◆ sfMusic_getPosition()
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
◆ sfMusic_getSampleRate()
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
◆ sfMusic_getStatus()
sfSoundStatus sfMusic_getStatus | ( | const sfMusic * | music | ) |
Get the current status of a music (stopped, paused, playing)
- Parameters
-
music Music object
- Returns
- Current status
◆ sfMusic_getVolume()
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]
◆ sfMusic_isRelativeToListener()
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
◆ sfMusic_pause()
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
◆ sfMusic_play()
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
◆ sfMusic_setAttenuation()
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
◆ sfMusic_setLoop()
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
◆ sfMusic_setLoopPoints()
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.
- 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
- See also
- getLoopPoints
◆ sfMusic_setMinDistance()
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
◆ sfMusic_setPitch()
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
◆ sfMusic_setPlayingOffset()
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
◆ sfMusic_setPosition()
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
◆ sfMusic_setRelativeToListener()
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
◆ sfMusic_setVolume()
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
◆ sfMusic_stop()
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