* created SoundSource base class

* Music, SoundStream and Sound inherit from SoundSource
* moved SoundStatus struct to SoundSource.d

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1348 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
trass3r 2010-01-11 21:15:23 +00:00
parent 77d248f79e
commit 06d91c6020
6 changed files with 346 additions and 727 deletions

View File

@ -33,5 +33,4 @@ public import
dsfml.audio.soundbuffer,
dsfml.audio.soundbufferrecorder,
dsfml.audio.soundrecorder,
dsfml.audio.soundstatus,
dsfml.audio.soundstream;

View File

@ -26,7 +26,7 @@
module dsfml.audio.music;
import dsfml.audio.soundstatus;
import dsfml.audio.soundsource;
import dsfml.system.common;
import dsfml.system.exception;
@ -37,7 +37,7 @@ import dsfml.system.vector3;
* Music defines a big sound played using streaming,
* so usually what we call a music :)
*/
class Music : DSFMLObject
class Music : SoundSource!("sfMusic")
{
/**
* Open a music file (doesn't play it -- call Play for that)
@ -51,7 +51,7 @@ class Music : DSFMLObject
if (filename is null || filename.length == 0)
throw new LoadingException("LoadingException : Filename is invalid.");
super(sfMusic_CreateFromFile(toStringz(filename)));
m_ptr = sfMusic_CreateFromFile(toStringz(filename)); // TODO: this is a hack, should properly call the super constructor
}
/**
@ -66,12 +66,7 @@ class Music : DSFMLObject
if (data is null || data.length == 0)
throw new Exception("LoadingException : Memory stream is invalid.");
super(m_ptr = sfMusic_CreateFromMemory(data.ptr, data.length));
}
override void dispose()
{
sfMusic_Destroy(m_ptr);
m_ptr = sfMusic_CreateFromMemory(data.ptr, data.length); // TODO: ditto
}
/**
@ -133,18 +128,6 @@ class Music : DSFMLObject
return sfMusic_GetDuration(m_ptr);
}
/**
* Get the status of the stream (stopped, paused, playing)
*
* Returns:
* Current status of the sound
*/
SoundStatus getStatus()
{
return sfMusic_GetStatus(m_ptr);
}
/**
* Tell whether or not the music is looping
*
@ -156,65 +139,6 @@ class Music : DSFMLObject
return cast(bool)sfMusic_GetLoop(m_ptr);
}
/**
* Get the pitch
*
* Returns:
* Pitch value
*/
float getPitch()
{
return sfMusic_GetPitch(m_ptr);
}
/**
* Get the volume
*
* Returns:
* Volume value (in range [1, 100])
*/
float getVolume()
{
return sfMusic_GetVolume(m_ptr);
}
/**
* Get the sound position
*
* Returns:
* Current position of the music.
*/
Vector3f getPosition()
{
Vector3f ret;
sfMusic_GetPosition(m_ptr, &ret.x, &ret.y, &ret.z);
return ret;
}
/**
* Get the minimum distance
*
* Returns:
* Minimum distance for the sound
*/
float getMinDistance()
{
return sfMusic_GetMinDistance(m_ptr);
}
/**
* Get the attenuation factor
*
* Returns:
* Attenuation factor of the sound
*
*/
float getAttenuation()
{
return sfMusic_GetAttenuation(m_ptr);
}
/**
* Set the music loop state.
* This parameter is disabled by default
@ -226,116 +150,6 @@ class Music : DSFMLObject
{
sfMusic_SetLoop(m_ptr, loop);
}
/**
* Set the sound pitch.
* The default pitch is 1
*
* Params:
* pitch = New pitch
*
*/
void setPitch(float pitch)
{
sfMusic_SetPitch(m_ptr, pitch);
}
/**
* Set the sound volume.
* The default volume is 100
*
* Params:
* volume = Volume (in range [0, 100])
*
*/
void setVolume(float volume)
in
{
assert (volume >= 0.f && volume <= 100.f);
}
body
{
sfMusic_SetVolume(m_ptr, volume);
}
/**
* Set the sound position.
* The default position is (0, 0, 0)
*
* Params:
* x = X position of the sound in the world
* y = Y position of the sound in the world
* z = Z position of the sound in the world
*
*/
void setPosition(float x, float y, float z)
{
sfMusic_SetPosition(m_ptr, x, y, z);
}
/**
* Set the sound position.
* The default position is (0, 0, 0)
*
* Params:
* position = new position
*
*/
void setPosition(Vector3f position)
{
sfMusic_SetPosition(m_ptr, position.x, position.y, position.z);
}
/**
* Set the minimum distance - closer than thsi distance
* the listener will hear the sound at its maximum volume.
* The default distance is 1.0
*
* Params:
* minDistance = new minimum distance for the sound
*/
void setMinDistance(float minDistance)
{
sfMusic_SetMinDistance(m_ptr, minDistance);
}
/**
* 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:
* attenuation = new attenuation factor for the sound
*/
void setAttenuation(float attenuation)
{
sfMusic_SetAttenuation(m_ptr, attenuation);
}
/**
* Make the music's position relative to the listener's position, or absolute.
* The default value is false (absolute)
*
* Params:
* relative = True to set the position relative, false to set it absolute
*/
void setRelativeToListener(bool relative)
{
sfMusic_SetRelativeToListener(m_ptr, relative);
}
/**
* Tell if the music's position is relative to the listener's
* position, or if it's absolute
*
* Returns:
* true if the position is relative, sfFalse if it's absolute
*/
bool isRelativeToListener()
{
return sfMusic_IsRelativeToListener(m_ptr);
}
}
private:
@ -344,7 +158,6 @@ extern(C)
{
void* function(cchar*) sfMusic_CreateFromFile;
void* function(byte*, size_t) sfMusic_CreateFromMemory;
void function(void*) sfMusic_Destroy;
void function(void*, int) sfMusic_SetLoop;
bool function(void*) sfMusic_GetLoop;
float function(void*) sfMusic_GetDuration;
@ -353,21 +166,6 @@ void function(void*) sfMusic_Pause;
void function(void*) sfMusic_Stop;
uint function(void*) sfMusic_GetChannelsCount;
uint function(void*) sfMusic_GetSampleRate;
SoundStatus function(void*) sfMusic_GetStatus;
void function(void*, float) sfMusic_SetPitch;
void function(void*, float) sfMusic_SetVolume;
void function(void*, float, float, float) sfMusic_SetPosition;
float function(void*) sfMusic_GetPitch;
float function(void*) sfMusic_GetVolume;
void function(void*, float*, float*, float*)sfMusic_GetPosition;
float function(void*) sfMusic_GetMinDistance;
float function(void*) sfMusic_GetAttenuation;
void function(void*, float) sfMusic_SetMinDistance;
void function(void*, float) sfMusic_SetAttenuation;
void function(void*, bool) sfMusic_SetRelativeToListener;
bool function(void*) sfMusic_IsRelativeToListener;
}
static this()
@ -379,7 +177,6 @@ else
mixin(loadFromSharedLib("sfMusic_CreateFromFile"));
mixin(loadFromSharedLib("sfMusic_CreateFromMemory"));
mixin(loadFromSharedLib("sfMusic_Destroy"));
mixin(loadFromSharedLib("sfMusic_SetLoop"));
mixin(loadFromSharedLib("sfMusic_GetLoop"));
mixin(loadFromSharedLib("sfMusic_GetDuration"));
@ -388,18 +185,4 @@ else
mixin(loadFromSharedLib("sfMusic_Stop"));
mixin(loadFromSharedLib("sfMusic_GetChannelsCount"));
mixin(loadFromSharedLib("sfMusic_GetSampleRate"));
mixin(loadFromSharedLib("sfMusic_GetStatus"));
mixin(loadFromSharedLib("sfMusic_SetPitch"));
mixin(loadFromSharedLib("sfMusic_SetVolume"));
mixin(loadFromSharedLib("sfMusic_SetPosition"));
mixin(loadFromSharedLib("sfMusic_GetPitch"));
mixin(loadFromSharedLib("sfMusic_GetVolume"));
mixin(loadFromSharedLib("sfMusic_GetPosition"));
mixin(loadFromSharedLib("sfMusic_GetMinDistance"));
mixin(loadFromSharedLib("sfMusic_GetAttenuation"));
mixin(loadFromSharedLib("sfMusic_SetMinDistance"));
mixin(loadFromSharedLib("sfMusic_SetAttenuation"));
mixin(loadFromSharedLib("sfMusic_SetRelativeToListener"));
mixin(loadFromSharedLib("sfMusic_IsRelativeToListener"));
}

