Moved all bindings to the "bindings" sub-directory
Renamed the CSFML directory to c Renamed the DSFML directory to d --> bindings must now be updated to match the new organization! git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1630 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
0cc5563cac
commit
0e2297af28
417 changed files with 0 additions and 0 deletions
72
bindings/dotnet/src/Audio/Listener.cs
Normal file
72
bindings/dotnet/src/Audio/Listener.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Listener
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Global volume of all sounds, in range [0 .. 100] (default is 100)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static float GlobalVolume
|
||||
{
|
||||
get {return sfListener_GetGlobalVolume();}
|
||||
set {sfListener_SetGlobalVolume(value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 3D position of the listener (default is (0, 0, 0))
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 Position
|
||||
{
|
||||
get {Vector3 v; sfListener_GetPosition(out v.X, out v.Y, out v.Z); return v;}
|
||||
set {sfListener_SetPosition(value.X, value.Y, value.Z);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 3D direction of the listener (default is (0, 0, -1))
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 Direction
|
||||
{
|
||||
get {Vector3 v; sfListener_GetDirection(out v.X, out v.Y, out v.Z); return v;}
|
||||
set {sfListener_SetDirection(value.X, value.Y, value.Z);}
|
||||
}
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfListener_SetGlobalVolume(float Volume);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfListener_GetGlobalVolume();
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfListener_SetPosition(float X, float Y, float Z);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfListener_GetPosition(out float X, out float Y, out float Z);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfListener_SetDirection(float X, float Y, float Z);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfListener_GetDirection(out float X, out float Y, out float Z);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
333
bindings/dotnet/src/Audio/Music.cs
Normal file
333
bindings/dotnet/src/Audio/Music.cs
Normal file
|
@ -0,0 +1,333 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.IO;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Music defines a big sound played using streaming,
|
||||
/// so usually what we call a music :)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Music : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the music from a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Path of the music file to load</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Music(string filename) :
|
||||
base(sfMusic_CreateFromFile(filename))
|
||||
{
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("music", filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the music from a file in a stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream containing the file contents</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Music(Stream stream) :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
stream.Position = 0;
|
||||
byte[] StreamData = new byte[stream.Length];
|
||||
uint Read = (uint)stream.Read(StreamData, 0, StreamData.Length);
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* dataPtr = StreamData)
|
||||
{
|
||||
SetThis(sfMusic_CreateFromMemory((char*)dataPtr, Read));
|
||||
}
|
||||
}
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("music");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Play the music
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Play()
|
||||
{
|
||||
sfMusic_Play(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pause the music
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Pause()
|
||||
{
|
||||
sfMusic_Pause(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Stop the music
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Stop()
|
||||
{
|
||||
sfMusic_Stop(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Samples rate, in samples per second
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint SampleRate
|
||||
{
|
||||
get {return sfMusic_GetSampleRate(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Number of channels (1 = mono, 2 = stereo)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint ChannelsCount
|
||||
{
|
||||
get {return sfMusic_GetChannelsCount(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current status of the music (see SoundStatus enum)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundStatus Status
|
||||
{
|
||||
get {return sfMusic_GetStatus(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Total duration of the music, in seconds
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Duration
|
||||
{
|
||||
get {return sfMusic_GetDuration(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Loop state of the sound. Default value is false
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Loop
|
||||
{
|
||||
get {return sfMusic_GetLoop(This);}
|
||||
set {sfMusic_SetLoop(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pitch of the music. Default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Pitch
|
||||
{
|
||||
get {return sfMusic_GetPitch(This);}
|
||||
set {sfMusic_SetPitch(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Volume of the music, in range [0, 100]. Default value is 100
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Volume
|
||||
{
|
||||
get {return sfMusic_GetVolume(This);}
|
||||
set {sfMusic_SetVolume(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 3D position of the music. Default value is (0, 0, 0)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector3 Position
|
||||
{
|
||||
get {Vector3 v; sfMusic_GetPosition(This, out v.X, out v.Y, out v.Z); return v;}
|
||||
set {sfMusic_SetPosition(This, value.X, value.Y, value.Z);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Is the music's position relative to the listener's position,
|
||||
/// or is it absolute?
|
||||
/// Default value is false (absolute)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool RelativeToListener
|
||||
{
|
||||
get {return sfMusic_IsRelativeToListener(This);}
|
||||
set {sfMusic_SetRelativeToListener(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Minimum distance of the music. Closer than this distance,
|
||||
/// the listener will hear the sound at its maximum volume.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float MinDistance
|
||||
{
|
||||
get {return sfMusic_GetMinDistance(This);}
|
||||
set {sfMusic_SetMinDistance(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Attenuation factor. The higher the attenuation, the
|
||||
/// more the sound will be attenuated with distance from listener.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Attenuation
|
||||
{
|
||||
get {return sfMusic_GetAttenuation(This);}
|
||||
set {sfMusic_SetAttenuation(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current playing position, in seconds
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float PlayingOffset
|
||||
{
|
||||
get {return sfMusic_GetPlayingOffset(This);}
|
||||
set {sfMusic_SetPlayingOffset(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Provide a string describing the object
|
||||
/// </summary>
|
||||
/// <returns>String description of the object</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override string ToString()
|
||||
{
|
||||
return "[Music]" +
|
||||
" SampleRate(" + SampleRate + ")" +
|
||||
" ChannelsCount(" + ChannelsCount + ")" +
|
||||
" Status(" + Status + ")" +
|
||||
" Duration(" + Duration + ")" +
|
||||
" Loop(" + Loop + ")" +
|
||||
" Pitch(" + Pitch + ")" +
|
||||
" Volume(" + Volume + ")" +
|
||||
" Position(" + Position + ")" +
|
||||
" RelativeToListener(" + RelativeToListener + ")" +
|
||||
" MinDistance(" + MinDistance + ")" +
|
||||
" Attenuation(" + Attenuation + ")" +
|
||||
" PlayingOffset(" + PlayingOffset + ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfMusic_Destroy(This);
|
||||
}
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfMusic_CreateFromFile(string Filename);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
unsafe static extern IntPtr sfMusic_CreateFromMemory(char* Data, uint SizeInBytes);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_Destroy(IntPtr MusicStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_Play(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_Pause(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_Stop(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern SoundStatus sfMusic_GetStatus(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfMusic_GetDuration(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfMusic_GetChannelsCount(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfMusic_GetSampleRate(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_SetPitch(IntPtr Music, float Pitch);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_SetLoop(IntPtr Music, bool Loop);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_SetVolume(IntPtr Music, float Volume);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_SetPosition(IntPtr Music, float X, float Y, float Z);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_SetRelativeToListener(IntPtr Music, bool Relative);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_SetMinDistance(IntPtr Music, float MinDistance);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_SetAttenuation(IntPtr Music, float Attenuation);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_SetPlayingOffset(IntPtr Music, float TimeOffset);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfMusic_GetLoop(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfMusic_GetPitch(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfMusic_GetVolume(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfMusic_GetPosition(IntPtr Music, out float X, out float Y, out float Z);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfMusic_IsRelativeToListener(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfMusic_GetMinDistance(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfMusic_GetAttenuation(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfMusic_GetPlayingOffset(IntPtr Music);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
325
bindings/dotnet/src/Audio/Sound.cs
Normal file
325
bindings/dotnet/src/Audio/Sound.cs
Normal file
|
@ -0,0 +1,325 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enumeration of all possible sound states
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public enum SoundStatus
|
||||
{
|
||||
/// <summary>Sound is not playing</summary>
|
||||
Stopped,
|
||||
|
||||
/// <summary>Sound is paused</summary>
|
||||
Paused,
|
||||
|
||||
/// <summary>Sound is playing</summary>
|
||||
Playing
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Sound defines the properties of a sound such as position,
|
||||
/// volume, pitch, etc.
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Sound : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor (invalid sound)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Sound() :
|
||||
base(sfSound_Create())
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sound from a source buffer
|
||||
/// </summary>
|
||||
/// <param name="buffer">Sound buffer to play</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Sound(SoundBuffer buffer) :
|
||||
base(sfSound_Create())
|
||||
{
|
||||
SoundBuffer = buffer;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sound from another source
|
||||
/// </summary>
|
||||
/// <param name="copy">Sound to copy</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Sound(Sound copy) :
|
||||
base(sfSound_Copy(copy.This))
|
||||
{
|
||||
SoundBuffer = copy.SoundBuffer;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Play the sound
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Play()
|
||||
{
|
||||
sfSound_Play(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pause the sound
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Pause()
|
||||
{
|
||||
sfSound_Pause(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Stop the sound
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Stop()
|
||||
{
|
||||
sfSound_Stop(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Buffer containing the sound data to play through the sound
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer SoundBuffer
|
||||
{
|
||||
get {return myBuffer;}
|
||||
set {myBuffer = value; sfSound_SetBuffer(This, value != null ? value.This : IntPtr.Zero);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current status of the sound (see SoundStatus enum)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundStatus Status
|
||||
{
|
||||
get {return sfSound_GetStatus(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Loop state of the sound. Default value is false
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Loop
|
||||
{
|
||||
get {return sfSound_GetLoop(This);}
|
||||
set {sfSound_SetLoop(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pitch of the sound. Default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Pitch
|
||||
{
|
||||
get {return sfSound_GetPitch(This);}
|
||||
set {sfSound_SetPitch(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Volume of the sound, in range [0, 100]. Default value is 100
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Volume
|
||||
{
|
||||
get {return sfSound_GetVolume(This);}
|
||||
set {sfSound_SetVolume(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current playing position of the sound, in seconds
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float PlayingOffset
|
||||
{
|
||||
get {return sfSound_GetPlayingOffset(This);}
|
||||
set {sfSound_SetPlayingOffset(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 3D position of the sound. Default value is (0, 0, 0)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector3 Position
|
||||
{
|
||||
get {Vector3 v; sfSound_GetPosition(This, out v.X, out v.Y, out v.Z); return v;}
|
||||
set {sfSound_SetPosition(This, value.X, value.Y, value.Z);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Is the sound's position relative to the listener's position,
|
||||
/// or is it absolute?
|
||||
/// Default value is false (absolute)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool RelativeToListener
|
||||
{
|
||||
get {return sfSound_IsRelativeToListener(This);}
|
||||
set {sfSound_SetRelativeToListener(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Minimum distance of the sound. Closer than this distance,
|
||||
/// the listener will hear the sound at its maximum volume.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float MinDistance
|
||||
{
|
||||
get {return sfSound_GetMinDistance(This);}
|
||||
set {sfSound_SetMinDistance(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Attenuation factor. The higher the attenuation, the
|
||||
/// more the sound will be attenuated with distance from listener.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Attenuation
|
||||
{
|
||||
get {return sfSound_GetAttenuation(This);}
|
||||
set {sfSound_SetAttenuation(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Provide a string describing the object
|
||||
/// </summary>
|
||||
/// <returns>String description of the object</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override string ToString()
|
||||
{
|
||||
return "[Sound]" +
|
||||
" Status(" + Status + ")" +
|
||||
" Loop(" + Loop + ")" +
|
||||
" Pitch(" + Pitch + ")" +
|
||||
" Volume(" + Volume + ")" +
|
||||
" Position(" + Position + ")" +
|
||||
" RelativeToListener(" + RelativeToListener + ")" +
|
||||
" MinDistance(" + MinDistance + ")" +
|
||||
" Attenuation(" + Attenuation + ")" +
|
||||
" PlayingOffset(" + PlayingOffset + ")" +
|
||||
" SoundBuffer(" + SoundBuffer + ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfSound_Destroy(This);
|
||||
}
|
||||
|
||||
private SoundBuffer myBuffer;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSound_Create();
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSound_Copy(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_Destroy(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_Play(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_Pause(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_Stop(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetBuffer(IntPtr Sound, IntPtr Buffer);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSound_GetBuffer(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetLoop(IntPtr Sound, bool Loop);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfSound_GetLoop(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern SoundStatus sfSound_GetStatus(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetPitch(IntPtr Sound, float Pitch);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetVolume(IntPtr Sound, float Volume);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetPosition(IntPtr Sound, float X, float Y, float Z);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetRelativeToListener(IntPtr Sound, bool Relative);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetMinDistance(IntPtr Sound, float MinDistance);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetAttenuation(IntPtr Sound, float Attenuation);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetPlayingOffset(IntPtr Sound, float TimeOffset);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSound_GetPitch(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSound_GetVolume(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_GetPosition(IntPtr Sound, out float X, out float Y, out float Z);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfSound_IsRelativeToListener(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSound_GetMinDistance(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSound_GetAttenuation(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSound_GetPlayingOffset(IntPtr Sound);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
209
bindings/dotnet/src/Audio/SoundBuffer.cs
Normal file
209
bindings/dotnet/src/Audio/SoundBuffer.cs
Normal file
|
@ -0,0 +1,209 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.IO;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// SoundBuffer is the low-level class for loading and manipulating
|
||||
/// sound buffers. A sound buffer holds audio data (samples)
|
||||
/// which can then be played by a Sound or saved to a file.
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class SoundBuffer : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sound buffer from a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Path of the sound file to load</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer(string filename) :
|
||||
base(sfSoundBuffer_CreateFromFile(filename))
|
||||
{
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("sound buffer", filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sound buffer from a file in a stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream containing the file contents</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer(Stream stream) :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
stream.Position = 0;
|
||||
byte[] StreamData = new byte[stream.Length];
|
||||
uint Read = (uint)stream.Read(StreamData, 0, StreamData.Length);
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* dataPtr = StreamData)
|
||||
{
|
||||
SetThis(sfSoundBuffer_CreateFromMemory((char*)dataPtr, Read));
|
||||
}
|
||||
}
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("sound buffer");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sound buffer from an array of samples
|
||||
/// </summary>
|
||||
/// <param name="samples">Array of samples</param>
|
||||
/// <param name="channelsCount">Channels count</param>
|
||||
/// <param name="sampleRate">Sample rate</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer(short[] samples, uint channelsCount, uint sampleRate) :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (short* SamplesPtr = samples)
|
||||
{
|
||||
SetThis(sfSoundBuffer_CreateFromSamples(SamplesPtr, (uint)samples.Length, channelsCount, sampleRate));
|
||||
}
|
||||
}
|
||||
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("sound buffer");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sound buffer from another sound buffer
|
||||
/// </summary>
|
||||
/// <param name="copy">Sound buffer to copy</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer(SoundBuffer copy) :
|
||||
base(sfSoundBuffer_Copy(copy.This))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Save the sound buffer to an audio file
|
||||
/// </summary>
|
||||
/// <param name="filename">Path of the sound file to write</param>
|
||||
/// <returns>True if saving has been successful</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool SaveToFile(string filename)
|
||||
{
|
||||
return sfSoundBuffer_SaveToFile(This, filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Samples rate, in samples per second
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint SampleRate
|
||||
{
|
||||
get {return sfSoundBuffer_GetSampleRate(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Number of channels (1 = mono, 2 = stereo)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint ChannelsCount
|
||||
{
|
||||
get {return sfSoundBuffer_GetChannelsCount(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Total duration of the buffer, in seconds
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Duration
|
||||
{
|
||||
get {return sfSoundBuffer_GetDuration(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Array of samples contained in the buffer
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public short[] Samples
|
||||
{
|
||||
get
|
||||
{
|
||||
short[] SamplesArray = new short[sfSoundBuffer_GetSamplesCount(This)];
|
||||
Marshal.Copy(sfSoundBuffer_GetSamples(This), SamplesArray, 0, SamplesArray.Length);
|
||||
return SamplesArray;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Provide a string describing the object
|
||||
/// </summary>
|
||||
/// <returns>String description of the object</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override string ToString()
|
||||
{
|
||||
return "[SoundBuffer]" +
|
||||
" SampleRate(" + SampleRate + ")" +
|
||||
" ChannelsCount(" + ChannelsCount + ")" +
|
||||
" Duration(" + Duration + ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfSoundBuffer_Destroy(This);
|
||||
}
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSoundBuffer_CreateFromFile(string Filename);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
unsafe static extern IntPtr sfSoundBuffer_CreateFromMemory(char* Data, uint SizeInBytes);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
unsafe static extern IntPtr sfSoundBuffer_CreateFromSamples(short* Samples, uint SamplesCount, uint ChannelsCount, uint SampleRate);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSoundBuffer_Copy(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundBuffer_Destroy(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfSoundBuffer_SaveToFile(IntPtr SoundBuffer, string Filename);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSoundBuffer_GetSamples(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfSoundBuffer_GetSamplesCount(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfSoundBuffer_GetSampleRate(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfSoundBuffer_GetChannelsCount(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSoundBuffer_GetDuration(IntPtr SoundBuffer);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
83
bindings/dotnet/src/Audio/SoundBufferRecorder.cs
Normal file
83
bindings/dotnet/src/Audio/SoundBufferRecorder.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Specialized SoundRecorder which saves the captured
|
||||
/// audio data into a sound buffer
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class SoundBufferRecorder : SoundRecorder
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Sound buffer containing the recorded data (invalid until the capture stops)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer SoundBuffer
|
||||
{
|
||||
get
|
||||
{
|
||||
return mySoundBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Provide a string describing the object
|
||||
/// </summary>
|
||||
/// <returns>String description of the object</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override string ToString()
|
||||
{
|
||||
return "[SoundBufferRecorder]" +
|
||||
" SampleRate(" + SampleRate + ")" +
|
||||
" SoundBuffer(" + SoundBuffer + ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called when a new capture starts
|
||||
/// </summary>
|
||||
/// <returns>False to abort recording audio data, true to continue</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override bool OnStart()
|
||||
{
|
||||
mySamplesArray.Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Process a new chunk of recorded samples
|
||||
/// </summary>
|
||||
/// <param name="samples">Array of samples to process</param>
|
||||
/// <returns>False to stop recording audio data, true to continue</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override bool OnProcessSamples(short[] samples)
|
||||
{
|
||||
mySamplesArray.AddRange(samples);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called when the current capture stops
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void OnStop()
|
||||
{
|
||||
mySoundBuffer = new SoundBuffer(mySamplesArray.ToArray(), 1, SampleRate);
|
||||
}
|
||||
|
||||
List<short> mySamplesArray = new List<short>();
|
||||
SoundBuffer mySoundBuffer = null;
|
||||
}
|
||||
}
|
||||
}
|
192
bindings/dotnet/src/Audio/SoundRecorder.cs
Normal file
192
bindings/dotnet/src/Audio/SoundRecorder.cs
Normal file
|
@ -0,0 +1,192 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// SoundRecorder is an interface for capturing sound data,
|
||||
/// it is meant to be used as a base class
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract class SoundRecorder : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundRecorder() :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
myStartCallback = new StartCallback(OnStart);
|
||||
myProcessCallback = new ProcessCallback(ProcessSamples);
|
||||
myStopCallback = new StopCallback(OnStop);
|
||||
|
||||
SetThis(sfSoundRecorder_Create(myStartCallback, myProcessCallback, myStopCallback, IntPtr.Zero));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Start the capture using default sample rate (44100 Hz)
|
||||
/// Warning : only one capture can happen at the same time
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Start()
|
||||
{
|
||||
Start(44100);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Start the capture.
|
||||
/// Warning : only one capture can happen at the same time
|
||||
/// </summary>
|
||||
/// <param name="sampleRate"> Sound frequency; the more samples, the higher the quality (44100 by default = CD quality)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Start(uint sampleRate)
|
||||
{
|
||||
sfSoundRecorder_Start(This, sampleRate);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Stop the capture
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Stop()
|
||||
{
|
||||
sfSoundRecorder_Stop(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Sample rate of the recorder, in samples per second
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint SampleRate
|
||||
{
|
||||
get {return sfSoundRecorder_GetSampleRate(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Tell if the system supports sound capture.
|
||||
/// If not, this class won't be usable
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static bool IsAvailable
|
||||
{
|
||||
get {return sfSoundRecorder_IsAvailable();}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Provide a string describing the object
|
||||
/// </summary>
|
||||
/// <returns>String description of the object</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override string ToString()
|
||||
{
|
||||
return "[SoundRecorder]" +
|
||||
" SampleRate(" + SampleRate + ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called when a new capture starts
|
||||
/// </summary>
|
||||
/// <returns>False to abort recording audio data, true to continue</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected virtual bool OnStart()
|
||||
{
|
||||
// Does nothing by default
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Process a new chunk of recorded samples
|
||||
/// </summary>
|
||||
/// <param name="samples">Array of samples to process</param>
|
||||
/// <returns>False to stop recording audio data, true to continue</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected abstract bool OnProcessSamples(short[] samples);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called when the current capture stops
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected virtual void OnStop()
|
||||
{
|
||||
// Does nothing by default
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfSoundRecorder_Destroy(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Function called directly by the C library ; convert
|
||||
/// arguments and forward them to the internal virtual function
|
||||
/// </summary>
|
||||
/// <param name="samples">Pointer to the array of samples</param>
|
||||
/// <param name="nbSamples">Number of samples in the array</param>
|
||||
/// <param name="userData">User data -- unused</param>
|
||||
/// <returns>False to stop recording audio data, true to continue</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
private bool ProcessSamples(IntPtr samples, uint nbSamples, IntPtr userData)
|
||||
{
|
||||
short[] samplesArray = new short[nbSamples];
|
||||
Marshal.Copy(samples, samplesArray, 0, samplesArray.Length);
|
||||
|
||||
return OnProcessSamples(samplesArray);
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate bool StartCallback();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate bool ProcessCallback(IntPtr samples, uint nbSamples, IntPtr userData);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate void StopCallback();
|
||||
|
||||
private StartCallback myStartCallback;
|
||||
private ProcessCallback myProcessCallback;
|
||||
private StopCallback myStopCallback;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSoundRecorder_Create(StartCallback OnStart, ProcessCallback OnProcess, StopCallback OnStop, IntPtr UserData);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundRecorder_Destroy(IntPtr SoundRecorder);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundRecorder_Start(IntPtr SoundRecorder, uint SampleRate);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundRecorder_Stop(IntPtr SoundRecorder);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfSoundRecorder_GetSampleRate(IntPtr SoundRecorder);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfSoundRecorder_IsAvailable();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
386
bindings/dotnet/src/Audio/SoundStream.cs
Normal file
386
bindings/dotnet/src/Audio/SoundStream.cs
Normal file
|
@ -0,0 +1,386 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// SoundStream is a streamed sound, ie. samples are acquired
|
||||
/// while the sound is playing. Use it for big sounds that would
|
||||
/// require hundreds of MB in memory (see Music),
|
||||
/// or for streaming sound from the network
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract class SoundStream : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundStream() :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Play the sound stream
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Play()
|
||||
{
|
||||
sfSoundStream_Play(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pause the sound stream
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Pause()
|
||||
{
|
||||
sfSoundStream_Pause(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Stop the sound stream
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Stop()
|
||||
{
|
||||
sfSoundStream_Stop(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Samples rate, in samples per second
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint SampleRate
|
||||
{
|
||||
get {return sfSoundStream_GetSampleRate(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Number of channels (1 = mono, 2 = stereo)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint ChannelsCount
|
||||
{
|
||||
get {return sfSoundStream_GetChannelsCount(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current status of the sound stream (see SoundStatus enum)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundStatus Status
|
||||
{
|
||||
get {return sfSoundStream_GetStatus(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Loop state of the sound stream. Default value is false
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Loop
|
||||
{
|
||||
get {return sfSoundStream_GetLoop(This);}
|
||||
set {sfSoundStream_SetLoop(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pitch of the sound stream. Default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Pitch
|
||||
{
|
||||
get {return sfSoundStream_GetPitch(This);}
|
||||
set {sfSoundStream_SetPitch(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Volume of the sound stream, in range [0, 100]. Default value is 100
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Volume
|
||||
{
|
||||
get {return sfSoundStream_GetVolume(This);}
|
||||
set {sfSoundStream_SetVolume(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 3D position of the sound stream. Default value is (0, 0, 0)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector3 Position
|
||||
{
|
||||
get {Vector3 v; sfSoundStream_GetPosition(This, out v.X, out v.Y, out v.Z); return v;}
|
||||
set {sfSoundStream_SetPosition(This, value.X, value.Y, value.Z);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Is the sound stream's position relative to the listener's position,
|
||||
/// or is it absolute?
|
||||
/// Default value is false (absolute)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool RelativeToListener
|
||||
{
|
||||
get {return sfSoundStream_IsRelativeToListener(This);}
|
||||
set {sfSoundStream_SetRelativeToListener(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Minimum distance of the sound stream. Closer than this distance,
|
||||
/// the listener will hear the sound at its maximum volume.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float MinDistance
|
||||
{
|
||||
get {return sfSoundStream_GetMinDistance(This);}
|
||||
set {sfSoundStream_SetMinDistance(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Attenuation factor. The higher the attenuation, the
|
||||
/// more the sound will be attenuated with distance from listener.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Attenuation
|
||||
{
|
||||
get {return sfSoundStream_GetAttenuation(This);}
|
||||
set {sfSoundStream_SetAttenuation(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current playing position, in seconds
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float PlayingOffset
|
||||
{
|
||||
get {return sfSoundStream_GetPlayingOffset(This);}
|
||||
set {sfSoundStream_SetPlayingOffset(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Provide a string describing the object
|
||||
/// </summary>
|
||||
/// <returns>String description of the object</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override string ToString()
|
||||
{
|
||||
return "[SoundStream]" +
|
||||
" SampleRate(" + SampleRate + ")" +
|
||||
" ChannelsCount(" + ChannelsCount + ")" +
|
||||
" Status(" + Status + ")" +
|
||||
" Loop(" + Loop + ")" +
|
||||
" Pitch(" + Pitch + ")" +
|
||||
" Volume(" + Volume + ")" +
|
||||
" Position(" + Position + ")" +
|
||||
" RelativeToListener(" + RelativeToListener + ")" +
|
||||
" MinDistance(" + MinDistance + ")" +
|
||||
" Attenuation(" + Attenuation + ")" +
|
||||
" PlayingOffset(" + PlayingOffset + ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Set the audio stream parameters, you must call it before Play()
|
||||
/// </summary>
|
||||
/// <param name="sampleRate">Number of channels</param>
|
||||
/// <param name="channelsCount">Sample rate, in samples per second</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected void Initialize(uint channelsCount, uint sampleRate)
|
||||
{
|
||||
myGetDataCallback = new GetDataCallbackType(GetData);
|
||||
mySeekCallback = new SeekCallbackType(Seek);
|
||||
SetThis(sfSoundStream_Create(myGetDataCallback, mySeekCallback, channelsCount, sampleRate, IntPtr.Zero));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Virtual function called each time new audio data is needed to feed the stream
|
||||
/// </summary>
|
||||
/// <param name="samples">Array of samples to fill for the stream</param>
|
||||
/// <returns>True to continue playback, false to stop</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected abstract bool OnGetData(out short[] samples);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Virtual function called to seek into the stream
|
||||
/// </summary>
|
||||
/// <param name="timeOffset">New position, expressed in seconds</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected abstract void OnSeek(float timeOffset);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfSoundStream_Destroy(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Structure mapping the C library arguments passed to the data callback
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct Chunk
|
||||
{
|
||||
unsafe public short* samplesPtr;
|
||||
public uint samplesCount;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called each time new audio data is needed to feed the stream
|
||||
/// </summary>
|
||||
/// <param name="dataChunk">Data chunk to fill with new audio samples</param>
|
||||
/// <param name="userData">User data -- unused</param>
|
||||
/// <returns>True to continue playback, false to stop</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
private bool GetData(ref Chunk dataChunk, IntPtr userData)
|
||||
{
|
||||
if (OnGetData(out myTempBuffer))
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (short* samplesPtr = myTempBuffer)
|
||||
{
|
||||
dataChunk.samplesPtr = samplesPtr;
|
||||
dataChunk.samplesCount = (uint)myTempBuffer.Length;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called to seek in the stream
|
||||
/// </summary>
|
||||
/// <param name="timeOffset">New position, expressed in seconds</param>
|
||||
/// <param name="userData">User data -- unused</param>
|
||||
/// <returns>If false is returned, the playback is aborted</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
private void Seek(float timeOffset, IntPtr userData)
|
||||
{
|
||||
OnSeek(timeOffset);
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate bool GetDataCallbackType(ref Chunk dataChunk, IntPtr UserData);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate void SeekCallbackType(float timeOffset, IntPtr UserData);
|
||||
|
||||
private GetDataCallbackType myGetDataCallback;
|
||||
private SeekCallbackType mySeekCallback;
|
||||
private short[] myTempBuffer;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSoundStream_Create(GetDataCallbackType OnGetData, SeekCallbackType OnSeek, uint ChannelsCount, uint SampleRate, IntPtr UserData);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_Destroy(IntPtr SoundStreamStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_Play(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_Pause(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_Stop(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern SoundStatus sfSoundStream_GetStatus(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfSoundStream_GetChannelsCount(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfSoundStream_GetSampleRate(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_SetLoop(IntPtr SoundStream, bool Loop);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_SetPitch(IntPtr SoundStream, float Pitch);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_SetVolume(IntPtr SoundStream, float Volume);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_SetPosition(IntPtr SoundStream, float X, float Y, float Z);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_SetRelativeToListener(IntPtr SoundStream, bool Relative);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_SetMinDistance(IntPtr SoundStream, float MinDistance);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_SetAttenuation(IntPtr SoundStream, float Attenuation);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_SetPlayingOffset(IntPtr SoundStream, float TimeOffset);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfSoundStream_GetLoop(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSoundStream_GetPitch(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSoundStream_GetVolume(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundStream_GetPosition(IntPtr SoundStream, out float X, out float Y, out float Z);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfSoundStream_IsRelativeToListener(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSoundStream_GetMinDistance(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSoundStream_GetAttenuation(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio-2", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSoundStream_GetPlayingOffset(IntPtr SoundStream);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
133
bindings/dotnet/src/Audio/Vector3.cs
Normal file
133
bindings/dotnet/src/Audio/Vector3.cs
Normal file
|
@ -0,0 +1,133 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Vector3 is an utility class for manipulating 3 dimensional
|
||||
/// vectors with float components
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Vector3
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the vector from its coordinates
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate</param>
|
||||
/// <param name="y">Y coordinate</param>
|
||||
/// <param name="z">Z coordinate</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector3(float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator - overload ; returns the opposite of a vector
|
||||
/// </summary>
|
||||
/// <param name="v">Vector to negate</param>
|
||||
/// <returns>-v</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator -(Vector3 v)
|
||||
{
|
||||
return new Vector3(-v.X, -v.Y, -v.Z);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator - overload ; subtracts two vectors
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>v1 - v2</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator -(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return new Vector3(v1.X - v2.X, v1.Y - v2.X, v1.Z - v2.Z);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator + overload ; add two vectors
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>v1 + v2</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator +(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return new Vector3(v1.X + v2.X, v1.Y + v2.X, v1.Z + v2.Z);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator * overload ; multiply a vector by a scalar value
|
||||
/// </summary>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <param name="x">Scalar value</param>
|
||||
/// <returns>v * x</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator *(Vector3 v, float x)
|
||||
{
|
||||
return new Vector3(v.X * x, v.Y * x, v.Z * x);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator * overload ; multiply a scalar value by a vector
|
||||
/// </summary>
|
||||
/// <param name="x">Scalar value</param>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <returns>x * v</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator *(float x, Vector3 v)
|
||||
{
|
||||
return new Vector3(v.X * x, v.Y * x, v.Z * x);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator / overload ; divide a vector by a scalar value
|
||||
/// </summary>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <param name="x">Scalar value</param>
|
||||
/// <returns>v / x</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator /(Vector3 v, float x)
|
||||
{
|
||||
return new Vector3(v.X / x, v.Y / x, v.Z / x);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Provide a string describing the object
|
||||
/// </summary>
|
||||
/// <returns>String description of the object</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override string ToString()
|
||||
{
|
||||
return "[Vector3]" +
|
||||
" X(" + X + ")" +
|
||||
" Y(" + Y + ")" +
|
||||
" Z(" + Z + ")";
|
||||
}
|
||||
|
||||
/// <summary>X (horizontal) component of the vector</summary>
|
||||
public float X;
|
||||
|
||||
/// <summary>Y (vertical) component of the vector</summary>
|
||||
public float Y;
|
||||
|
||||
/// <summary>Z (depth) component of the vector</summary>
|
||||
public float Z;
|
||||
}
|
||||
}
|
||||
}
|
69
bindings/dotnet/src/Audio/sfml-audio.csproj
Normal file
69
bindings/dotnet/src/Audio/sfml-audio.csproj
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{0B202C4D-A457-47FE-84A3-031DD878C6BE}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SFML.Audio</RootNamespace>
|
||||
<AssemblyName>sfmlnet-audio-2</AssemblyName>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>2.0</OldToolsVersion>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\lib\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DocumentationFile>..\..\doc\build\audio-doc.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\lib\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DocumentationFile>..\..\doc\build\audio-doc.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Compile Include="Listener.cs" />
|
||||
<Compile Include="Music.cs" />
|
||||
<Compile Include="Sound.cs" />
|
||||
<Compile Include="SoundBuffer.cs" />
|
||||
<Compile Include="SoundBufferRecorder.cs" />
|
||||
<Compile Include="SoundRecorder.cs" />
|
||||
<Compile Include="SoundStream.cs" />
|
||||
<Compile Include="Vector3.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Window\sfml-window.csproj">
|
||||
<Project>{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}</Project>
|
||||
<Name>sfml-window</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue