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