View File

@ -27,7 +27,7 @@
module dsfml.audio.sound;
import dsfml.audio.soundbuffer;
import dsfml.audio.soundstatus;
import dsfml.audio.soundsource;
import dsfml.system.common;
import dsfml.system.exception;
@ -37,14 +37,14 @@ import dsfml.system.vector3;
* Sound defines the properties of the sound such as position,
* volume, pitch, etc.
*/
class Sound : DSFMLObject
class Sound : SoundSource!("sfSound")
{
/**
* Default constructor
*/
this()
{
super(sfSound_Create());
super();
}
/**
@ -67,20 +67,15 @@ class Sound : DSFMLObject
if (buffer is null)
throw new NullParameterException("NullParameterException : SoundBuffer is null.");
super(sfSound_Create());
super();
sfSound_SetBuffer(m_ptr, buffer.getNativePointer());
sfSound_SetLoop(m_ptr, loop);
sfSound_SetPitch(m_ptr, pitch);
sfSound_SetVolume(m_ptr, volume);
sfSound_SetPosition(m_ptr, x, y, z);
setPitch(pitch);
setVolume(volume);
setPosition(x, y, z);
}
override void dispose()
{
sfSound_Destroy(m_ptr);
}
/**
* Play the sound
*/
@ -132,87 +127,6 @@ class Sound : DSFMLObject
sfSound_SetLoop(m_ptr, loop);
}
/**
* Set the sound pitch.
* The default pitch is 1
*
* Params:
* pitch = New pitch
*/
void setPitch(float pitch)
{
sfSound_SetPitch(m_ptr, pitch);
}
/**
* Set the sound volume.
* The default volume is 100
*
* Params:
* volume = Volume (in range [0, 100])
*/
void setVolume(float volume)
in
{
assert(volume >= 0 && volume <= 100);
}
body
{
sfSound_SetVolume(m_ptr, volume);
}
/**
* Set the sound position.
* The default position is (0, 0, 0)
*
* Params:
* x = X position of the sound in the world
* y = Y position of the sound in the world
* z = Z position of the sound in the world
*/
void setPosition(float x, float y, float z)
{
sfSound_SetPosition(m_ptr, x, y, z);
}
/**
* Set the sound position.
* The default position is (0, 0, 0)
*
* Params :
* position = new position
*/
void setPosition(Vector3f position)
{
sfSound_SetPosition(m_ptr, position.x, position.y, position.z);
}
/**
* Set the minimum distance - closer than this distance
* the listener will hear the sound at its maximum volume.
* The default distance is 1.0
*
* Params:
* minDistance = new minimum distance for the sound
*/
void setMinDistance(float minDistance)
{
sfSound_SetMinDistance(m_ptr, minDistance);
}
/**
* 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:
* attenuation = new attenuation factor for the sound
*/
void setAttenuation(float attenuation)
{
sfSound_SetAttenuation(m_ptr, attenuation);
}
/**
* Set the current playing offset of a sound
*
@ -248,78 +162,6 @@ class Sound : DSFMLObject
return cast(bool)(sfSound_GetLoop(m_ptr));
}
/**
* Get the pitch
*
* Returns:
* Pitch value
*/
float getPitch()
{
return sfSound_GetPitch(m_ptr);
}
/**
* Get the volume
*
* Returns:
* Volume value (in range [1, 100])
*/
float getVolume()
{
return sfSound_GetVolume(m_ptr);
}
/**
* Get the sound position
*
* Params:
* x = X position of the sound in the world
* y = Y position of the sound in the world
* z = Z position of the sound in the world
*/
Vector3f getPosition()
{
Vector3f ret;
sfSound_GetPosition(m_ptr, &ret.x, &ret.y, &ret.z);
return ret;
}
/**
* Get the minimum distance
*
* Returns:
* Minimum distance for the sound
*/
float getMinDistance()
{
return sfSound_GetMinDistance(m_ptr);
}
/**
* Get the attenuation factor
*
* Returns:
* Attenuation factor of the sound
*
*/
float getAttenuation()
{
return sfSound_GetAttenuation(m_ptr);
}
/**
* Get the status of the sound (stopped, paused, playing)
*
* Returns:
* Current status of the sound
*/
SoundStatus getStatus()
{
return sfSound_GetStatus(m_ptr);
}
/**
* Get the current playing position of the sound
*
@ -331,31 +173,6 @@ class Sound : DSFMLObject
return sfSound_GetPlayingOffset(m_ptr);
}
/**
* Make the sound's position relative to the listener's position, or absolute.
* The default value is false (absolute)
*
* Params:
* relative = True to set the position relative, false to set it absolute
*/
void setRelativeToListener(bool relative)
{
sfSound_SetRelativeToListener(m_ptr, relative);
}
/**
* Tell if the sound's position is relative to the listener's
* position, or if it's absolute
*
* Returns:
* true if the position is relative, sfFalse if it's absolute
*/
bool isRelativeToListener()
{
return sfSound_IsRelativeToListener(m_ptr);
}
private:
SoundBuffer m_buffer;
@ -363,8 +180,6 @@ private:
extern (C)
{
typedef void* function() pf_sfSound_Create;
typedef void function(void*) pf_sfSound_Destroy;
typedef void function(void*) pf_sfSound_Play;
typedef void function(void*) pf_sfSound_Pause;
typedef void function(void*) pf_sfSound_Stop;
@ -372,25 +187,9 @@ private:
typedef void* function(void*) pf_sfSound_GetBuffer;
typedef void function(void*, int) pf_sfSound_SetLoop;
typedef int function(void*) pf_sfSound_GetLoop;
typedef SoundStatus function(void*) pf_sfSound_GetStatus;
typedef void function(void*, float) pf_sfSound_SetPitch;
typedef void function(void*, float) pf_sfSound_SetVolume;
typedef void function(void*, float, float, float) pf_sfSound_SetPosition;
typedef float function(void*) pf_sfSound_GetPitch;
typedef float function(void*) pf_sfSound_GetVolume;
typedef void function(void*, float*, float*, float*) pf_sfSound_GetPosition;
typedef float function(void*) pf_sfSound_GetPlayingOffset;
typedef float function(void*) pf_sfSound_GetMinDistance;
typedef float function(void*) pf_sfSound_GetAttenuation;
typedef void function(void*, float) pf_sfSound_SetMinDistance;
typedef void function(void*, float) pf_sfSound_SetAttenuation;
typedef void function(void*, float) pf_sfSound_SetPlayingOffset;
static void function(void*, bool) sfSound_SetRelativeToListener;
static bool function(void*) sfSound_IsRelativeToListener;
static pf_sfSound_Create sfSound_Create;
static pf_sfSound_Destroy sfSound_Destroy;
static pf_sfSound_Play sfSound_Play;
static pf_sfSound_Pause sfSound_Pause;
static pf_sfSound_Stop sfSound_Stop;
@ -398,18 +197,7 @@ private:
static pf_sfSound_GetBuffer sfSound_GetBuffer;
static pf_sfSound_SetLoop sfSound_SetLoop;
static pf_sfSound_GetLoop sfSound_GetLoop;
static pf_sfSound_GetStatus sfSound_GetStatus;
static pf_sfSound_SetPitch sfSound_SetPitch;
static pf_sfSound_SetVolume sfSound_SetVolume;
static pf_sfSound_SetPosition sfSound_SetPosition;
static pf_sfSound_GetPitch sfSound_GetPitch;
static pf_sfSound_GetVolume sfSound_GetVolume;
static pf_sfSound_GetPosition sfSound_GetPosition;
static pf_sfSound_GetPlayingOffset sfSound_GetPlayingOffset;
static pf_sfSound_GetMinDistance sfSound_GetMinDistance;
static pf_sfSound_GetAttenuation sfSound_GetAttenuation;
static pf_sfSound_SetMinDistance sfSound_SetMinDistance;
static pf_sfSound_SetAttenuation sfSound_SetAttenuation;
static pf_sfSound_SetPlayingOffset sfSound_SetPlayingOffset;
}
@ -420,8 +208,6 @@ private:
else
DllLoader dll = DllLoader.load("csfml-audio");
sfSound_Create = cast(pf_sfSound_Create)dll.getSymbol("sfSound_Create");
sfSound_Destroy = cast(pf_sfSound_Destroy)dll.getSymbol("sfSound_Destroy");
sfSound_Play = cast(pf_sfSound_Play)dll.getSymbol("sfSound_Play");
sfSound_Pause = cast(pf_sfSound_Pause)dll.getSymbol("sfSound_Pause");
sfSound_Stop = cast(pf_sfSound_Stop)dll.getSymbol("sfSound_Stop");
@ -429,22 +215,7 @@ private:
sfSound_GetBuffer = cast(pf_sfSound_GetBuffer)dll.getSymbol("sfSound_GetBuffer");
sfSound_SetLoop = cast(pf_sfSound_SetLoop)dll.getSymbol("sfSound_SetLoop");
sfSound_GetLoop = cast(pf_sfSound_GetLoop)dll.getSymbol("sfSound_GetLoop");
sfSound_GetStatus = cast(pf_sfSound_GetStatus)dll.getSymbol("sfSound_GetStatus");
sfSound_SetPitch = cast(pf_sfSound_SetPitch)dll.getSymbol("sfSound_SetPitch");
sfSound_SetVolume = cast(pf_sfSound_SetVolume)dll.getSymbol("sfSound_SetVolume");
sfSound_SetPosition = cast(pf_sfSound_SetPosition)dll.getSymbol("sfSound_SetPosition");
sfSound_GetPitch = cast(pf_sfSound_GetPitch)dll.getSymbol("sfSound_GetPitch");
sfSound_GetVolume = cast(pf_sfSound_GetVolume)dll.getSymbol("sfSound_GetVolume");
sfSound_GetPosition = cast(pf_sfSound_GetPosition)dll.getSymbol("sfSound_GetPosition");
sfSound_GetPlayingOffset = cast(pf_sfSound_GetPlayingOffset)dll.getSymbol("sfSound_GetPlayingOffset");
sfSound_GetMinDistance = cast(pf_sfSound_GetMinDistance)dll.getSymbol("sfSound_GetMinDistance");
sfSound_GetAttenuation = cast(pf_sfSound_GetAttenuation)dll.getSymbol("sfSound_GetAttenuation");
sfSound_SetMinDistance = cast(pf_sfSound_SetMinDistance)dll.getSymbol("sfSound_SetMinDistance");
sfSound_SetAttenuation = cast(pf_sfSound_SetAttenuation)dll.getSymbol("sfSound_SetAttenuation");
sfSound_SetPlayingOffset = cast(pf_sfSound_SetPlayingOffset)dll.getSymbol("sfSound_SetPlayingOffset");
mixin(loadFromSharedLib("sfSound_SetRelativeToListener"));
mixin(loadFromSharedLib("sfSound_IsRelativeToListener"));
}
}

