Fixed that Uri produces %20 in the paths and fixed an OpenALSoundEffect constructor
This commit is contained in:
parent
0d25ca7589
commit
c99598446f
@ -106,16 +106,14 @@ namespace ANX.SoundSystem.OpenAL
|
|||||||
public ISoundEffect CreateSoundEffect(SoundEffect parent, Stream stream)
|
public ISoundEffect CreateSoundEffect(SoundEffect parent, Stream stream)
|
||||||
{
|
{
|
||||||
PreventSystemChange();
|
PreventSystemChange();
|
||||||
return new OpenALSoundEffect(parent, stream);
|
return new OpenALSoundEffect(stream);
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region CreateSoundEffect
|
|
||||||
public ISoundEffect CreateSoundEffect(SoundEffect parent, byte[] buffer, int offset, int count, int sampleRate,
|
public ISoundEffect CreateSoundEffect(SoundEffect parent, byte[] buffer, int offset, int count, int sampleRate,
|
||||||
AudioChannels channels, int loopStart, int loopLength)
|
AudioChannels channels, int loopStart, int loopLength)
|
||||||
{
|
{
|
||||||
PreventSystemChange();
|
PreventSystemChange();
|
||||||
return new OpenALSoundEffect(parent, buffer, offset, count, sampleRate, channels, loopStart, loopLength);
|
return new OpenALSoundEffect(buffer, offset, count, sampleRate, channels, loopStart, loopLength);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using ANX.Framework;
|
using ANX.Framework;
|
||||||
|
using ANX.Framework.NonXNA.Development;
|
||||||
using ANX.Framework.NonXNA.SoundSystem;
|
using ANX.Framework.NonXNA.SoundSystem;
|
||||||
using OpenTK.Audio.OpenAL;
|
using OpenTK.Audio.OpenAL;
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ using OpenTK.Audio.OpenAL;
|
|||||||
|
|
||||||
namespace ANX.SoundSystem.OpenAL
|
namespace ANX.SoundSystem.OpenAL
|
||||||
{
|
{
|
||||||
|
[Developer("AstrorEnales")]
|
||||||
public class OpenALAudioListener : IAudioListener
|
public class OpenALAudioListener : IAudioListener
|
||||||
{
|
{
|
||||||
#region Private
|
#region Private
|
||||||
|
@ -30,8 +30,9 @@ namespace ANX.SoundSystem.OpenAL
|
|||||||
|
|
||||||
public OpenALSong(Song setParent, Uri uri)
|
public OpenALSong(Song setParent, Uri uri)
|
||||||
{
|
{
|
||||||
|
string path = uri.AbsolutePath.Replace("%20", "");
|
||||||
parent = setParent;
|
parent = setParent;
|
||||||
Init(uri.AbsolutePath);
|
Init(path);
|
||||||
// TODO: duration
|
// TODO: duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using ANX.Framework.Audio;
|
using ANX.Framework.Audio;
|
||||||
|
using ANX.Framework.NonXNA.Development;
|
||||||
using ANX.Framework.NonXNA.SoundSystem;
|
using ANX.Framework.NonXNA.SoundSystem;
|
||||||
using OpenTK.Audio.OpenAL;
|
using OpenTK.Audio.OpenAL;
|
||||||
using WaveUtils;
|
using WaveUtils;
|
||||||
@ -12,45 +13,47 @@ using ALFormat = OpenTK.Audio.OpenAL.ALFormat;
|
|||||||
|
|
||||||
namespace ANX.SoundSystem.OpenAL
|
namespace ANX.SoundSystem.OpenAL
|
||||||
{
|
{
|
||||||
|
[Developer("AstrorEnales")]
|
||||||
public class OpenALSoundEffect : ISoundEffect
|
public class OpenALSoundEffect : ISoundEffect
|
||||||
{
|
{
|
||||||
#region Private
|
#region Private
|
||||||
internal SoundEffect parent;
|
|
||||||
private WaveInfo waveInfo;
|
private WaveInfo waveInfo;
|
||||||
private TimeSpan duration;
|
private TimeSpan duration;
|
||||||
internal int bufferHandle;
|
internal int BufferHandle { get; private set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public
|
#region Public
|
||||||
public TimeSpan Duration
|
public TimeSpan Duration
|
||||||
{
|
{
|
||||||
get
|
get { return duration; }
|
||||||
{
|
}
|
||||||
return duration;
|
#endregion
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
#region Constructor
|
||||||
internal OpenALSoundEffect(SoundEffect setParent, Stream stream)
|
internal OpenALSoundEffect(Stream stream)
|
||||||
{
|
{
|
||||||
parent = setParent;
|
|
||||||
CreateFromStream(stream);
|
CreateFromStream(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal OpenALSoundEffect(SoundEffect setParent, byte[] buffer, int offset, int count, int sampleRate,
|
internal OpenALSoundEffect(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels,
|
||||||
AudioChannels channels, int loopStart, int loopLength)
|
int loopStart, int loopLength)
|
||||||
{
|
{
|
||||||
parent = setParent;
|
// TODO: loopStart and loopLength
|
||||||
|
|
||||||
using (MemoryStream stream = new MemoryStream())
|
byte[] subBuffer = new byte[count];
|
||||||
{
|
Array.Copy(buffer, offset, subBuffer, 0, count);
|
||||||
BinaryWriter writer = new BinaryWriter(stream);
|
BufferHandle = AL.GenBuffer();
|
||||||
writer.Write(buffer, offset, count);
|
|
||||||
stream.Position = 0;
|
|
||||||
|
|
||||||
CreateFromStream(stream);
|
// TODO: evaluate if 8bit or 16bit!!
|
||||||
}
|
ALFormat format = channels == AudioChannels.Mono ? ALFormat.Mono8 : ALFormat.Stereo8;
|
||||||
|
AL.BufferData(BufferHandle, format, subBuffer, count, sampleRate);
|
||||||
|
|
||||||
|
float sizeMulBlockAlign = count / ((int)channels * 2f);
|
||||||
|
duration = TimeSpan.FromMilliseconds(sizeMulBlockAlign * 1000f / sampleRate);
|
||||||
|
|
||||||
|
ALError error = AL.GetError();
|
||||||
|
if (error != ALError.NoError)
|
||||||
|
throw new Exception("OpenAL error " + error + ": " + AL.GetErrorString(error));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -60,14 +63,14 @@ namespace ANX.SoundSystem.OpenAL
|
|||||||
waveInfo = WaveFile.LoadData(stream);
|
waveInfo = WaveFile.LoadData(stream);
|
||||||
if (waveInfo.WaveFormat != WaveFormat.PCM)
|
if (waveInfo.WaveFormat != WaveFormat.PCM)
|
||||||
{
|
{
|
||||||
WaveConverter converter = new WaveConverter(waveInfo);
|
var converter = new WaveConverter(waveInfo);
|
||||||
converter.ConvertToPcm();
|
converter.ConvertToPcm();
|
||||||
}
|
}
|
||||||
|
|
||||||
duration = waveInfo.CalculateDuration();
|
duration = waveInfo.CalculateDuration();
|
||||||
|
|
||||||
bufferHandle = AL.GenBuffer();
|
BufferHandle = AL.GenBuffer();
|
||||||
AL.BufferData(bufferHandle, (ALFormat)waveInfo.ALFormat, waveInfo.Data, waveInfo.Data.Length, waveInfo.SampleRate);
|
AL.BufferData(BufferHandle, (ALFormat)waveInfo.ALFormat, waveInfo.Data, waveInfo.Data.Length, waveInfo.SampleRate);
|
||||||
|
|
||||||
ALError error = AL.GetError();
|
ALError error = AL.GetError();
|
||||||
if (error != ALError.NoError)
|
if (error != ALError.NoError)
|
||||||
@ -79,8 +82,7 @@ namespace ANX.SoundSystem.OpenAL
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
waveInfo = null;
|
waveInfo = null;
|
||||||
|
AL.DeleteBuffer(BufferHandle);
|
||||||
AL.DeleteBuffer(bufferHandle);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using ANX.Framework.Audio;
|
using ANX.Framework.Audio;
|
||||||
|
using ANX.Framework.NonXNA.Development;
|
||||||
using ANX.Framework.NonXNA.SoundSystem;
|
using ANX.Framework.NonXNA.SoundSystem;
|
||||||
using OpenTK.Audio.OpenAL;
|
using OpenTK.Audio.OpenAL;
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ using OpenTK.Audio.OpenAL;
|
|||||||
|
|
||||||
namespace ANX.SoundSystem.OpenAL
|
namespace ANX.SoundSystem.OpenAL
|
||||||
{
|
{
|
||||||
|
[Developer("AstrorEnales")]
|
||||||
public class OpenALSoundEffectInstance : ISoundEffectInstance
|
public class OpenALSoundEffectInstance : ISoundEffectInstance
|
||||||
{
|
{
|
||||||
#region Private
|
#region Private
|
||||||
@ -70,7 +72,7 @@ namespace ANX.SoundSystem.OpenAL
|
|||||||
parent = setParent;
|
parent = setParent;
|
||||||
State = SoundState.Stopped;
|
State = SoundState.Stopped;
|
||||||
handle = AL.GenSource();
|
handle = AL.GenSource();
|
||||||
AL.Source(handle, ALSourcei.Buffer, parent.bufferHandle);
|
AL.Source(handle, ALSourcei.Buffer, parent.BufferHandle);
|
||||||
IsLooped = false;
|
IsLooped = false;
|
||||||
Pitch = 1f;
|
Pitch = 1f;
|
||||||
Volume = 1f;
|
Volume = 1f;
|
||||||
|
@ -13,7 +13,7 @@ namespace ANX.SoundSystem.OpenAL
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return new PlatformName[]
|
return new[]
|
||||||
{
|
{
|
||||||
PlatformName.Windows7,
|
PlatformName.Windows7,
|
||||||
PlatformName.WindowsXP,
|
PlatformName.WindowsXP,
|
||||||
|
@ -131,14 +131,14 @@ namespace ANX.SoundSystem.Windows.XAudio
|
|||||||
public ISoundEffect CreateSoundEffect(SoundEffect parent, Stream stream)
|
public ISoundEffect CreateSoundEffect(SoundEffect parent, Stream stream)
|
||||||
{
|
{
|
||||||
PreventSystemChange();
|
PreventSystemChange();
|
||||||
return new XAudioSoundEffect(parent, stream);
|
return new XAudioSoundEffect(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISoundEffect CreateSoundEffect(SoundEffect parent, byte[] buffer, int offset, int count, int sampleRate,
|
public ISoundEffect CreateSoundEffect(SoundEffect parent, byte[] buffer, int offset, int count, int sampleRate,
|
||||||
AudioChannels channels, int loopStart, int loopLength)
|
AudioChannels channels, int loopStart, int loopLength)
|
||||||
{
|
{
|
||||||
PreventSystemChange();
|
PreventSystemChange();
|
||||||
return new XAudioSoundEffect(parent, buffer, offset, count, sampleRate, channels, loopStart, loopLength);
|
return new XAudioSoundEffect(buffer, offset, count, sampleRate, channels, loopStart, loopLength);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@ namespace ANX.SoundSystem.Windows.XAudio
|
|||||||
|
|
||||||
public XAudioSong(XAudio2 device, Uri uri)
|
public XAudioSong(XAudio2 device, Uri uri)
|
||||||
{
|
{
|
||||||
Init(device, uri.AbsolutePath);
|
string path = uri.AbsolutePath.Replace("%20", "");
|
||||||
|
Init(device, path);
|
||||||
// TODO: duration
|
// TODO: duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using ANX.Framework.Audio;
|
using ANX.Framework.Audio;
|
||||||
|
using ANX.Framework.NonXNA.Development;
|
||||||
using ANX.Framework.NonXNA.SoundSystem;
|
using ANX.Framework.NonXNA.SoundSystem;
|
||||||
using SharpDX.Multimedia;
|
using SharpDX.Multimedia;
|
||||||
using SharpDX.XAudio2;
|
using SharpDX.XAudio2;
|
||||||
@ -11,10 +12,10 @@ using SharpDX.XAudio2;
|
|||||||
|
|
||||||
namespace ANX.SoundSystem.Windows.XAudio
|
namespace ANX.SoundSystem.Windows.XAudio
|
||||||
{
|
{
|
||||||
|
[Developer("AstrorEnales")]
|
||||||
public class XAudioSoundEffect : ISoundEffect
|
public class XAudioSoundEffect : ISoundEffect
|
||||||
{
|
{
|
||||||
#region Private
|
#region Private
|
||||||
internal SoundEffect Parent;
|
|
||||||
private TimeSpan duration;
|
private TimeSpan duration;
|
||||||
internal WaveFormat WaveFormat;
|
internal WaveFormat WaveFormat;
|
||||||
internal AudioBuffer AudioBuffer;
|
internal AudioBuffer AudioBuffer;
|
||||||
@ -29,24 +30,16 @@ namespace ANX.SoundSystem.Windows.XAudio
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructor
|
#region Constructor
|
||||||
internal XAudioSoundEffect(SoundEffect setParent, Stream stream)
|
internal XAudioSoundEffect(Stream stream)
|
||||||
{
|
{
|
||||||
Parent = setParent;
|
|
||||||
CreateFromStream(stream);
|
CreateFromStream(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal XAudioSoundEffect(SoundEffect setParent, byte[] buffer, int offset, int count, int sampleRate,
|
internal XAudioSoundEffect(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels,
|
||||||
AudioChannels channels, int loopStart, int loopLength)
|
int loopStart, int loopLength)
|
||||||
{
|
{
|
||||||
Parent = setParent;
|
// TODO: the buffer already contains the pcm data to be played!
|
||||||
|
throw new NotImplementedException();
|
||||||
using (var stream = new MemoryStream())
|
|
||||||
{
|
|
||||||
var writer = new BinaryWriter(stream);
|
|
||||||
writer.Write(buffer, offset, count);
|
|
||||||
stream.Position = 0;
|
|
||||||
CreateFromStream(stream);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~XAudioSoundEffect()
|
~XAudioSoundEffect()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using ANX.Framework;
|
using ANX.Framework;
|
||||||
using ANX.Framework.Audio;
|
using ANX.Framework.Audio;
|
||||||
|
using ANX.Framework.NonXNA.Development;
|
||||||
using ANX.Framework.NonXNA.SoundSystem;
|
using ANX.Framework.NonXNA.SoundSystem;
|
||||||
using SharpDX.XAudio2;
|
using SharpDX.XAudio2;
|
||||||
|
|
||||||
@ -10,6 +11,7 @@ using SharpDX.XAudio2;
|
|||||||
|
|
||||||
namespace ANX.SoundSystem.Windows.XAudio
|
namespace ANX.SoundSystem.Windows.XAudio
|
||||||
{
|
{
|
||||||
|
[Developer("AstrorEnales")]
|
||||||
public class XAudioSoundEffectInstance : ISoundEffectInstance
|
public class XAudioSoundEffectInstance : ISoundEffectInstance
|
||||||
{
|
{
|
||||||
#region Private
|
#region Private
|
||||||
|
@ -24,8 +24,8 @@ namespace WaveUtils
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TimeSpan CalculateDuration()
|
public TimeSpan CalculateDuration()
|
||||||
{
|
{
|
||||||
float sizeMulBlockAlign = Data.Length / ((int)Channels * 2);
|
float sizeMulBlockAlign = Data.Length / (Channels * 2f);
|
||||||
return TimeSpan.FromMilliseconds((double)(sizeMulBlockAlign * 1000f / (float)SampleRate));
|
return TimeSpan.FromMilliseconds(sizeMulBlockAlign * 1000f / SampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WaveInfo()
|
public WaveInfo()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user