CSFML - C binding of the Simple and Fast Multimedia Library

CSFML 3.0.0

- Main Page
- Classes
- Files

- File List
- File Members

Loading...
Searching...
No Matches
Classes | Typedefs | Functions
SoundStream.h File Reference
`#include <CSFML/Audio/Export.h>`
`#include <CSFML/Audio/EffectProcessor.h>`
`#include <CSFML/Audio/SoundChannel.h>`
`#include <CSFML/Audio/SoundSourceCone.h>`
`#include <CSFML/Audio/SoundStatus.h>`
`#include <CSFML/Audio/Types.h>`
`#include <CSFML/System/Time.h>`
`#include <CSFML/System/Vector3.h>`
`#include <stddef.h>`

Go to the source code of this file.

## Classes
struct | sfSoundStreamChunk
| defines the data to fill by the OnGetData callback More...

## Typedefs
typedef bool(* | sfSoundStreamGetDataCallback) (sfSoundStreamChunk *, void *)
| Type of the callback used to get a sound stream data.
typedef void(* | sfSoundStreamSeekCallback) (sfTime, void *)
| Type of the callback used to seek in a sound stream.

## Functions
sfSoundStream * | sfSoundStream_create (sfSoundStreamGetDataCallback onGetData, sfSoundStreamSeekCallback onSeek, unsigned int channelCount, unsigned int sampleRate, sfSoundChannel *channelMapData, size_t channelMapSize, void *userData)
| Create a new sound stream.
void | sfSoundStream_destroy (const sfSoundStream *soundStream)
| Destroy a sound stream.
void | sfSoundStream_play (sfSoundStream *soundStream)
| Start or resume playing a sound stream.
void | sfSoundStream_pause (sfSoundStream *soundStream)
| Pause a sound stream.
void | sfSoundStream_stop (sfSoundStream *soundStream)
| Stop playing a sound stream.
sfSoundStatus | sfSoundStream_getStatus (const sfSoundStream *soundStream)
| Get the current status of a sound stream (stopped, paused, playing)
unsigned int | sfSoundStream_getChannelCount (const sfSoundStream *soundStream)
| Return the number of channels of a sound stream.
unsigned int | sfSoundStream_getSampleRate (const sfSoundStream *soundStream)
| Get the sample rate of a sound stream.
sfSoundChannel * | sfSoundStream_getChannelMap (const sfSoundStream *soundStream, size_t *count)
| Get the map of position in sample frame to sound channel.
void | sfSoundStream_setPitch (sfSoundStream *soundStream, float pitch)
| Set the pitch of a sound stream.
void | sfSoundStream_setPan (sfSoundStream *soundStream, float pan)
| Set the pan of the sound.
void | sfSoundStream_setVolume (sfSoundStream *soundStream, float volume)
| Set the volume of a sound stream.
void | sfSoundStream_setSpatializationEnabled (sfSoundStream *soundStream, bool enabled)
| Set whether spatialization of the sound is enabled.
void | sfSoundStream_setPosition (sfSoundStream *soundStream, sfVector3f position)
| Set the 3D position of a sound stream in the audio scene.
void | sfSoundStream_setDirection (sfSoundStream *soundStream, sfVector3f direction)
| Set the 3D direction of the sound in the audio scene.
void | sfSoundStream_setCone (sfSoundStream *soundStream, sfSoundSourceCone cone)
| Set the cone properties of the sound in the audio scene.
void | sfSoundStream_setVelocity (sfSoundStream *soundStream, sfVector3f velocity)
| Set the 3D velocity of the sound in the audio scene.
void | sfSoundStream_setDopplerFactor (sfSoundStream *soundStream, float factor)
| Set the doppler factor of the sound.
void | sfSoundStream_setDirectionalAttenuationFactor (sfSoundStream *soundStream, float factor)
| Set the directional attenuation factor of the sound.
void | sfSoundStream_setRelativeToListener (sfSoundStream *soundStream, bool relative)
| Make a sound stream's position relative to the listener or absolute.
void | sfSoundStream_setMinDistance (sfSoundStream *soundStream, float distance)
| Set the minimum distance of a sound stream.
void | sfSoundStream_setMaxDistance (sfSoundStream *soundStream, float distance)
| Set the maximum distance of the sound.
void | sfSoundStream_setMinGain (sfSoundStream *soundStream, float gain)
| Set the minimum gain of the sound.
void | sfSoundStream_setMaxGain (sfSoundStream *soundStream, float gain)
| Set the maximum gain of the sound.
void | sfSoundStream_setAttenuation (sfSoundStream *soundStream, float attenuation)
| Set the attenuation factor of a sound stream.
void | sfSoundStream_setPlayingOffset (sfSoundStream *soundStream, sfTime timeOffset)
| Change the current playing position of a sound stream.
void | sfSoundStream_setLooping (sfSoundStream *soundStream, bool loop)
| Set whether or not a sound stream should loop after reaching the end.
float | sfSoundStream_getPitch (const sfSoundStream *soundStream)
| Get the pitch of a sound stream.
float | sfSoundStream_getPan (const sfSoundStream *soundStream)
| Get the pan of the sound.
float | sfSoundStream_getVolume (const sfSoundStream *soundStream)
| Get the volume of a sound stream.
bool | sfSoundStream_isSpatializationEnabled (const sfSoundStream *soundStream)
| Tell whether spatialization of the sound is enabled.
sfVector3f | sfSoundStream_getPosition (const sfSoundStream *soundStream)
| Get the 3D position of a sound stream in the audio scene.
sfVector3f | sfSoundStream_getDirection (const sfSoundStream *soundStream)
| Get the 3D direction of the sound in the audio scene.
sfSoundSourceCone | sfSoundStream_getCone (const sfSoundStream *soundStream)
| Get the cone properties of the sound in the audio scene.
sfVector3f | sfSoundStream_getVelocity (const sfSoundStream *soundStream)
| Get the 3D velocity of the sound in the audio scene.
float | sfSoundStream_getDopplerFactor (const sfSoundStream *soundStream)
| Get the doppler factor of the sound.
float | sfSoundStream_getDirectionalAttenuationFactor (const sfSoundStream *soundStream)
| Get the directional attenuation factor of the sound.
bool | sfSoundStream_isRelativeToListener (const sfSoundStream *soundStream)
| Tell whether a sound stream's position is relative to the listener or is absolute.
float | sfSoundStream_getMinDistance (const sfSoundStream *soundStream)
| Get the minimum distance of a sound stream.
float | sfSoundStream_getMaxDistance (const sfSoundStream *soundStream)
| Get the maximum distance of the sound.
float | sfSoundStream_getMinGain (const sfSoundStream *soundStream)
| Get the minimum gain of the sound.
float | sfSoundStream_getMaxGain (const sfSoundStream *soundStream)
| Get the maximum gain of the sound.
float | sfSoundStream_getAttenuation (const sfSoundStream *soundStream)
| Get the attenuation factor of a sound stream.
bool | sfSoundStream_isLooping (const sfSoundStream *soundStream)
| Tell whether or not a sound stream is in loop mode.
void | sfSoundStream_setEffectProcessor (sfSoundStream *soundStream, sfEffectProcessor effectProcessor)
| Set the effect processor to be applied to the sound.
sfTime | sfSoundStream_getPlayingOffset (const sfSoundStream *soundStream)
| Get the current playing position of a sound stream.