View File

@ -0,0 +1,319 @@
/**
*
*/
module dsfml.audio.soundsource;
import dsfml.system.vector3;
import dsfml.system.common;
enum SoundStatus
{
Stopped, /// Sound is not playing
Paused, /// Sound is paused
Playing /// Sound is playing
}
/// base class
package class SoundSource(alias symbol) : DSFMLObject
{
private:
protected :
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// This constructor is meant ot be called by derived classes only.
///
////////////////////////////////////////////////////////////
this()
{
super(sfSoundSource_Create());
}
this(void* ptr)
{
super(ptr, true);
}
////////////////////////////////////////////////////////////
/// \brief Get the current status of the sound (stopped, paused, playing)
///
/// \return Current status of the sound
///
////////////////////////////////////////////////////////////
SoundStatus getStatus()
{
return sfSoundSource_GetStatus(m_ptr);
}
public:
////////////////////////////////////////////////////////////
/// \brief Set the pitch of the sound
///
/// The pitch represents the perceived fundamental frequency
/// of a sound; thus you can make a sound more acute or grave
/// by changing its pitch. A side effect of changing the pitch
/// is to modify the playing speed of the sound as well.
/// The default value for the pitch is 1.
///
/// \param pitch New pitch to apply to the sound
///
/// \see GetPitch
///
////////////////////////////////////////////////////////////
void setPitch(float pitch)
{
sfSoundSource_SetPitch(m_ptr, pitch);
}
////////////////////////////////////////////////////////////
/// \brief Set the volume of the sound
///
/// The volume is a value between 0 (mute) and 100 (full volume).
/// The default value for the volume is 100.
///
/// \param volume Volume of the sound
///
/// \see GetVolume
///
////////////////////////////////////////////////////////////
void setVolume(float volume)
in
{
assert(volume >= 0 && volume <= 100);
}
body
{
sfSoundSource_SetVolume(m_ptr, volume);
}
////////////////////////////////////////////////////////////
/// \brief Set the 3D position of the sound in the audio scene
///
/// Only sounds with one channel (mono sounds) can be
/// spatialized.
/// The default position of a sound is (0, 0, 0).
///
/// \param x X coordinate of the position of the sound in the scene
/// \param y Y coordinate of the position of the sound in the scene
/// \param z Z coordinate of the position of the sound in the scene
///
/// \see GetPosition
///
////////////////////////////////////////////////////////////
void setPosition(float x, float y, float z)
{
sfSoundSource_SetPosition(m_ptr, x, y, z);
}
////////////////////////////////////////////////////////////
/// \brief Set the 3D position of the sound in the audio scene
///
/// Only sounds with one channel (mono sounds) can be
/// spatialized.
/// The default position of a sound is (0, 0, 0).
///
/// \param position Position of the sound in the scene
///
/// \see GetPosition
///
////////////////////////////////////////////////////////////
void setPosition(Vector3f position)
{
sfSoundSource_SetPosition(m_ptr, position.x, position.y, position.z);
}
////////////////////////////////////////////////////////////
/// \brief Make the sound's position relative to the listener or absolute
///
/// Making a sound 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 sounds, sounds that are
/// produced by the listener, or sounds attached to it.
/// The default value is false (position is absolute).
///
/// \param relative True to set the position relative, false to set it absolute
///
/// \see IsRelativeToListener
///
////////////////////////////////////////////////////////////
void setRelativeToListener(bool relative)
{
sfSoundSource_SetRelativeToListener(m_ptr, relative);
}
////////////////////////////////////////////////////////////
/// \brief Set the minimum distance of the sound
///
/// The "minimum distance" of a sound 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.
///
/// \param distance New minimum distance of the sound
///
/// \see GetMinDistance, SetAttenuation
///
////////////////////////////////////////////////////////////
void setMinDistance(float distance)
{
sfSoundSource_SetMinDistance(m_ptr, distance);
}
////////////////////////////////////////////////////////////
/// \brief Set the attenuation factor of the sound
///
/// The attenuation is a multiplicative factor which makes
/// the sound more or less loud according to its distance
/// from the listener. An attenuation of 0 will produce a
/// non-attenuated sound, 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 sound fade out
/// very quickly as it gets further from the listener.
/// The default value of the attenuation is 1.
///
/// \param attenuation New attenuation factor of the sound
///
/// \see GetAttenuation, SetMinDistance
///
////////////////////////////////////////////////////////////
void setAttenuation(float attenuation)
{
sfSoundSource_SetAttenuation(m_ptr, attenuation);
}
////////////////////////////////////////////////////////////
/// \brief Get the pitch of the sound
///
/// \return Pitch of the sound
///
/// \see SetPitch
///
////////////////////////////////////////////////////////////
float GetPitch()
{
return sfSoundSource_GetPitch(m_ptr);
}
////////////////////////////////////////////////////////////
/// \brief Get the volume of the sound
///
/// \return Volume of the sound, in the range [0, 100]
///
/// \see SetVolume
///
////////////////////////////////////////////////////////////
float GetVolume()
{
return sfSoundSource_GetVolume(m_ptr);
}
////////////////////////////////////////////////////////////
/// \brief Get the 3D position of the sound in the audio scene
///
/// \return Position of the sound
///
/// \see SetPosition
///
////////////////////////////////////////////////////////////
Vector3f getPosition()
{
Vector3f ret;
sfSoundSource_GetPosition(m_ptr, &ret.x, &ret.y, &ret.z);
return ret;
}
////////////////////////////////////////////////////////////
/// \brief Tell whether the sound's position is relative to the
/// listener or is absolute
///
/// \return True if the position is relative, false if it's absolute
///
/// \see SetRelativeToListener
///
////////////////////////////////////////////////////////////
bool isRelativeToListener()
{
return sfSoundSource_IsRelativeToListener(m_ptr);
}
////////////////////////////////////////////////////////////
/// \brief Get the minimum distance of the sound
///
/// \return Minimum distance of the sound
///
/// \see SetMinDistance, GetAttenuation
///
////////////////////////////////////////////////////////////
float getMinDistance()
{
return sfSoundSource_GetMinDistance(m_ptr);
}
////////////////////////////////////////////////////////////
/// \brief Get the attenuation factor of the sound
///
/// \return Attenuation factor of the sound
///
/// \see SetAttenuation, GetMinDistance
///
////////////////////////////////////////////////////////////
float getAttenuation()
{
return sfSoundSource_GetAttenuation(m_ptr);
}
override void dispose()
{
sfSoundSource_Destroy(m_ptr);
}
private:
static extern(C)
{
void* function() sfSoundSource_Create;
void function(void*) sfSoundSource_Destroy;
SoundStatus function(void*) sfSoundSource_GetStatus;
void function(void*, float) sfSoundSource_SetPitch;
void function(void*, float) sfSoundSource_SetVolume;
void function(void*, float, float, float) sfSoundSource_SetPosition;
float function(void*) sfSoundSource_GetPitch;
float function(void*) sfSoundSource_GetVolume;
void function(void*, float*, float*, float*) sfSoundSource_GetPosition;
float function(void*) sfSoundSource_GetMinDistance;
float function(void*) sfSoundSource_GetAttenuation;
void function(void*, float) sfSoundSource_SetMinDistance;
void function(void*, float) sfSoundSource_SetAttenuation;
void function(void*, bool) sfSoundSource_SetRelativeToListener;
bool function(void*) sfSoundSource_IsRelativeToListener;
}
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-audio-d");
else
DllLoader dll = DllLoader.load("csfml-audio");
mixin(loadDerivedFromSharedLib("sfSoundSource", "Create", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "Destroy", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "GetStatus", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "GetPitch", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "SetPitch", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "GetVolume", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "SetVolume", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "GetPosition", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "SetPosition", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "GetMinDistance", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "SetMinDistance", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "GetAttenuation", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "SetAttenuation", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "SetRelativeToListener", symbol));
mixin(loadDerivedFromSharedLib("sfSoundSource", "IsRelativeToListener", symbol));
}
}

