replaced all crappy spaces with proper tabs

kept this in its own changeset so it doesn't interfere with real changes

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1334 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
trass3r 2010-01-06 20:37:29 +00:00
parent 8431753ba3
commit 2f2fc5d4fa
56 changed files with 8094 additions and 8094 deletions

View file

@ -1,37 +1,37 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* 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.
* 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:
* 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.
* 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.
* 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.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.audio.all;
public import
dsfml.audio.listener,
dsfml.audio.music,
dsfml.audio.sound,
dsfml.audio.soundbuffer,
dsfml.audio.soundbufferrecorder,
dsfml.audio.soundrecorder,
dsfml.audio.soundstatus,
dsfml.audio.soundstream;
dsfml.audio.listener,
dsfml.audio.music,
dsfml.audio.sound,
dsfml.audio.soundbuffer,
dsfml.audio.soundbufferrecorder,
dsfml.audio.soundrecorder,
dsfml.audio.soundstatus,
dsfml.audio.soundstream;

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* 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.
* 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:
* 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.
* 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.
* 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.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.audio.listener;
@ -30,122 +30,122 @@ import dsfml.system.common;
import dsfml.system.vector3;
/**
* Listener is a global interface for defining the audio
* listener properties ; the audio listener is the point in
* the scene from where all the sounds are heard.
*
* See_Also:
* SFML Tutorial for sound spatialization example.
* Listener is a global interface for defining the audio
* listener properties ; the audio listener is the point in
* the scene from where all the sounds are heard.
*
* See_Also:
* SFML Tutorial for sound spatialization example.
*/
class Listener
{
/**
* Change the global volume of all the sounds.
* The default volume is 100
*
* Params:
* volume = New global volume, in the range [0, 100]
*/
static void setGlobalVolume(float volume)
in
{
assert (volume >= 0.f && volume <= 100.f);
}
body
/**
* Change the global volume of all the sounds.
* The default volume is 100
*
* Params:
* volume = New global volume, in the range [0, 100]
*/
static void setGlobalVolume(float volume)
in
{
assert (volume >= 0.f && volume <= 100.f);
}
body
{
sfListener_SetGlobalVolume(volume);
}
/**
* Get the current value of the global volume of all the sounds
*
* Returns:
* Current global volume, in the range [0, 100]
*/
static float getGlobalVolume()
/**
* Get the current value of the global volume of all the sounds
*
* Returns:
* Current global volume, in the range [0, 100]
*/
static float getGlobalVolume()
{
return sfListener_GetGlobalVolume();
}
/**
* Change the position of the listener.
* The default position is (0, 0, 0)
*
* Params:
* posX = X position of the listener in the world
* posY = Y position of the listener in the world
* posZ = Z position of the listener in the world
*/
static void setPosition(float posX, float posY, float posZ)
/**
* Change the position of the listener.
* The default position is (0, 0, 0)
*
* Params:
* posX = X position of the listener in the world
* posY = Y position of the listener in the world
* posZ = Z position of the listener in the world
*/
static void setPosition(float posX, float posY, float posZ)
{
sfListener_SetPosition(posX, posY, posZ);
}
/**
* Change the position of the listener.
* The default position is (0, 0, 0)
*
* Params:
* position = new position
*/
static void setPosition(Vector3f position)
/**
* Change the position of the listener.
* The default position is (0, 0, 0)
*
* Params:
* position = new position
*/
static void setPosition(Vector3f position)
{
sfListener_SetPosition(position.x, position.y, position.z);
}
/**
* Get the current position of the listener
*
* Returns:
* Current position
*/
static Vector3f getPosition()
/**
* Get the current position of the listener
*
* Returns:
* Current position
*/
static Vector3f getPosition()
{
Vector3f ret;
Vector3f ret;
sfListener_GetPosition(&ret.x, &ret.y, &ret.z);
return ret;
}
/**
* Change the orientation of the listener (the point
* he must look at).
* The default target is (0, 0, -1)
*
* Params:
* targetX = X position of the point the listener must look at
* targetY = X position of the point the listener must look at
* targetZ = X position of the point the listener must look at
*/
static void setTarget(float targetX, float targetY, float targetZ)
/**
* Change the orientation of the listener (the point
* he must look at).
* The default target is (0, 0, -1)
*
* Params:
* targetX = X position of the point the listener must look at
* targetY = X position of the point the listener must look at
* targetZ = X position of the point the listener must look at
*/
static void setTarget(float targetX, float targetY, float targetZ)
{
sfListener_SetTarget(targetX, targetY, targetZ);
}
/**
* Change the orientation of the listener (the point
* he must look at).
* The default target is (0, 0, -1)
*
* Params:
* target = Position of the point the listener must look at
*/
static void setTarget(Vector3f position)
/**
* Change the orientation of the listener (the point
* he must look at).
* The default target is (0, 0, -1)
*
* Params:
* target = Position of the point the listener must look at
*/
static void setTarget(Vector3f position)
{
sfListener_SetTarget(position.x, position.y, position.z);
}
/**
* Get the current orientation of the listener (the point
* he's looking at)
*
* Returns:
* Position of the point the listener is looking at
*/
static Vector3f getTarget()
/**
* Get the current orientation of the listener (the point
* he's looking at)
*
* Returns:
* Position of the point the listener is looking at
*/
static Vector3f getTarget()
{
Vector3f ret;
Vector3f ret;
sfListener_GetTarget(&ret.x, &ret.y, &ret.z);
return ret;
}
@ -154,35 +154,35 @@ private:
// External ====================================================================
extern (C)
{
typedef void function(float) pf_sfListener_SetGlobalVolume;
typedef float function() pf_sfListener_GetGlobalVolume;
typedef void function(float, float, float) pf_sfListener_SetPosition;
typedef void function(float*, float*, float*) pf_sfListener_GetPosition;
typedef void function(float, float, float) pf_sfListener_SetTarget;
typedef void function(float*, float*, float*) pf_sfListener_GetTarget;
static pf_sfListener_SetGlobalVolume sfListener_SetGlobalVolume;
static pf_sfListener_GetGlobalVolume sfListener_GetGlobalVolume;
static pf_sfListener_SetPosition sfListener_SetPosition;
static pf_sfListener_GetPosition sfListener_GetPosition;
static pf_sfListener_SetTarget sfListener_SetTarget;
static pf_sfListener_GetTarget sfListener_GetTarget;
}
extern (C)
{
typedef void function(float) pf_sfListener_SetGlobalVolume;
typedef float function() pf_sfListener_GetGlobalVolume;
typedef void function(float, float, float) pf_sfListener_SetPosition;
typedef void function(float*, float*, float*) pf_sfListener_GetPosition;
typedef void function(float, float, float) pf_sfListener_SetTarget;
typedef void function(float*, float*, float*) pf_sfListener_GetTarget;
static pf_sfListener_SetGlobalVolume sfListener_SetGlobalVolume;
static pf_sfListener_GetGlobalVolume sfListener_GetGlobalVolume;
static pf_sfListener_SetPosition sfListener_SetPosition;
static pf_sfListener_GetPosition sfListener_GetPosition;
static pf_sfListener_SetTarget sfListener_SetTarget;
static pf_sfListener_GetTarget sfListener_GetTarget;
}
static this()
{
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-audio-d");
else
DllLoader dll = DllLoader.load("csfml-audio");
sfListener_SetGlobalVolume = cast(pf_sfListener_SetGlobalVolume)dll.getSymbol("sfListener_SetGlobalVolume");
sfListener_GetGlobalVolume = cast(pf_sfListener_GetGlobalVolume)dll.getSymbol("sfListener_GetGlobalVolume");
sfListener_SetPosition = cast(pf_sfListener_SetPosition)dll.getSymbol("sfListener_SetPosition");
sfListener_GetPosition = cast(pf_sfListener_GetPosition)dll.getSymbol("sfListener_GetPosition");
sfListener_SetTarget = cast(pf_sfListener_SetTarget)dll.getSymbol("sfListener_SetTarget");
sfListener_GetTarget = cast(pf_sfListener_GetTarget)dll.getSymbol("sfListener_GetTarget");
}
sfListener_SetGlobalVolume = cast(pf_sfListener_SetGlobalVolume)dll.getSymbol("sfListener_SetGlobalVolume");
sfListener_GetGlobalVolume = cast(pf_sfListener_GetGlobalVolume)dll.getSymbol("sfListener_GetGlobalVolume");
sfListener_SetPosition = cast(pf_sfListener_SetPosition)dll.getSymbol("sfListener_SetPosition");
sfListener_GetPosition = cast(pf_sfListener_GetPosition)dll.getSymbol("sfListener_GetPosition");
sfListener_SetTarget = cast(pf_sfListener_SetTarget)dll.getSymbol("sfListener_SetTarget");
sfListener_GetTarget = cast(pf_sfListener_GetTarget)dll.getSymbol("sfListener_GetTarget");
}
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* 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.
* 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:
* 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.
* 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.
* 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.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.audio.music;
@ -39,278 +39,278 @@ import dsfml.system.vector3;
*/
class Music : DSFMLObject
{
/**
* Open a music file (doesn't play it -- call Play for that)
*
* Params:
* filename = Path of the file to open
*
*/
this(string filename)
{
/**
* Open a music file (doesn't play it -- call Play for that)
*
* Params:
* filename = Path of the file to open
*
*/
this(string filename)
{
if (filename is null || filename.length == 0)
throw new LoadingException("LoadingException : Filename is invalid.");
throw new LoadingException("LoadingException : Filename is invalid.");
super(sfMusic_CreateFromFile(toStringz(filename)));
}
}
/**
* Open a music file from memory (doesn't play it -- call Play() for that)
*
* Params:
* data = file data in memory
*
*/
this(byte[] data)
{
/**
* Open a music file from memory (doesn't play it -- call Play() for that)
*
* Params:
* data = file data in memory
*
*/
this(byte[] data)
{
if (data is null || data.length == 0)
throw new Exception("LoadingException : Memory stream is invalid.");
throw new Exception("LoadingException : Memory stream is invalid.");
super(m_ptr = sfMusic_CreateFromMemory(data.ptr, data.length));
}
}
override void dispose()
{
override void dispose()
{
sfMusic_Destroy(m_ptr);
}
}
/**
* Start playing the audio stream
*/
void play()
{
/**
* Start playing the audio stream
*/
void play()
{
sfMusic_Play(m_ptr);
}
}
/**
* Stop playing the audio stream
*/
void stop()
{
/**
* Stop playing the audio stream
*/
void stop()
{
sfMusic_Stop(m_ptr);
}
}
/**
* Pause the audio stream
*/
void pause()
{
/**
* Pause the audio stream
*/
void pause()
{
sfMusic_Pause(m_ptr);
}
}
/**
* Return the number of channels (1 = mono, 2 = stereo)
*
* Returns:
* Number of channels
*/
uint getChannelsCount()
{
/**
* Return the number of channels (1 = mono, 2 = stereo)
*
* Returns:
* Number of channels
*/
uint getChannelsCount()
{
return sfMusic_GetChannelsCount(m_ptr);
}
}
/**
* Get the stream sample rate
*
* Returns:
* Stream frequency (number of samples per second)
*/
uint getSampleRate()
{
/**
* Get the stream sample rate
*
* Returns:
* Stream frequency (number of samples per second)
*/
uint getSampleRate()
{
return sfMusic_GetSampleRate(m_ptr);
}
}
/**
* Get the music duration
*
* Returns:
* Music duration, in seconds
*/
float getDuration()
{
/**
* Get the music duration
*
* Returns:
* Music duration, in seconds
*/
float getDuration()
{
return sfMusic_GetDuration(m_ptr);
}
}
/**
* Get the status of the stream (stopped, paused, playing)
*
* Returns:
* Current status of the sound
*/
SoundStatus getStatus()
{
/**
* 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
*
* Returns:
* True if the music is looping, false otherwise
*/
bool getLoop()
{
/**
* Tell whether or not the music is looping
*
* Returns:
* True if the music is looping, false otherwise
*/
bool getLoop()
{
return cast(bool)sfMusic_GetLoop(m_ptr);
}
}
/**
* Get the pitch
*
* Returns:
* Pitch value
*/
float getPitch()
{
/**
* 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()
{
/**
* 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()
{
/**
* 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()
{
/**
* 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()
{
/**
* 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
*
* Params:
* loop = True to play in loop, false to play once
*/
void setLoop(bool loop)
{
/**
* Set the music loop state.
* This parameter is disabled by default
*
* Params:
* loop = True to play in loop, false to play once
*/
void setLoop(bool loop)
{
sfMusic_SetLoop(m_ptr, loop);
}
}
/**
* Set the sound pitch.
* The default pitch is 1
*
* Params:
* pitch = New pitch
*
*/
void setPitch(float pitch)
{
/**
* 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
{
/**
* 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
{
}
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)
{
/**
* 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)
{
/**
* 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)
{
/**
* 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)
{
/**
* 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.

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* 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.
* 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:
* 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.
* 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.
* 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.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.audio.sound;
@ -34,39 +34,39 @@ import dsfml.system.exception;
import dsfml.system.vector3;
/**
* Sound defines the properties of the sound such as position,
* volume, pitch, etc.
* Sound defines the properties of the sound such as position,
* volume, pitch, etc.
*/
class Sound : DSFMLObject
{
/**
* Default constructor
*/
this()
/**
* Default constructor
*/
this()
{
super(sfSound_Create());
}
/**
* Construct the sound from its parameters
*
* Params:
* buffer = Sound buffer to play
* loop = Loop flag (false by default)
* pitch = Value of the pitch (1 by default)
* volume = Volume (100 by default)
* x = X position (0 by default)
* y = Y position (0 by default)
* z = Z position (0 by default)
*
* Throws:
* NullParameterException if buffer is null
*/
this(SoundBuffer buffer, bool loop = false, float pitch = 1.f, float volume = 100.f, float x = 0.f, float y = 0.f, float z = 0.f)
/**
* Construct the sound from its parameters
*
* Params:
* buffer = Sound buffer to play
* loop = Loop flag (false by default)
* pitch = Value of the pitch (1 by default)
* volume = Volume (100 by default)
* x = X position (0 by default)
* y = Y position (0 by default)
* z = Z position (0 by default)
*
* Throws:
* NullParameterException if buffer is null
*/
this(SoundBuffer buffer, bool loop = false, float pitch = 1.f, float volume = 100.f, float x = 0.f, float y = 0.f, float z = 0.f)
{
if (buffer is null)
throw new NullParameterException("NullParameterException : SoundBuffer is null.");
if (buffer is null)
throw new NullParameterException("NullParameterException : SoundBuffer is null.");
super(sfSound_Create());
sfSound_SetBuffer(m_ptr, buffer.getNativePointer());
sfSound_SetLoop(m_ptr, loop);
@ -76,257 +76,257 @@ class Sound : DSFMLObject
}
override void dispose()
override void dispose()
{
sfSound_Destroy(m_ptr);
}
/**
* Play the sound
*/
void play()
/**
* Play the sound
*/
void play()
{
sfSound_Play(m_ptr);
}
/**
* Pause the sound
*/
void pause()
/**
* Pause the sound
*/
void pause()
{
sfSound_Pause(m_ptr);
}
/**
* Stop the sound
*/
void stop()
/**
* Stop the sound
*/
void stop()
{
sfSound_Stop(m_ptr);
}
/**
* Set the source buffer
*
* Params:
* buffer = New sound buffer to bind to the sound
*/
void setBuffer(SoundBuffer buffer)
/**
* Set the source buffer
*
* Params:
* buffer = New sound buffer to bind to the sound
*/
void setBuffer(SoundBuffer buffer)
{
if (buffer is null)
throw new NullParameterException("NullParameterException : SoundBuffer is null.");
if (buffer is null)
throw new NullParameterException("NullParameterException : SoundBuffer is null.");
m_buffer = buffer;
sfSound_SetBuffer(m_ptr, buffer.getNativePointer);
}
/**
* Set the sound loop state.
* This parameter is disabled by default
*
* Params:
* loop = True to play in loop, false to play once
*/
void setLoop(bool loop)
/**
* Set the sound loop state.
* This parameter is disabled by default
*
* Params:
* loop = True to play in loop, false to play once
*/
void setLoop(bool loop)
{
sfSound_SetLoop(m_ptr, loop);
}
/**
* Set the sound pitch.
* The default pitch is 1
*
* Params:
* pitch = New pitch
*/
void setPitch(float pitch)
/**
* 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
/**
* 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)
/**
* 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 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 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 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
*
* Params:
* offset = new playing position, expressed in seconds
*/
void setPlayingOffset(float offset)
{
sfSound_SetPlayingOffset(m_ptr, offset);
}
/**
* Set the current playing offset of a sound
*
* Params:
* offset = new playing position, expressed in seconds
*/
void setPlayingOffset(float offset)
{
sfSound_SetPlayingOffset(m_ptr, offset);
}
/**
* Get the source buffer
*
* Returns:
* Sound buffer bound to the sound (can be NULL)
*/
SoundBuffer getBuffer()
/**
* Get the source buffer
*
* Returns:
* Sound buffer bound to the sound (can be NULL)
*/
SoundBuffer getBuffer()
{
return m_buffer;
}
/**
* Tell whether or not the sound is looping
*
* Returns:
* True if the sound is looping, false otherwise
*/
bool getLoop()
/**
* Tell whether or not the sound is looping
*
* Returns:
* True if the sound is looping, false otherwise
*/
bool getLoop()
{
return cast(bool)(sfSound_GetLoop(m_ptr));
}
/**
* Get the pitch
*
* Returns:
* Pitch value
*/
float getPitch()
/**
* 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()
/**
* 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()
/**
* 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;
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 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 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()
/**
* 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
*
* Returns:
* Current playing position, expressed in seconds
*/
float getPlayingOffset()
/**
* Get the current playing position of the sound
*
* Returns:
* Current playing position, expressed in seconds
*/
float getPlayingOffset()
{
return sfSound_GetPlayingOffset(m_ptr);
}
@ -361,90 +361,90 @@ private:
// External ====================================================================
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;
typedef void function(void*, void*) pf_sfSound_SetBuffer;
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;
static pf_sfSound_SetBuffer sfSound_SetBuffer;
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;
}
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;
typedef void function(void*, void*) pf_sfSound_SetBuffer;
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;
static pf_sfSound_SetBuffer sfSound_SetBuffer;
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;
}
static this()
{
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-audio-d");
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");
sfSound_SetBuffer = cast(pf_sfSound_SetBuffer)dll.getSymbol("sfSound_SetBuffer");
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"));
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");
sfSound_SetBuffer = cast(pf_sfSound_SetBuffer)dll.getSymbol("sfSound_SetBuffer");
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

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* 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.
* 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:
* 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.
* 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.
* 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.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.audio.soundbuffer;
@ -32,83 +32,83 @@ import dsfml.system.stringutil;
/**
* SoundBuffer is the low-level for loading and manipulating
* sound buffers
* SoundBuffer is the low-level for loading and manipulating
* sound buffers
*/
class SoundBuffer : DSFMLObject
{
/**
* Load the sound buffer from a file
*
* Params:
* filename = Path of the sound file to load
*
* Throws:
* LoadingException on failure
*/
this(string filename)
/**
* Load the sound buffer from a file
*
* Params:
* filename = Path of the sound file to load
*
* Throws:
* LoadingException on failure
*/
this(string filename)
{
if (filename is null || filename.length == 0)
throw new LoadingException("LoadingException : Filename is invalid.");
super(sfSoundBuffer_CreateFromFile(toStringz(filename)));
if (filename is null || filename.length == 0)
throw new LoadingException("LoadingException : Filename is invalid.");
super(sfSoundBuffer_CreateFromFile(toStringz(filename)));
}
/**
* Load the sound buffer from a file in memory
*
* Params:
* data = Array of file data in memory
*
* Throws:
* LoadingException on failure
*/
this(byte[] data)
/**
* Load the sound buffer from a file in memory
*
* Params:
* data = Array of file data in memory
*
* Throws:
* LoadingException on failure
*/
this(byte[] data)
{
if (data is null || data.length == 0)
throw new Exception("LoadingException : Memory stream is invalid.");
if (data is null || data.length == 0)
throw new Exception("LoadingException : Memory stream is invalid.");
super(sfSoundBuffer_CreateFromMemory(data.ptr, data.length));
}
/**
* Load the sound buffer from an array of samples - assumed format for
* samples is 16 bits signed integer
*
* Params:
* samples = Array of samples in memory
* channelsCount = Number of channels (1 = mono, 2 = stereo, ...)
* sampleRate = Frequency (number of samples to play per second)
*
* Throws:
* LoadingException on failure
*/
this(short[] samples, uint channelsCount, uint sampleRate)
/**
* Load the sound buffer from an array of samples - assumed format for
* samples is 16 bits signed integer
*
* Params:
* samples = Array of samples in memory
* channelsCount = Number of channels (1 = mono, 2 = stereo, ...)
* sampleRate = Frequency (number of samples to play per second)
*
* Throws:
* LoadingException on failure
*/
this(short[] samples, uint channelsCount, uint sampleRate)
{
if (samples is null || samples.length == 0)
throw new Exception("LoadingException : Samples array is invalid.");
if (samples is null || samples.length == 0)
throw new Exception("LoadingException : Samples array is invalid.");
super(sfSoundBuffer_CreateFromSamples(samples.ptr, samples.length, channelsCount, sampleRate));
}
override void dispose()
override void dispose()
{
sfSoundBuffer_Destroy(m_ptr);
}
/**
* Save the sound buffer to a file
*
* Params:
* filename = Path of the sound file to write
*
* Returns:
* True if saving has been successful
*/
bool saveToFile(string filename)
{
/**
* Save the sound buffer to a file
*
* Params:
* filename = Path of the sound file to write
*
* Returns:
* True if saving has been successful
*/
bool saveToFile(string filename)
{
if (filename !is null && filename.length > 0 )
{
return cast(bool)sfSoundBuffer_SaveToFile(m_ptr, toStringz(filename));
@ -116,115 +116,115 @@ class SoundBuffer : DSFMLObject
return false;
}
/**
* Return the sound samples
*
* Returns:
* Array of sound samples, in 16 bits signed integer format
*/
short[] getSamples()
/**
* Return the sound samples
*
* Returns:
* Array of sound samples, in 16 bits signed integer format
*/
short[] getSamples()
{
short* temp = null;
temp = sfSoundBuffer_GetSamples(m_ptr);
short* temp = null;
temp = sfSoundBuffer_GetSamples(m_ptr);
return temp is null ? null : temp[0..getSamplesCount];
}
/**
* Return the samples count
*
* Returns:
* Number of samples
*/
size_t getSamplesCount()
/**
* Return the samples count
*
* Returns:
* Number of samples
*/
size_t getSamplesCount()
{
return sfSoundBuffer_GetSamplesCount(m_ptr);
}
/**
* Get the sample rate
*
* Returns:
* Sound frequency (number of samples per second)
*/
uint getSampleRate()
/**
* Get the sample rate
*
* Returns:
* Sound frequency (number of samples per second)
*/
uint getSampleRate()
{
return sfSoundBuffer_GetSampleRate(m_ptr);
}
/**
* Return the number of channels (1 = mono, 2 = stereo, ...)
*
* Returns:
* Number of channels
*/
uint getChannelsCount()
/**
* Return the number of channels (1 = mono, 2 = stereo, ...)
*
* Returns:
* Number of channels
*/
uint getChannelsCount()
{
return sfSoundBuffer_GetChannelsCount(m_ptr);
}
/**
* Get the sound duration
*
* Returns:
* Sound duration, in seconds
*/
float getDuration()
/**
* Get the sound duration
*
* Returns:
* Sound duration, in seconds
*/
float getDuration()
{
return sfSoundBuffer_GetDuration(m_ptr);
}
package:
this(void* ptr)
{
super(ptr, true);
}
package:
this(void* ptr)
{
super(ptr, true);
}
private:
// External ====================================================================
extern (C)
{
typedef void* function(cchar*) pf_sfSoundBuffer_CreateFromFile;
typedef void* function(byte*, size_t) pf_sfSoundBuffer_CreateFromMemory;
typedef void* function(short*, size_t, uint, uint) pf_sfSoundBuffer_CreateFromSamples;
typedef void function(void*) pf_sfSoundBuffer_Destroy;
typedef int function(void*, cchar*) pf_sfSoundBuffer_SaveToFile;
typedef short* function(void*) pf_sfSoundBuffer_GetSamples;
typedef size_t function(void*) pf_sfSoundBuffer_GetSamplesCount;
typedef uint function(void*) pf_sfSoundBuffer_GetSampleRate;
typedef uint function(void*) pf_sfSoundBuffer_GetChannelsCount;
typedef float function(void*) pf_sfSoundBuffer_GetDuration;
static pf_sfSoundBuffer_CreateFromFile sfSoundBuffer_CreateFromFile;
static pf_sfSoundBuffer_CreateFromMemory sfSoundBuffer_CreateFromMemory;
static pf_sfSoundBuffer_CreateFromSamples sfSoundBuffer_CreateFromSamples;
static pf_sfSoundBuffer_Destroy sfSoundBuffer_Destroy;
static pf_sfSoundBuffer_SaveToFile sfSoundBuffer_SaveToFile;
static pf_sfSoundBuffer_GetSamples sfSoundBuffer_GetSamples;
static pf_sfSoundBuffer_GetSamplesCount sfSoundBuffer_GetSamplesCount;
static pf_sfSoundBuffer_GetSampleRate sfSoundBuffer_GetSampleRate;
static pf_sfSoundBuffer_GetChannelsCount sfSoundBuffer_GetChannelsCount;
static pf_sfSoundBuffer_GetDuration sfSoundBuffer_GetDuration;
}
extern (C)
{
typedef void* function(cchar*) pf_sfSoundBuffer_CreateFromFile;
typedef void* function(byte*, size_t) pf_sfSoundBuffer_CreateFromMemory;
typedef void* function(short*, size_t, uint, uint) pf_sfSoundBuffer_CreateFromSamples;
typedef void function(void*) pf_sfSoundBuffer_Destroy;
typedef int function(void*, cchar*) pf_sfSoundBuffer_SaveToFile;
typedef short* function(void*) pf_sfSoundBuffer_GetSamples;
typedef size_t function(void*) pf_sfSoundBuffer_GetSamplesCount;
typedef uint function(void*) pf_sfSoundBuffer_GetSampleRate;
typedef uint function(void*) pf_sfSoundBuffer_GetChannelsCount;
typedef float function(void*) pf_sfSoundBuffer_GetDuration;
static pf_sfSoundBuffer_CreateFromFile sfSoundBuffer_CreateFromFile;
static pf_sfSoundBuffer_CreateFromMemory sfSoundBuffer_CreateFromMemory;
static pf_sfSoundBuffer_CreateFromSamples sfSoundBuffer_CreateFromSamples;
static pf_sfSoundBuffer_Destroy sfSoundBuffer_Destroy;
static pf_sfSoundBuffer_SaveToFile sfSoundBuffer_SaveToFile;
static pf_sfSoundBuffer_GetSamples sfSoundBuffer_GetSamples;
static pf_sfSoundBuffer_GetSamplesCount sfSoundBuffer_GetSamplesCount;
static pf_sfSoundBuffer_GetSampleRate sfSoundBuffer_GetSampleRate;
static pf_sfSoundBuffer_GetChannelsCount sfSoundBuffer_GetChannelsCount;
static pf_sfSoundBuffer_GetDuration sfSoundBuffer_GetDuration;
}
static this()
{
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-audio-d");
else
DllLoader dll = DllLoader.load("csfml-audio");
sfSoundBuffer_CreateFromFile = cast(pf_sfSoundBuffer_CreateFromFile)dll.getSymbol("sfSoundBuffer_CreateFromFile");
sfSoundBuffer_CreateFromMemory = cast(pf_sfSoundBuffer_CreateFromMemory)dll.getSymbol("sfSoundBuffer_CreateFromMemory");
sfSoundBuffer_CreateFromSamples = cast(pf_sfSoundBuffer_CreateFromSamples)dll.getSymbol("sfSoundBuffer_CreateFromSamples");
sfSoundBuffer_Destroy = cast(pf_sfSoundBuffer_Destroy)dll.getSymbol("sfSoundBuffer_Destroy");
sfSoundBuffer_SaveToFile = cast(pf_sfSoundBuffer_SaveToFile)dll.getSymbol("sfSoundBuffer_SaveToFile");
sfSoundBuffer_GetSamples = cast(pf_sfSoundBuffer_GetSamples)dll.getSymbol("sfSoundBuffer_GetSamples");
sfSoundBuffer_GetSamplesCount = cast(pf_sfSoundBuffer_GetSamplesCount)dll.getSymbol("sfSoundBuffer_GetSamplesCount");
sfSoundBuffer_GetSampleRate = cast(pf_sfSoundBuffer_GetSampleRate)dll.getSymbol("sfSoundBuffer_GetSampleRate");
sfSoundBuffer_GetChannelsCount = cast(pf_sfSoundBuffer_GetChannelsCount)dll.getSymbol("sfSoundBuffer_GetChannelsCount");
sfSoundBuffer_GetDuration = cast(pf_sfSoundBuffer_GetDuration)dll.getSymbol("sfSoundBuffer_GetDuration");
}
sfSoundBuffer_CreateFromFile = cast(pf_sfSoundBuffer_CreateFromFile)dll.getSymbol("sfSoundBuffer_CreateFromFile");
sfSoundBuffer_CreateFromMemory = cast(pf_sfSoundBuffer_CreateFromMemory)dll.getSymbol("sfSoundBuffer_CreateFromMemory");
sfSoundBuffer_CreateFromSamples = cast(pf_sfSoundBuffer_CreateFromSamples)dll.getSymbol("sfSoundBuffer_CreateFromSamples");
sfSoundBuffer_Destroy = cast(pf_sfSoundBuffer_Destroy)dll.getSymbol("sfSoundBuffer_Destroy");
sfSoundBuffer_SaveToFile = cast(pf_sfSoundBuffer_SaveToFile)dll.getSymbol("sfSoundBuffer_SaveToFile");
sfSoundBuffer_GetSamples = cast(pf_sfSoundBuffer_GetSamples)dll.getSymbol("sfSoundBuffer_GetSamples");
sfSoundBuffer_GetSamplesCount = cast(pf_sfSoundBuffer_GetSamplesCount)dll.getSymbol("sfSoundBuffer_GetSamplesCount");
sfSoundBuffer_GetSampleRate = cast(pf_sfSoundBuffer_GetSampleRate)dll.getSymbol("sfSoundBuffer_GetSampleRate");
sfSoundBuffer_GetChannelsCount = cast(pf_sfSoundBuffer_GetChannelsCount)dll.getSymbol("sfSoundBuffer_GetChannelsCount");
sfSoundBuffer_GetDuration = cast(pf_sfSoundBuffer_GetDuration)dll.getSymbol("sfSoundBuffer_GetDuration");
}
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* 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.
* 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:
* 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.
* 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.
* 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.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.audio.soundbufferrecorder;
@ -32,78 +32,78 @@ import dsfml.audio.soundbuffer;
import dsfml.audio.soundrecorder;
/**
* Specialized sfSoundRecorder which saves the captured
* audio data into a sound buffer
* Specialized sfSoundRecorder which saves the captured
* audio data into a sound buffer
*/
class SoundBufferRecorder : SoundRecorder
{
/**
* Constructor
*/
this()
{
super(sfSoundBufferRecorder_Create());
}
override void dispose()
{
sfSoundBufferRecorder_Destroy(m_ptr);
}
/**
* Constructor
*/
this()
{
super(sfSoundBufferRecorder_Create());
}
override void dispose()
{
sfSoundBufferRecorder_Destroy(m_ptr);
}
/**
* Get the sound buffer containing the captured audio data
*
* Returns:
* SoundBuffer containing the captured audio data
*
*/
SoundBuffer getBuffer()
{
return new SoundBuffer(sfSoundBufferRecorder_GetBuffer(m_ptr));
}
/**
* Get the sound buffer containing the captured audio data
*
* Returns:
* SoundBuffer containing the captured audio data
*
*/
SoundBuffer getBuffer()
{
return new SoundBuffer(sfSoundBufferRecorder_GetBuffer(m_ptr));
}
protected:
override bool onStart()
{
return true;
}
override bool onStart()
{
return true;
}
override bool onProcessSamples(short[] s)
{
return true;
}
override void onStop()
{
}
override bool onProcessSamples(short[] s)
{
return true;
}
override void onStop()
{
}
private:
// External ====================================================================
extern (C)
{
typedef void* function() pf_sfSoundBufferRecorder_Create;
typedef void function(void*) pf_sfSoundBufferRecorder_Destroy;
typedef void* function(void*) pf_sfSoundBufferRecorder_GetBuffer;
static pf_sfSoundBufferRecorder_Create sfSoundBufferRecorder_Create;
static pf_sfSoundBufferRecorder_Destroy sfSoundBufferRecorder_Destroy;
static pf_sfSoundBufferRecorder_GetBuffer sfSoundBufferRecorder_GetBuffer;
}
extern (C)
{
typedef void* function() pf_sfSoundBufferRecorder_Create;
typedef void function(void*) pf_sfSoundBufferRecorder_Destroy;
typedef void* function(void*) pf_sfSoundBufferRecorder_GetBuffer;
static pf_sfSoundBufferRecorder_Create sfSoundBufferRecorder_Create;
static pf_sfSoundBufferRecorder_Destroy sfSoundBufferRecorder_Destroy;
static pf_sfSoundBufferRecorder_GetBuffer sfSoundBufferRecorder_GetBuffer;
}
static this()
{
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-audio-d");
else
DllLoader dll = DllLoader.load("csfml-audio");
sfSoundBufferRecorder_Create = cast(pf_sfSoundBufferRecorder_Create)dll.getSymbol("sfSoundBufferRecorder_Create");
sfSoundBufferRecorder_Destroy = cast(pf_sfSoundBufferRecorder_Destroy)dll.getSymbol("sfSoundBufferRecorder_Destroy");
sfSoundBufferRecorder_GetBuffer = cast(pf_sfSoundBufferRecorder_GetBuffer)dll.getSymbol("sfSoundBufferRecorder_GetBuffer");
}
sfSoundBufferRecorder_Create = cast(pf_sfSoundBufferRecorder_Create)dll.getSymbol("sfSoundBufferRecorder_Create");
sfSoundBufferRecorder_Destroy = cast(pf_sfSoundBufferRecorder_Destroy)dll.getSymbol("sfSoundBufferRecorder_Destroy");
sfSoundBufferRecorder_GetBuffer = cast(pf_sfSoundBufferRecorder_GetBuffer)dll.getSymbol("sfSoundBufferRecorder_GetBuffer");
}
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* 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.
* 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:
* 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.
* 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.
* 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.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.audio.soundrecorder;
@ -38,300 +38,300 @@ import dsfml.system.lock;
import core.thread;
/**
* SoundRecorder is an interface for capturing sound data.
*
* $(B onProcessSamples and onStop will be called by a different thread, take care of synchronization issues.)
*
* Examples:
* -------
* class MySoundRecorder : SoundRecorder
* {
* this()
* {
*
* }
*
* protected bool onStart()
* {
* return true;
* }
*
* protected void onStop()
* {
*
* }
*
* protected bool onProcessSamples(out short[])
* {
* // Process data here
*
* return true; //return true to continue capture, else return false
* }
* }
* -------
* SoundRecorder is an interface for capturing sound data.
*
* $(B onProcessSamples and onStop will be called by a different thread, take care of synchronization issues.)
*
* Examples:
* -------
* class MySoundRecorder : SoundRecorder
* {
* this()
* {
*
* }
*
* protected bool onStart()
* {
* return true;
* }
*
* protected void onStop()
* {
*
* }
*
* protected bool onProcessSamples(out short[])
* {
* // Process data here
*
* return true; //return true to continue capture, else return false
* }
* }
* -------
*/
abstract class SoundRecorder : DSFMLObject
{
override void dispose()
{
if (m_flag)
stop();
override void dispose()
{
if (m_flag)
stop();
m_instances.remove(m_id);
sfSoundRecorder_Destroy(m_ptr);
}
m_instances.remove(m_id);
sfSoundRecorder_Destroy(m_ptr);
}
/**
* Start the capture.
*
* Only one capture can happen at the same time
*
* Params:
* sampleRate : Sound frequency (the more samples, the higher the quality)
* (44100 by default = CD quality)
*/
void start(uint sampleRate = 44100)
{
sfSoundRecorder_Start(m_ptr, sampleRate);
m_t = new Thread(&threadPoll);
m_t.start();
}
/**
* Start the capture.
*
* Only one capture can happen at the same time
*
* Params:
* sampleRate : Sound frequency (the more samples, the higher the quality)
* (44100 by default = CD quality)
*/
void start(uint sampleRate = 44100)
{
sfSoundRecorder_Start(m_ptr, sampleRate);
m_t = new Thread(&threadPoll);
m_t.start();
}
/**
* Stop the capture
*/
void stop()
{
sfSoundRecorder_Stop(m_ptr);
m_flag = false;
m_t.join();
m_t = null;
}
/**
* Stop the capture
*/
void stop()
{
sfSoundRecorder_Stop(m_ptr);
m_flag = false;
m_t.join();
m_t = null;
}
/**
* Get the sample rate
*
* Returns:
* Frequency, in samples per second
*/
uint getSampleRate()
{
return sfSoundRecorder_GetSampleRate(m_ptr);
}
/**
* Get the sample rate
*
* Returns:
* Frequency, in samples per second
*/
uint getSampleRate()
{
return sfSoundRecorder_GetSampleRate(m_ptr);
}
/**
* Tell if the system supports sound capture.
* If not, this class won't be usable
*
* Returns:
* True if audio capture is supported
*
*/
static bool canCapture()
{
return cast(bool)sfSoundRecorder_CanCapture();
}
/**
* Tell if the system supports sound capture.
* If not, this class won't be usable
*
* Returns:
* True if audio capture is supported
*
*/
static bool canCapture()
{
return cast(bool)sfSoundRecorder_CanCapture();
}
protected:
/**
* Protected constructor
*/
this()
{
m_id = ++seed;
m_instances[m_id] = this;
super(sfSoundRecorder_Create(&internalOnStart, &internalCallback, &internalOnStop, &m_id));
init(true);
}
/**
* Protected constructor
*/
this()
{
m_id = ++seed;
m_instances[m_id] = this;
super(sfSoundRecorder_Create(&internalOnStart, &internalCallback, &internalOnStop, &m_id));
init(true);
}
this(void* ptr)
{
super(ptr);
this(void* ptr)
{
super(ptr);
init(false);
}
init(false);
}
/**
* Start recording audio data
*
* Returns:
* False to abort recording audio data, true to start
*/
abstract bool onStart();
/**
* Stop recording audio data
*/
abstract void onStop();
/**
* callback function
*
* Parameters:
* samples = Array of samples
*
* Returns:
* true to continue recording, false to stop.
*/
abstract bool onProcessSamples(short[] samples);
/**
* Start recording audio data
*
* Returns:
* False to abort recording audio data, true to start
*/
abstract bool onStart();
/**
* Stop recording audio data
*/
abstract void onStop();
/**
* callback function
*
* Parameters:
* samples = Array of samples
*
* Returns:
* true to continue recording, false to stop.
*/
abstract bool onProcessSamples(short[] samples);
bool m_disposed;
bool m_disposed;
private:
/*
* an init function to initialize id of the object.
*/
void init(bool flag)
{
if (flag)
{
m_list = new LinkedList!(Samples)();
m_flag = true;
m_continue = true;
m_mutex = new Mutex();
}
}
void* m_userData;
int m_id;
static int seed = 0;
static SoundRecorder[int] m_instances;
/*
* Extern C callback function
*
* This function must be static for C interop. To retrieve the current
* instance, we retrieve id of the sender in the user data, and search associated instance
* in the associative array.
*
* We don't call delegate or derived class on that thread because GC is not aware of this thread
* instead we enqueue data informations in a queue and poll this queue with a managed thread.
*/
extern(C) static int internalCallback(short* s, size_t size, void* user)
{
int id;
// retrieve instance
if ((id = *cast(int*)(user)) in m_instances)
{
SoundRecorder temp = m_instances[id];
scope Lock l = new Lock(temp.m_mutex);
if (temp.m_continue)
// this new is allowed because Samples is an custom alloc class.
temp.m_list.enqueue(new Samples(s, size));
return temp.m_continue;
}
return false;
}
/*
* an init function to initialize id of the object.
*/
void init(bool flag)
{
if (flag)
{
m_list = new LinkedList!(Samples)();
m_flag = true;
m_continue = true;
m_mutex = new Mutex();
}
}
void* m_userData;
int m_id;
static int seed = 0;
static SoundRecorder[int] m_instances;
/*
* Extern C callback function
*
* This function must be static for C interop. To retrieve the current
* instance, we retrieve id of the sender in the user data, and search associated instance
* in the associative array.
*
* We don't call delegate or derived class on that thread because GC is not aware of this thread
* instead we enqueue data informations in a queue and poll this queue with a managed thread.
*/
extern(C) static int internalCallback(short* s, size_t size, void* user)
{
int id;
// retrieve instance
if ((id = *cast(int*)(user)) in m_instances)
{
SoundRecorder temp = m_instances[id];
scope Lock l = new Lock(temp.m_mutex);
if (temp.m_continue)
// this new is allowed because Samples is an custom alloc class.
temp.m_list.enqueue(new Samples(s, size));
return temp.m_continue;
}
return false;
}
extern(C) static int internalOnStart(void* user)
{
int id;
bool ret = false;
if ((id = *cast(int*)(user)) in m_instances)
{
SoundRecorder temp = m_instances[id];
ret = temp.onStart();
}
return ret;
}
extern(C) static int internalOnStart(void* user)
{
int id;
bool ret = false;
if ((id = *cast(int*)(user)) in m_instances)
{
SoundRecorder temp = m_instances[id];
ret = temp.onStart();
}
return ret;
}
extern(C) static void internalOnStop(void* user)
{
// Nothing to do
}
/*
* Managed thread loop
*/
void threadPoll()
{
while (m_flag)
{
sleep(0.05f);
// if samples are available
if (!m_list.empty)
{
// Lock ressources
scope Lock l = new Lock(m_mutex);
Samples s = m_list.dequeue;
m_continue = this.onProcessSamples(s.data[0..s.length].dup);
delete s;
if (!m_continue)
{
// delete all samples left
foreach(Samples dummy; m_list)
delete dummy;
break;
}
}
}
onStop();
}
Mutex m_mutex;
bool m_flag;
bool m_continue = true;
LinkedList!(Samples) m_list;
Thread m_t;
extern(C) static void internalOnStop(void* user)
{
// Nothing to do
}
/*
* Managed thread loop
*/
void threadPoll()
{
while (m_flag)
{
sleep(0.05f);
// if samples are available
if (!m_list.empty)
{
// Lock ressources
scope Lock l = new Lock(m_mutex);
Samples s = m_list.dequeue;
m_continue = this.onProcessSamples(s.data[0..s.length].dup);
delete s;
if (!m_continue)
{
// delete all samples left
foreach(Samples dummy; m_list)
delete dummy;
break;
}
}
}
onStop();
}
Mutex m_mutex;
bool m_flag;
bool m_continue = true;
LinkedList!(Samples) m_list;
Thread m_t;
// External ====================================================================
extern (C)
{
typedef void* function(int function(void*), int function(short*, size_t, void*), void function(void*), void*) pf_sfSoundRecorder_Create;
typedef void function(void*) pf_sfSoundRecorder_Destroy;
typedef void function(void*, uint SampleRate) pf_sfSoundRecorder_Start;
typedef void function(void*) pf_sfSoundRecorder_Stop;
typedef uint function(void*) pf_sfSoundRecorder_GetSampleRate;
typedef int function() pf_sfSoundRecorder_CanCapture;
static pf_sfSoundRecorder_Create sfSoundRecorder_Create;
static pf_sfSoundRecorder_Destroy sfSoundRecorder_Destroy;
static pf_sfSoundRecorder_Start sfSoundRecorder_Start;
static pf_sfSoundRecorder_Stop sfSoundRecorder_Stop;
static pf_sfSoundRecorder_GetSampleRate sfSoundRecorder_GetSampleRate;
static pf_sfSoundRecorder_CanCapture sfSoundRecorder_CanCapture;
}
extern (C)
{
typedef void* function(int function(void*), int function(short*, size_t, void*), void function(void*), void*) pf_sfSoundRecorder_Create;
typedef void function(void*) pf_sfSoundRecorder_Destroy;
typedef void function(void*, uint SampleRate) pf_sfSoundRecorder_Start;
typedef void function(void*) pf_sfSoundRecorder_Stop;
typedef uint function(void*) pf_sfSoundRecorder_GetSampleRate;
typedef int function() pf_sfSoundRecorder_CanCapture;
static pf_sfSoundRecorder_Create sfSoundRecorder_Create;
static pf_sfSoundRecorder_Destroy sfSoundRecorder_Destroy;
static pf_sfSoundRecorder_Start sfSoundRecorder_Start;
static pf_sfSoundRecorder_Stop sfSoundRecorder_Stop;
static pf_sfSoundRecorder_GetSampleRate sfSoundRecorder_GetSampleRate;
static pf_sfSoundRecorder_CanCapture sfSoundRecorder_CanCapture;
}
static this()
{
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-audio-d");
else
DllLoader dll = DllLoader.load("csfml-audio");
sfSoundRecorder_Create = cast(pf_sfSoundRecorder_Create)dll.getSymbol("sfSoundRecorder_Create");
sfSoundRecorder_Destroy = cast(pf_sfSoundRecorder_Destroy)dll.getSymbol("sfSoundRecorder_Destroy");
sfSoundRecorder_Start = cast(pf_sfSoundRecorder_Start)dll.getSymbol("sfSoundRecorder_Start");
sfSoundRecorder_Stop = cast(pf_sfSoundRecorder_Stop)dll.getSymbol("sfSoundRecorder_Stop");
sfSoundRecorder_GetSampleRate = cast(pf_sfSoundRecorder_GetSampleRate)dll.getSymbol("sfSoundRecorder_GetSampleRate");
sfSoundRecorder_CanCapture = cast(pf_sfSoundRecorder_CanCapture)dll.getSymbol("sfSoundRecorder_CanCapture");
}
sfSoundRecorder_Create = cast(pf_sfSoundRecorder_Create)dll.getSymbol("sfSoundRecorder_Create");
sfSoundRecorder_Destroy = cast(pf_sfSoundRecorder_Destroy)dll.getSymbol("sfSoundRecorder_Destroy");
sfSoundRecorder_Start = cast(pf_sfSoundRecorder_Start)dll.getSymbol("sfSoundRecorder_Start");
sfSoundRecorder_Stop = cast(pf_sfSoundRecorder_Stop)dll.getSymbol("sfSoundRecorder_Stop");
sfSoundRecorder_GetSampleRate = cast(pf_sfSoundRecorder_GetSampleRate)dll.getSymbol("sfSoundRecorder_GetSampleRate");
sfSoundRecorder_CanCapture = cast(pf_sfSoundRecorder_CanCapture)dll.getSymbol("sfSoundRecorder_CanCapture");
}
}
// Use explicit alloc to allow instaciation by C thread
private class Samples
{
mixin Alloc;
this(short* data, size_t length)
{
this.data = data;
this.length = length;
}
mixin Alloc;
this(short* data, size_t length)
{
this.data = data;
this.length = length;
}
public short* data;
public size_t length;
public short* data;
public size_t length;
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* 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.
* 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:
* 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.
* 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.
* 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.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.audio.soundstatus;

File diff suppressed because it is too large Load diff