Loading...
Searching...
No Matches
Music.h File Reference

Go to the source code of this file.

Classes

struct  sfTimeSpan
 Structure defining a time range. More...
 

Functions

sfMusicsfMusic_createFromFile (const char *filename)
 Create a new music and load it from a file.
 
sfMusicsfMusic_createFromMemory (const void *data, size_t sizeInBytes)
 Create a new music and load it from a file in memory.
 
sfMusicsfMusic_createFromStream (sfInputStream *stream)
 Create a new music and load it from a custom stream.
 
void sfMusic_destroy (const sfMusic *music)
 Destroy a music.
 
void sfMusic_setLooping (sfMusic *music, bool loop)
 Set whether or not a music should loop after reaching the end.
 
bool sfMusic_isLooping (const sfMusic *music)
 Tell whether or not a music is in loop mode.
 
void sfMusic_setEffectProcessor (sfMusic *music, sfEffectProcessor effectProcessor)
 Set the effect processor to be applied to the sound.
 
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 sfTime.
 
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.
 
const sfSoundChannelsfMusic_getChannelMap (const sfMusic *music, size_t *count)
 Get the map of position in sample frame to sound channel.
 
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_setPan (sfMusic *music, float pan)
 Set the pan of the sound.
 
void sfMusic_setVolume (sfMusic *music, float volume)
 Set the volume of a music.
 
void sfMusic_setSpatializationEnabled (sfMusic *music, bool enabled)
 Set whether spatialization of the sound is enabled.
 
void sfMusic_setPosition (sfMusic *music, sfVector3f position)
 Set the 3D position of a music in the audio scene.
 
void sfMusic_setDirection (sfMusic *music, sfVector3f direction)
 Set the 3D direction of the sound in the audio scene.
 
void sfMusic_setCone (sfMusic *music, sfSoundSourceCone cone)
 Set the cone properties of the sound in the audio scene.
 
void sfMusic_setVelocity (sfMusic *music, sfVector3f velocity)
 Set the 3D velocity of the sound in the audio scene.
 
void sfMusic_setDopplerFactor (sfMusic *music, float factor)
 Set the doppler factor of the sound.
 
void sfMusic_setDirectionalAttenuationFactor (sfMusic *music, float factor)
 Set the directional attenuation factor of the sound.
 
