CSFML - C binding of the Simple and Fast Multimedia Library

CSFML

- Main Page
- Data Structures
- Files

- File List
- Globals

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 sfMusic * | sfMusic_createFromFile (const char *filename)
| Create a new music and load it from a file. More...
CSFML_AUDIO_API sfMusic * | sfMusic_createFromMemory (const void *data, size_t sizeInBytes)
| Create a new music and load it from a file in memory. More...
CSFML_AUDIO_API sfMusic * | sfMusic_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

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

  filename | Path of the music file to open

Returns
  A new sfMusic object (NULL if failed)

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

  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)

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

  stream | Source stream to read from

Returns
  A new sfMusic object (NULL if failed)

CSFML_AUDIO_API void sfMusic_destroy | ( | sfMusic * | music | ) |

Destroy a music.

Parameters

  music | Music to destroy

CSFML_AUDIO_API float sfMusic_getAttenuation | ( | const sfMusic * | music | ) |

Get the attenuation factor of a music.

Parameters

  music | Music object

Returns
  Attenuation factor of the music

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

  music | Music object

Returns
  Number of channels

CSFML_AUDIO_API sfTime sfMusic_getDuration | ( | const sfMusic * | music | ) |

Get the total duration of a music.

Parameters

  music | Music object

Returns
  Music duration

CSFML_AUDIO_API 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

CSFML_AUDIO_API float sfMusic_getMinDistance | ( | const sfMusic * | music | ) |

Get the minimum distance of a music.

Parameters

  music | Music object

Returns
  Minimum distance of the music

CSFML_AUDIO_API float sfMusic_getPitch | ( | const sfMusic * | music | ) |

Get the pitch of a music.

Parameters

  music | Music object

Returns
  Pitch of the music

CSFML_AUDIO_API sfTime sfMusic_getPlayingOffset | ( | const sfMusic * | music | ) |

Get the current playing position of a music.

Parameters

  music | Music object

Returns
  Current playing position

CSFML_AUDIO_API 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

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

  music | Music object

Returns
  Sample rate, in number of samples per second

CSFML_AUDIO_API sfSoundStatus sfMusic_getStatus | ( | const sfMusic * | music | ) |

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

Parameters

  music | Music object

Returns
  Current status

CSFML_AUDIO_API 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]

CSFML_AUDIO_API 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

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

  music | Music object

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

  music | Music object

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

  music | Music object
  attenuation | New attenuation factor of the music

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

  music | Music object
  loop | sfTrue to play in loop, sfFalse to play once

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

  music | Music object
  distance | New minimum distance of the music

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

  music | Music object
  pitch | New pitch to apply to the music

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

  music | Music object
  timeOffset | New playing position

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

  music | Music object
  position | Position of the music in the scene

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

  music | Music object
  relative | sfTrue to set the position relative, sfFalse to set it absolute

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

  music | Music object
  volume | Volume of the music

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

  music | Music object