View File

@ -1,35 +0,0 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.audio.soundstatus;
/// Enumeration of the sound states
enum SoundStatus
{
STOPPED, /// Sound / music is not playing
PAUSED, /// Sound / music is paused
PLAYING /// Sound / music is playing
}

View File

@ -37,7 +37,7 @@ import dsfml.system.sleep;
import core.thread;
import dsfml.audio.sound;
import dsfml.audio.soundstatus;
import dsfml.audio.soundsource;
/**
* SoundStream is a streamed sound, ie samples are acquired
@ -69,7 +69,7 @@ import dsfml.audio.soundstatus;
* }
* ------------------------
*/
abstract class SoundStream : DSFMLObject
abstract class SoundStream : SoundSource!("sfSoundStream")
{
override void dispose()
{
@ -86,7 +86,7 @@ abstract class SoundStream : DSFMLObject
m_flag = true;
sfSoundStream_Play(m_ptr);
if (getStatus() != SoundStatus.PAUSED)
if (getStatus() != SoundStatus.Paused)
{
m_t = new Thread(&threadPoll);
m_t.start();
@ -135,159 +135,6 @@ abstract class SoundStream : DSFMLObject
return m_sampleRate;
}
/**
* Get the current status of the stream
*
* Returns:
* Current stream status
*/
SoundStatus getStatus()
{
return sfSoundStream_GetStatus(m_ptr);
}
/**
* Set the sound pitch.
* The default pitch is 1
*
* Params:
* pitch = New pitch
*/
void setPitch(float pitch)
{
sfSoundStream_SetPitch(m_ptr, pitch);
}
/**
* Set the sound volume.
* The default volume is 100
*
* Params:
* volume = Volume (in range [0, 100])
*/
void setVolume(float volume)
in
{
assert(volume >= 0.f && volume <= 100.f);
}
body
{
sfSoundStream_SetVolume(m_ptr, volume);
}
/*
* Set the sound position (take 3 values).
* The default position is (0, 0, 0)
*
* Params:
* x, y, z = Position of the sound in the world
*/
void setPosition(float x, float y, float z)
{
sfSoundStream_SetPosition(m_ptr, x, y, z);
}
/**
* Set the sound position (take 3 values).
* The default position is (0, 0, 0)
*
* Params:
* vec = Position of the sound in the world
*
*/
void setPosition(Vector3f vec)
{
sfSoundStream_SetPosition(m_ptr, vec.x, vec.y, vec.z);
}
/**
* 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:
* minDistance = New minimum distance for the sound
*/
void setMinDistance(float minDistance)
{
sfSoundStream_SetMinDistance(m_ptr, minDistance);
}
/**
* 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:
* attenuation = New attenuation factor for the sound
*
*/
void setAttenuation(float attenuation)
{
sfSoundStream_SetAttenuation(m_ptr, attenuation);
}
/**
* Get the pitch
*
* Returns:
* Pitch value
*/
float getPitch()
{
return sfSoundStream_GetPitch(m_ptr);
}
/**
* Get the volume
*
* Returns:
* Volume value (in range [1, 100])
*
*/
float getVolume()
{
return sfSoundStream_GetVolume(m_ptr);
}
/**
* Get the sound position
*
* Returns:
* Sound position
*/
Vector3f getPosition()
{
Vector3f vec;
sfSoundStream_GetPosition(m_ptr, &vec.x, &vec.y, &vec.z);
return vec;
}
/**
* Get the minimum distance
*
* Returns:
* Get the minimum distance of the sound
*/
float getMinDistance()
{
return sfSoundStream_GetMinDistance(m_ptr);
}
/**
* Get the attenuation
*
* Returns:
* Get the attenuation of the sound
*/
float getAttenuation()
{
return sfSoundStream_GetAttenuation(m_ptr);
}
/**
* Get the current playing offset of the stream
*
@ -326,29 +173,6 @@ abstract class SoundStream : DSFMLObject
sfSoundStream_SetLoop(m_ptr, loop);
}
/**
* Make the sound stream's position relative to the listener's position, or absolute.
* The default value is false (absolute)
*
* Params:
* relative = True to set the position relative, false to set it absolute
*/
void setRelativeToListener(bool relative)
{
sfSoundStream_SetRelativeToListener(m_ptr, relative);
}
/**
* Tell if the sound stream's position is relative to the listener's
* position, or if it's absolute
*
* Returns:
* true if the position is relative, sfFalse if it's absolute
*/
bool isRelativeToListener()
{
return sfSoundStream_IsRelativeToListener(m_ptr);
}
protected:
/**
@ -363,7 +187,8 @@ protected:
{
m_channelsCount = channelsCount;
m_sampleRate = sampleRate;
super(sfSoundStream_Create(&externalOnStart, &externalOnGetData, channelsCount, sampleRate, &m_id));
m_ptr = sfSoundStream_Create(&externalOnStart, &externalOnGetData, channelsCount, sampleRate, &m_id); // TODO: hack
m_mutex = new Mutex();
@ -502,30 +327,16 @@ private:
alias int function(void*) sfSoundStreamStartCallback;
alias int function (sfSoundStreamChunk*, void*) sfSoundStreamGetDataCallback;
typedef void* function(sfSoundStreamStartCallback, sfSoundStreamGetDataCallback, uint, uint, void*) pf_sfSoundStream_Create;
typedef void function(void*) pf_sfSoundStream_Destroy;
typedef void function(void*) pf_sfSoundStream_Play;
typedef void function(void*) pf_sfSoundStream_Pause;
typedef void function(void*) pf_sfSoundStream_Stop;
typedef SoundStatus function(void*) pf_sfSoundStream_GetStatus;
typedef uint function(void*) pf_sfSoundStream_GetChannelsCount;
typedef uint function(void*) pf_sfSoundStream_GetSampleRate;
typedef void function(void*, float) pf_sfSoundStream_SetPitch;
typedef void function(void*, float) pf_sfSoundStream_SetVolume;
typedef void function(void*, float, float, float) pf_sfSoundStream_SetPosition;
typedef void function(void*, float) pf_sfSoundStream_SetMinDistance;
typedef void function(void*, float) pf_sfSoundStream_SetAttenuation;
typedef float function(void*) pf_sfSoundStream_GetPitch;
typedef float function(void*) pf_sfSoundStream_GetVolume;
typedef void function(void*, float*, float*, float*) pf_sfSoundStream_GetPosition;
typedef float function(void*) pf_sfSoundStream_GetMinDistance;
typedef float function(void*) pf_sfSoundStream_GetAttenuation;
typedef float function(void*) pf_sfSoundStream_GetPlayingOffset;
typedef int function(void*) pf_sfSoundStream_GetLoop;
typedef void function(void*, int) pf_sfSoundStream_SetLoop;
typedef bool function(void*) pf_sfSoundStream_IsRelativeToListener;
typedef void function(void*, bool) pf_sfSoundStream_SetRelativeToListener;
alias void* function(sfSoundStreamStartCallback, sfSoundStreamGetDataCallback, uint, uint, void*) pf_sfSoundStream_Create;
alias void function(void*) pf_sfSoundStream_Destroy;
alias void function(void*) pf_sfSoundStream_Play;
alias void function(void*) pf_sfSoundStream_Pause;
alias void function(void*) pf_sfSoundStream_Stop;
alias uint function(void*) pf_sfSoundStream_GetChannelsCount;
alias uint function(void*) pf_sfSoundStream_GetSampleRate;
alias float function(void*) pf_sfSoundStream_GetPlayingOffset;
alias int function(void*) pf_sfSoundStream_GetLoop;
alias void function(void*, int) pf_sfSoundStream_SetLoop;
static pf_sfSoundStream_Create sfSoundStream_Create;
@ -533,26 +344,11 @@ private:
static pf_sfSoundStream_Play sfSoundStream_Play;
static pf_sfSoundStream_Pause sfSoundStream_Pause;
static pf_sfSoundStream_Stop sfSoundStream_Stop;
static pf_sfSoundStream_GetStatus sfSoundStream_GetStatus;
static pf_sfSoundStream_GetChannelsCount sfSoundStream_GetChannelsCount;
static pf_sfSoundStream_GetSampleRate sfSoundStream_GetSampleRate;
static pf_sfSoundStream_SetPitch sfSoundStream_SetPitch;
static pf_sfSoundStream_SetVolume sfSoundStream_SetVolume;
static pf_sfSoundStream_SetPosition sfSoundStream_SetPosition;
static pf_sfSoundStream_SetMinDistance sfSoundStream_SetMinDistance;
static pf_sfSoundStream_SetAttenuation sfSoundStream_SetAttenuation;
static pf_sfSoundStream_GetPitch sfSoundStream_GetPitch;
static pf_sfSoundStream_GetVolume sfSoundStream_GetVolume;
static pf_sfSoundStream_GetPosition sfSoundStream_GetPosition;
static pf_sfSoundStream_GetMinDistance sfSoundStream_GetMinDistance;
static pf_sfSoundStream_GetAttenuation sfSoundStream_GetAttenuation;
static pf_sfSoundStream_GetPlayingOffset sfSoundStream_GetPlayingOffset;
static pf_sfSoundStream_GetLoop sfSoundStream_GetLoop;
static pf_sfSoundStream_SetLoop sfSoundStream_SetLoop;
static pf_sfSoundStream_IsRelativeToListener sfSoundStream_IsRelativeToListener;
static pf_sfSoundStream_SetRelativeToListener sfSoundStream_SetRelativeToListener;
}
static this()
@ -567,24 +363,10 @@ private:
sfSoundStream_Play = cast(pf_sfSoundStream_Play)dll.getSymbol("sfSoundStream_Play");
sfSoundStream_Pause = cast(pf_sfSoundStream_Pause)dll.getSymbol("sfSoundStream_Pause");
sfSoundStream_Stop = cast(pf_sfSoundStream_Stop)dll.getSymbol("sfSoundStream_Stop");
sfSoundStream_GetStatus = cast(pf_sfSoundStream_GetStatus)dll.getSymbol("sfSoundStream_GetStatus");
sfSoundStream_GetChannelsCount = cast(pf_sfSoundStream_GetChannelsCount)dll.getSymbol("sfSoundStream_GetChannelsCount");
sfSoundStream_GetSampleRate = cast(pf_sfSoundStream_GetSampleRate)dll.getSymbol("sfSoundStream_GetSampleRate");
sfSoundStream_SetPitch = cast(pf_sfSoundStream_SetPitch)dll.getSymbol("sfSoundStream_SetPitch");
sfSoundStream_SetVolume = cast(pf_sfSoundStream_SetVolume)dll.getSymbol("sfSoundStream_SetVolume");
sfSoundStream_SetPosition = cast(pf_sfSoundStream_SetPosition)dll.getSymbol("sfSoundStream_SetPosition");
sfSoundStream_SetMinDistance = cast(pf_sfSoundStream_SetMinDistance)dll.getSymbol("sfSoundStream_SetMinDistance");
sfSoundStream_SetAttenuation = cast(pf_sfSoundStream_SetAttenuation)dll.getSymbol("sfSoundStream_SetAttenuation");
sfSoundStream_GetPitch = cast(pf_sfSoundStream_GetPitch)dll.getSymbol("sfSoundStream_GetPitch");
sfSoundStream_GetVolume = cast(pf_sfSoundStream_GetVolume)dll.getSymbol("sfSoundStream_GetVolume");
sfSoundStream_GetPosition = cast(pf_sfSoundStream_GetPosition)dll.getSymbol("sfSoundStream_GetPosition");
sfSoundStream_GetMinDistance = cast(pf_sfSoundStream_GetMinDistance)dll.getSymbol("sfSoundStream_GetMinDistance");
sfSoundStream_GetAttenuation = cast(pf_sfSoundStream_GetAttenuation)dll.getSymbol("sfSoundStream_GetAttenuation");
sfSoundStream_GetPlayingOffset = cast(pf_sfSoundStream_GetPlayingOffset)dll.getSymbol("sfSoundStream_GetPlayingOffset");
sfSoundStream_GetLoop = cast(pf_sfSoundStream_GetLoop)dll.getSymbol("sfSoundStream_GetLoop");
sfSoundStream_SetLoop = cast(pf_sfSoundStream_SetLoop)dll.getSymbol("sfSoundStream_SetLoop");
sfSoundStream_IsRelativeToListener = cast(pf_sfSoundStream_IsRelativeToListener) dll.getSymbol("sfSoundStream_IsRelativeToListener");
sfSoundStream_SetRelativeToListener = cast(pf_sfSoundStream_SetRelativeToListener) dll.getSymbol("sfSoundStream_SetRelativeToListener");
}
}