dsfml.audio.soundstream



class SoundStream;
SoundStream is a streamed sound, ie samples are acquired while the sound is playing. Use it for big sounds that would require hundreds of MB in memory, or for streaming sound from the network.

SoundStream is a base class and cannot be instanciated directly.

onGetData override will be called by a different thread, take care of synchronization issues. onStart is called by the thread which called .play().

   class MySoundStream : SoundStream
   {
       this()
       {
           initialize(2, 44100); // you need to initialize the base class before any operation.
       }
       protected bool onGetData(out short[] data)
       {
           //You need to fill data array with some samples

           return true; //or false if you want to stop playback
       }

       protected bool onStart()
       {
           return true;
       }
   }


void play();
Start playing the stream

void pause();
Pause the stream

void stop();
Stop the stream

uint getChannelsCount();
Get number of channels of the stream

Returns:
number of channels

uint getSampleRate();
Get the sample rate of the stream

Returns:
sample rate

SoundStatus getStatus();
Get the current status of the stream

Returns:
Current stream status

void setPitch(float pitch);
Set the sound pitch. The default pitch is 1

Params:
float pitch New pitch

void setVolume(float volume);
Set the sound volume. The default volume is 100

Params:
float volume Volume (in range [0, 100])

void setPosition(Vector3!(float) vec);
Set the sound position (take 3 values). The default position is (0, 0, 0)

Params:
Vector3!(float) vec Position of the sound in the world

void setMinDistance(float minDistance);
Set the minimum distance - closer than this distance, the listener will hear the sound at its maximum volume. The default minimum distance is 1.0

Params:
float minDistance New minimum distance for the sound

void setAttenuation(float attenuation);
Set the attenuation factor - the higher the attenuation, the more the sound will be attenuated with distance from listener. The default attenuation factor 1.0

Params:
float attenuation New attenuation factor for the sound

float getPitch();
Get the pitch

Returns:
Pitch value

float getVolume();
Get the volume

Returns:
Volume value (in range [1, 100])



Vector3!(float) getPosition();
Get the sound position

Returns:
Sound position

float getMinDistance();
Get the minimum distance

Returns:
Get the minimum distance of the sound

float getAttenuation();
Get the attenuation

Returns:
Get the attenuation of the sound

this();
Protected constructor

protected void initialize(uint channelsCount, uint sampleRate);
Initialize the stream

Params:
uint channelsCount number of channel
uint sampleRate sample rate of the stream

Remarks:
if you don"t call this method before any streaming, object will be in an invalid state.

protected abstract bool onStart();
Called each time the stream restart

Returns:
false to abort the playback

protected abstract bool onGetData(out short[] data);
Called each time the stream needs new data. This method will be call by an other thread, take care of possible synchronisation issues.

Params:
short[] data array of samples to stream

Returns:
true to continue streaming, false to stop


Page generated by Ddoc.