SoundStream

Abstract base class for streamed audio sources.

Unlike audio buffers (see SoundBuffer), audio streams are never completely loaded in memory.

Instead, the audio data is acquired continuously while the stream is playing. This behaviour allows to play a sound with no loading delay, and keeps the memory consumption very low.

Sound sources that need to be streamed are usually big files (compressed audio musics that would eat hundreds of MB in memory) or files that would take a lot of time to be received (sounds played over the network).

SoundStream is a base class that doesn't care about the stream source, which is left to the derived class. SFML provides a built-in specialization for big files (see Music). No network stream source is provided, but you can write your own by combining this class with the network module.

A derived class has to override two virtual functions: - onGetData fills a new chunk of audio data to be played. - onSeek changes the current playing position in the source

It is important to note that each SoundStream is played in its own separate thread, so that the streaming loop doesn't block the rest of the program. In particular, the OnGetData and OnSeek virtual functions may sometimes be called from this separate thread. It is important to keep this in mind, because you may have to take care of synchronization issues if you share data between threads.

Constructors

this
this()
Undocumented in source.

Destructor

~this
~this()
Undocumented in source.

Members

Functions

initialize
void initialize(uint channelCount, uint sampleRate)
Undocumented in source. Be warned that the author may not have intended to support it.
onGetData
bool onGetData(const(short)[] samples)
Undocumented in source.
onSeek
void onSeek(Duration timeOffset)
Undocumented in source.
pause
void pause()
Undocumented in source. Be warned that the author may not have intended to support it.
play
void play()
Undocumented in source. Be warned that the author may not have intended to support it.
stop
void stop()
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

attenuation
float attenuation [@property setter]

The attenuation factor of the sound.

attenuation
float attenuation [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
channelCount
uint channelCount [@property getter]

The number of channels of the stream.

isLooping
bool isLooping [@property setter]

Whether or not the stream should loop after reaching the end.

isLooping
bool isLooping [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
minDistance
float minDistance [@property setter]

The minimum distance of the sound.

minDistance
float minDistance [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
pitch
float pitch [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
pitch
float pitch [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
playingOffset
Duration playingOffset [@property setter]

The current playing position (from the beginning) of the stream.

playingOffset
Duration playingOffset [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
position
Vector3f position [@property setter]

The 3D position of the sound in the audio scene.

position
Vector3f position [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
relativeToListener
bool relativeToListener [@property setter]

Make the sound's position relative to the listener (true) or absolute (false).

relativeToListener
bool relativeToListener [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
sampleRate
uint sampleRate [@property getter]

The stream sample rate of the stream

status
Status status [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
volume
float volume [@property setter]

The volume of the sound.

volume
float volume [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

sfPtr
sfSoundStream* sfPtr;
Undocumented in source.

Inherited Members

From SoundSource

Status
enum Status

Enumeration of the sound source states.

pitch
float pitch [@property setter]

The pitch of the sound.

pitch
float pitch [@property getter]
Undocumented in source.
volume
float volume [@property setter]

The volume of the sound.

volume
float volume [@property getter]
Undocumented in source.
position
Vector3f position [@property setter]

The 3D position of the sound in the audio scene.

position
Vector3f position [@property getter]
Undocumented in source.
relativeToListener
bool relativeToListener [@property setter]

Make the sound's position relative to the listener (true) or absolute (false).

relativeToListener
bool relativeToListener [@property getter]
Undocumented in source.
minDistance
float minDistance [@property setter]

The minimum distance of the sound.

minDistance
float minDistance [@property getter]
Undocumented in source.
attenuation
float attenuation [@property setter]

The attenuation factor of the sound.

attenuation
float attenuation [@property getter]
Undocumented in source.

See Also

Meta

Authors

Laurent Gomila, Jeremy DeHaan