void sfMusic_setRelativeToListener (sfMusic *music, bool 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_setMaxDistance (sfMusic *music, float distance)
 Set the maximum distance of the sound.
 
void sfMusic_setMinGain (sfMusic *music, float gain)
 Set the minimum gain of the sound.
 
void sfMusic_setMaxGain (sfMusic *music, float gain)
 Set the maximum gain of the sound.
 
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_getPan (const sfMusic *music)
 Get the pan of the sound.
 
bool sfMusic_isSpatializationEnabled (const sfMusic *music)
 Tell whether spatialization of the sound is enabled.
 
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.
 
sfVector3f sfMusic_getDirection (const sfMusic *music)
 Get the 3D direction of the sound in the audio scene.
 
sfSoundSourceCone sfMusic_getCone (const sfMusic *music)
 Get the cone properties of the sound in the audio scene.
 
sfVector3f sfMusic_getVelocity (const sfMusic *music)
 Get the 3D velocity of the sound in the audio scene.
 
float sfMusic_getDopplerFactor (const sfMusic *music)
 Get the doppler factor of the sound.
 
float sfMusic_getDirectionalAttenuationFactor (const sfMusic *music)
 Get the directional attenuation factor of the sound.
 
bool 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_getMaxDistance (const sfMusic *music)
 Get the maximum distance of the sound.
 
float sfMusic_getMinGain (const sfMusic *music)
 Get the minimum gain of the sound.
 
float sfMusic_getMaxGain (const sfMusic *music)
 Get the maximum gain of the sound.
 
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
filenamePath 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
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()

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
streamSource stream to read from
Returns
A new sfMusic object (NULL if failed)

◆ sfMusic_destroy()

void sfMusic_destroy ( const sfMusic music)

Destroy a music.

Parameters
musicMusic to destroy

◆ sfMusic_getAttenuation()

float sfMusic_getAttenuation ( const sfMusic music)

Get the attenuation factor of a music.

Parameters
musicMusic 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
musicMusic object
Returns
Number of channels

◆ sfMusic_getChannelMap()

const sfSoundChannel * sfMusic_getChannelMap ( const sfMusic music,
size_t *  count 
)

Get the map of position in sample frame to sound channel.

This is used to map a sample in the sample stream to a position during spatialization.

Parameters
musicMusic object
countPointer to a variable that will be filled with the number of channels in the map
Returns
Map of position in sample frame to sound channel

◆ sfMusic_getCone()

sfSoundSourceCone sfMusic_getCone ( const sfMusic music)

Get the cone properties of the sound in the audio scene.

Parameters
musicMusic object
Returns
Cone properties of the sound

◆ sfMusic_getDirection()

sfVector3f sfMusic_getDirection ( const sfMusic music)

Get the 3D direction of the sound in the audio scene.

Parameters
musicMusic object
Returns
Direction of the sound

◆ sfMusic_getDirectionalAttenuationFactor()

float sfMusic_getDirectionalAttenuationFactor ( const sfMusic music)

Get the directional attenuation factor of the sound.

Parameters
musicMusic object
Returns
Directional attenuation factor of the sound

◆ sfMusic_getDopplerFactor()

float sfMusic_getDopplerFactor ( const sfMusic music)

Get the doppler factor of the sound.

Parameters
musicMusic object
Returns
Doppler factor of the sound

◆ sfMusic_getDuration()

sfTime sfMusic_getDuration ( const sfMusic music)

Get the total duration of a music.

Parameters
musicMusic object
Returns
Music duration

◆ sfMusic_getLoopPoints()

sfTimeSpan sfMusic_getLoopPoints ( const sfMusic music)

Get the positions of the of the sound's looping sequence.

Parameters
musicMusic object
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_getMaxDistance()

float sfMusic_getMaxDistance ( const sfMusic music)

Get the maximum distance of the sound.

Parameters
musicMusic object
Returns
Maximum distance of the sound

◆ sfMusic_getMaxGain()

float sfMusic_getMaxGain ( const sfMusic music)

Get the maximum gain of the sound.

Parameters
musicMusic object
Returns
Maximum gain of the sound

◆ sfMusic_getMinDistance()

float sfMusic_getMinDistance ( const sfMusic music)

Get the minimum distance of a music.

Parameters
musicMusic object
Returns
Minimum distance of the music

◆ sfMusic_getMinGain()

float sfMusic_getMinGain ( const sfMusic music)

Get the minimum gain of the sound.

Parameters
musicMusic object
Returns
Minimum gain of the sound

◆ sfMusic_getPan()

float sfMusic_getPan ( const sfMusic music)

Get the pan of the sound.

Parameters
musicMusic object
Returns
Pan of the sound

◆ sfMusic_getPitch()

float sfMusic_getPitch ( const sfMusic music)

Get the pitch of a music.

Parameters
musicMusic object
Returns
Pitch of the music

◆ sfMusic_getPlayingOffset()

sfTime sfMusic_getPlayingOffset ( const sfMusic music)

Get the current playing position of a music.

Parameters
musicMusic 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
musicMusic 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
musicMusic 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
musicMusic object
Returns
Current status

◆ sfMusic_getVelocity()

sfVector3f sfMusic_getVelocity ( const sfMusic music)

Get the 3D velocity of the sound in the audio scene.

Parameters
musicMusic object
Returns
Velocity of the sound

◆ sfMusic_getVolume()

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

bool sfMusic_isLooping ( const sfMusic music)

Tell whether or not a music is in loop mode.

Parameters
musicMusic object
Returns
true if the music is looping, false otherwise

◆ sfMusic_isRelativeToListener()

bool sfMusic_isRelativeToListener ( const sfMusic music)

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

Parameters
musicMusic object
Returns
true if the position is relative, false if it's absolute

◆ sfMusic_isSpatializationEnabled()

bool sfMusic_isSpatializationEnabled ( const sfMusic music)

Tell whether spatialization of the sound is enabled.

Parameters
musicMusic object
Returns
true if spatialization is enabled, false if it's disabled

◆ 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
musicMusic 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
musicMusic 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
musicMusic object
attenuationNew attenuation factor of the music

◆ sfMusic_setCone()

void sfMusic_setCone ( sfMusic music,
sfSoundSourceCone  cone 
)

Set the cone properties of the sound in the audio scene.

The cone defines how directional attenuation is applied. The default cone of a sound is (2 * PI, 2 * PI, 1).

Parameters
musicMusic object
coneCone properties of the sound in the scene

◆ sfMusic_setDirection()

void sfMusic_setDirection ( sfMusic music,
sfVector3f  direction 
)

Set the 3D direction of the sound in the audio scene.

The direction defines where the sound source is facing in 3D space. It will affect how the sound is attenuated if facing away from the listener. The default direction of a sound is (0, 0, -1).

Parameters
musicMusic object
directionDirection of the sound in the scene

◆ sfMusic_setDirectionalAttenuationFactor()

void sfMusic_setDirectionalAttenuationFactor ( sfMusic music,
float  factor 
)

Set the directional attenuation factor of the sound.

Depending on the virtual position of an output channel relative to the listener (such as in surround sound setups), sounds will be attenuated when emitting them from certain channels. This factor determines how strong the attenuation based on output channel position relative to the listener is.

Parameters
musicMusic object
factorNew directional attenuation factor to apply to the sound

◆ sfMusic_setDopplerFactor()

void sfMusic_setDopplerFactor ( sfMusic music,
float  factor 
)

Set the doppler factor of the sound.

The doppler factor determines how strong the doppler shift will be.

Parameters
musicMusic object
factorNew doppler factor to apply to the sound

◆ sfMusic_setEffectProcessor()

void sfMusic_setEffectProcessor ( sfMusic music,
sfEffectProcessor  effectProcessor 
)

Set the effect processor to be applied to the sound.

The effect processor is a callable that will be called with sound data to be processed.

Parameters
musicMusic object
effectProcessorThe effect processor to attach to this sound, attach a null processor to disable processing

◆ sfMusic_setLooping()

void sfMusic_setLooping ( sfMusic music,
bool  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_setLooping(music, false) is called. The default looping state for musics is false.

Parameters
musicMusic object
looptrue to play in loop, false to play once

◆ sfMusic_setLoopPoints()

void sfMusic_setLoopPoints ( sfMusic music,
sfTimeSpan  timePoints 
)

Sets the beginning and end of the sound's looping sequence using sfTime.

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
musicMusic object
timePointsThe definition of the loop. Can be any time points within the sound's length
See also
getLoopPoints

◆ sfMusic_setMaxDistance()

void sfMusic_setMaxDistance ( sfMusic music,
float  distance 
)

Set the maximum distance of the sound.

The "maximum distance" of a sound is the minimum distance at which it is heard at its minimum volume. Closer than the maximum distance, it will start to fade in according to its attenuation factor. The default value of the maximum distance is the maximum value a float can represent.

Parameters
musicMusic object
distanceNew maximum distance of the sound

◆ sfMusic_setMaxGain()

void sfMusic_setMaxGain ( sfMusic music,
float  gain 
)

Set the maximum gain of the sound.

When the sound is closer from the listener than the "minimum distance" the attenuated gain is clamped so it cannot go above the maximum gain value.

Parameters
musicMusic object
gainNew maximum gain of the sound

◆ 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
musicMusic object
distanceNew minimum distance of the music

◆ sfMusic_setMinGain()

void sfMusic_setMinGain ( sfMusic music,
float  gain 
)

Set the minimum gain of the sound.

When the sound is further away from the listener than the "maximum distance" the attenuated gain is clamped so it cannot go below the minimum gain value.

Parameters
musicMusic object
gainNew minimum gain of the sound

◆ sfMusic_setPan()

void sfMusic_setPan ( sfMusic music,
float  pan 
)

Set the pan of the sound.

Using panning, a mono sound can be panned between stereo channels. When the pan is set to -1, the sound is played only on the left channel, when the pan is set to +1, the sound is played only on the right channel.

Parameters
musicMusic object
panNew pan to apply to the sound [-1, +1]

◆ 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
musicMusic object
pitchNew pitch to apply to the music

◆ sfMusic_setPlayingOffset()

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

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

void sfMusic_setRelativeToListener ( sfMusic music,
bool  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
relativetrue to set the position relative, false to set it absolute

◆ sfMusic_setSpatializationEnabled()

void sfMusic_setSpatializationEnabled ( sfMusic music,
bool  enabled 
)

Set whether spatialization of the sound is enabled.

Spatialization is the application of various effects to simulate a sound being emitted at a virtual position in 3D space and exhibiting various physical phenomena such as directional attenuation and doppler shift.

Parameters
musicMusic object
enabledtrue to enable spatialization, false to disable

◆ sfMusic_setVelocity()

void sfMusic_setVelocity ( sfMusic music,
sfVector3f  velocity 
)

Set the 3D velocity of the sound in the audio scene.

The velocity is used to determine how to doppler shift the sound. Sounds moving towards the listener will be perceived to have a higher pitch and sounds moving away from the listener will be perceived to have a lower pitch.

Parameters
musicMusic object
velocityVelocity of the sound in the scene

◆ 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
musicMusic object
volumeVolume 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
musicMusic object