## Typedef Documentation

## ◆ sfSoundStreamGetDataCallback

typedef bool(* sfSoundStreamGetDataCallback) (sfSoundStreamChunk *, void *)

Type of the callback used to get a sound stream data.

Definition at line 53 of file SoundStream.h.

## ◆ sfSoundStreamSeekCallback

typedef void(* sfSoundStreamSeekCallback) (sfTime, void *)

Type of the callback used to seek in a sound stream.

Definition at line 54 of file SoundStream.h.

## Function Documentation

## ◆ sfSoundStream_create()

sfSoundStream * sfSoundStream_create | ( | sfSoundStreamGetDataCallback | onGetData,
|  | sfSoundStreamSeekCallback | onSeek,
|  | unsigned int | channelCount,
|  | unsigned int | sampleRate,
|  | sfSoundChannel * | channelMapData,
|  | size_t | channelMapSize,
|  | void * | userData )

Create a new sound stream.

Parameters

  onGetData | Function called when the stream needs more data (can't be NULL)
  onSeek | Function called when the stream seeks (can't be NULL)
  channelCount | Number of channels to use (1 = mono, 2 = stereo)
  sampleRate | Sample rate of the sound (44100 = CD quality)
  channelMapData | Pointer to the array of channel map data
  channelMapSize | Size of channel map data array
  userData | Data to pass to the callback functions

Returns
  A new sfSoundStream object

## ◆ sfSoundStream_destroy()

void sfSoundStream_destroy | ( | const sfSoundStream * | soundStream | ) |

Destroy a sound stream.

Parameters

  soundStream | Sound stream to destroy

## ◆ sfSoundStream_getAttenuation()

float sfSoundStream_getAttenuation | ( | const sfSoundStream * | soundStream | ) |

Get the attenuation factor of a sound stream.

Parameters

  soundStream | Sound stream object

Returns
  Attenuation factor of the stream

## ◆ sfSoundStream_getChannelCount()

unsigned int sfSoundStream_getChannelCount | ( | const sfSoundStream * | soundStream | ) |

Return the number of channels of a sound stream.

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

Parameters

  soundStream | Sound stream object

Returns
  Number of channels

## ◆ sfSoundStream_getChannelMap()

sfSoundChannel * sfSoundStream_getChannelMap | ( | const sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  count | Pointer 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

## ◆ sfSoundStream_getCone()

sfSoundSourceCone sfSoundStream_getCone | ( | const sfSoundStream * | soundStream | ) |

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

Parameters

  soundStream | Sound stream object

Returns
  Cone properties of the sound

## ◆ sfSoundStream_getDirection()

sfVector3f sfSoundStream_getDirection | ( | const sfSoundStream * | soundStream | ) |

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

Parameters

  soundStream | Sound stream object

Returns
  Direction of the sound

## ◆ sfSoundStream_getDirectionalAttenuationFactor()

float sfSoundStream_getDirectionalAttenuationFactor | ( | const sfSoundStream * | soundStream | ) |

Get the directional attenuation factor of the sound.

Parameters

  soundStream | Sound stream object

Returns
  Directional attenuation factor of the sound

## ◆ sfSoundStream_getDopplerFactor()

float sfSoundStream_getDopplerFactor | ( | const sfSoundStream * | soundStream | ) |

Get the doppler factor of the sound.

Parameters

  soundStream | Sound stream object

Returns
  Doppler factor of the sound

## ◆ sfSoundStream_getMaxDistance()

float sfSoundStream_getMaxDistance | ( | const sfSoundStream * | soundStream | ) |

Get the maximum distance of the sound.

Parameters

  soundStream | Sound stream object

Returns
  Maximum distance of the sound

## ◆ sfSoundStream_getMaxGain()

float sfSoundStream_getMaxGain | ( | const sfSoundStream * | soundStream | ) |

Get the maximum gain of the sound.

Parameters

  soundStream | Sound stream object

Returns
  Maximum gain of the sound

## ◆ sfSoundStream_getMinDistance()

float sfSoundStream_getMinDistance | ( | const sfSoundStream * | soundStream | ) |

Get the minimum distance of a sound stream.

Parameters

  soundStream | Sound stream object

Returns
  Minimum distance of the stream

## ◆ sfSoundStream_getMinGain()

float sfSoundStream_getMinGain | ( | const sfSoundStream * | soundStream | ) |

Get the minimum gain of the sound.

Parameters

  soundStream | Sound stream object

Returns
  Minimum gain of the sound

## ◆ sfSoundStream_getPan()

float sfSoundStream_getPan | ( | const sfSoundStream * | soundStream | ) |

Get the pan of the sound.

Parameters

  soundStream | Sound stream object

Returns
  Pan of the sound

## ◆ sfSoundStream_getPitch()

float sfSoundStream_getPitch | ( | const sfSoundStream * | soundStream | ) |

Get the pitch of a sound stream.

Parameters

  soundStream | Sound stream object

Returns
  Pitch of the stream

## ◆ sfSoundStream_getPlayingOffset()

sfTime sfSoundStream_getPlayingOffset | ( | const sfSoundStream * | soundStream | ) |

Get the current playing position of a sound stream.

Parameters

  soundStream | Sound stream object

Returns
  Current playing position

## ◆ sfSoundStream_getPosition()

sfVector3f sfSoundStream_getPosition | ( | const sfSoundStream * | soundStream | ) |

Get the 3D position of a sound stream in the audio scene.

Parameters

  soundStream | Sound stream object

Returns
  Position of the stream in the world

## ◆ sfSoundStream_getSampleRate()

unsigned int sfSoundStream_getSampleRate | ( | const sfSoundStream * | soundStream | ) |

Get the sample rate of a sound stream.

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

Parameters

  soundStream | Sound stream object

Returns
  Sample rate, in number of samples per second

## ◆ sfSoundStream_getStatus()

sfSoundStatus sfSoundStream_getStatus | ( | const sfSoundStream * | soundStream | ) |

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

Parameters

  soundStream | Sound stream object

Returns
  Current status

## ◆ sfSoundStream_getVelocity()

sfVector3f sfSoundStream_getVelocity | ( | const sfSoundStream * | soundStream | ) |

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

Parameters

  soundStream | Sound stream object

Returns
  Velocity of the sound

## ◆ sfSoundStream_getVolume()

float sfSoundStream_getVolume | ( | const sfSoundStream * | soundStream | ) |

Get the volume of a sound stream.

Parameters

  soundStream | Sound stream object

Returns
  Volume of the stream, in the range [0, 100]

## ◆ sfSoundStream_isLooping()

bool sfSoundStream_isLooping | ( | const sfSoundStream * | soundStream | ) |

Tell whether or not a sound stream is in loop mode.

Parameters

  soundStream | Sound stream object

Returns
  true if the music is looping, false otherwise

## ◆ sfSoundStream_isRelativeToListener()

bool sfSoundStream_isRelativeToListener | ( | const sfSoundStream * | soundStream | ) |

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

Parameters

  soundStream | Sound stream object

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

## ◆ sfSoundStream_isSpatializationEnabled()

bool sfSoundStream_isSpatializationEnabled | ( | const sfSoundStream * | soundStream | ) |

Tell whether spatialization of the sound is enabled.

Parameters

  soundStream | Sound stream object

Returns
  `true` if spatialization is enabled, `false` if it's disabled

## ◆ sfSoundStream_pause()

void sfSoundStream_pause | ( | sfSoundStream * | soundStream | ) |

Pause a sound stream.

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

Parameters

  soundStream | Sound stream object

## ◆ sfSoundStream_play()

void sfSoundStream_play | ( | sfSoundStream * | soundStream | ) |

Start or resume playing a sound stream.

This function starts the stream 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

  soundStream | Sound stream object

## ◆ sfSoundStream_setAttenuation()

void sfSoundStream_setAttenuation | ( | sfSoundStream * | soundStream,
|  | float | attenuation )

Set the attenuation factor of a sound stream.

The attenuation is a multiplicative factor which makes the stream more or less loud according to its distance from the listener. An attenuation of 0 will produce a non-attenuated stream, 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 stream fade out very quickly as it gets further from the listener. The default value of the attenuation is 1.

Parameters

  soundStream | Sound stream object
  attenuation | New attenuation factor of the stream

## ◆ sfSoundStream_setCone()

void sfSoundStream_setCone | ( | sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  cone | Cone properties of the sound in the scene

## ◆ sfSoundStream_setDirection()

void sfSoundStream_setDirection | ( | sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  direction | Direction of the sound in the scene

## ◆ sfSoundStream_setDirectionalAttenuationFactor()

void sfSoundStream_setDirectionalAttenuationFactor | ( | sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  factor | New directional attenuation factor to apply to the sound

## ◆ sfSoundStream_setDopplerFactor()

void sfSoundStream_setDopplerFactor | ( | sfSoundStream * | soundStream,
|  | float | factor )

Set the doppler factor of the sound.

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

Parameters

  soundStream | Sound stream object
  factor | New doppler factor to apply to the sound

## ◆ sfSoundStream_setEffectProcessor()

void sfSoundStream_setEffectProcessor | ( | sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  effectProcessor | The effect processor to attach to this sound, attach an empty processor to disable processing

## ◆ sfSoundStream_setLooping()

void sfSoundStream_setLooping | ( | sfSoundStream * | soundStream,
|  | bool | loop )

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

If set, the stream will restart from beginning after reaching the end and so on, until it is stopped or sfSoundStream_setLooping(stream, false) is called. The default looping state for sound streams is false.

Parameters

  soundStream | Sound stream object
  loop | true to play in loop, false to play once

## ◆ sfSoundStream_setMaxDistance()

void sfSoundStream_setMaxDistance | ( | sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  distance | New maximum distance of the sound

## ◆ sfSoundStream_setMaxGain()

void sfSoundStream_setMaxGain | ( | sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  gain | New maximum gain of the sound

## ◆ sfSoundStream_setMinDistance()

void sfSoundStream_setMinDistance | ( | sfSoundStream * | soundStream,
|  | float | distance )

Set the minimum distance of a sound stream.

The "minimum distance" of a stream 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

  soundStream | Sound stream object
  distance | New minimum distance of the stream

## ◆ sfSoundStream_setMinGain()

void sfSoundStream_setMinGain | ( | sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  gain | New minimum gain of the sound

## ◆ sfSoundStream_setPan()

void sfSoundStream_setPan | ( | sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  pan | New pan to apply to the sound [-1, +1]

## ◆ sfSoundStream_setPitch()

void sfSoundStream_setPitch | ( | sfSoundStream * | soundStream,
|  | float | pitch )

Set the pitch of a sound stream.

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

Parameters

  soundStream | Sound stream object
  pitch | New pitch to apply to the stream

## ◆ sfSoundStream_setPlayingOffset()

void sfSoundStream_setPlayingOffset | ( | sfSoundStream * | soundStream,
|  | sfTime | timeOffset )

Change the current playing position of a sound stream.

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

Parameters

  soundStream | Sound stream object
  timeOffset | New playing position

## ◆ sfSoundStream_setPosition()

void sfSoundStream_setPosition | ( | sfSoundStream * | soundStream,
|  | sfVector3f | position )

Set the 3D position of a sound stream in the audio scene.

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

Parameters

  soundStream | Sound stream object
  position | Position of the stream in the scene

## ◆ sfSoundStream_setRelativeToListener()

void sfSoundStream_setRelativeToListener | ( | sfSoundStream * | soundStream,
|  | bool | relative )

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

Making a stream 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 streams, streams that are produced by the listener, or streams attached to it. The default value is false (position is absolute).

Parameters

  soundStream | Sound stream object
  relative | true to set the position relative, false to set it absolute

## ◆ sfSoundStream_setSpatializationEnabled()

void sfSoundStream_setSpatializationEnabled | ( | sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  enabled | `true` to enable spatialization, `false` to disable

## ◆ sfSoundStream_setVelocity()

void sfSoundStream_setVelocity | ( | sfSoundStream * | soundStream,
|  | 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

  soundStream | Sound stream object
  velocity | Velocity of the sound in the scene

## ◆ sfSoundStream_setVolume()

void sfSoundStream_setVolume | ( | sfSoundStream * | soundStream,
|  | float | volume )

Set the volume of a sound stream.

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

Parameters

  soundStream | Sound stream object
  volume | Volume of the stream

## ◆ sfSoundStream_stop()

void sfSoundStream_stop | ( | sfSoundStream * | soundStream | ) |

Stop playing a sound stream.

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

Parameters

  soundStream | Sound stream object