SND\AstrorEnales_cp 0fc4409e58 - Fixed the Texture2DReader to correctly fill the texture with the mipmaps
- Implemented Mipmap textures for Dx10, Dx11, GL3. Metro is implemented but has still some problems with mipmaps (probably cause of the vm)
- Added Sample dds texture
- Fixed compiler error in MetroGameTimer
2012-09-08 09:07:23 +00:00

91 lines
2.1 KiB
C#

using System;
using System.IO;
using ANX.Framework.Audio;
using ANX.Framework.NonXNA.SoundSystem;
using SharpDX.XAudio2;
using SharpDX.Multimedia;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.SoundSystem.Windows.XAudio
{
public class XAudioSoundEffect : ISoundEffect
{
#region Private
internal SoundEffect parent;
private TimeSpan duration;
internal WaveFormat waveFormat;
internal AudioBuffer audioBuffer;
internal uint[] DecodedPacketsInfo;
#endregion
#region Public
public TimeSpan Duration
{
get
{
return duration;
}
}
#endregion
#region Constructor
internal XAudioSoundEffect(SoundEffect setParent, Stream stream)
{
parent = setParent;
CreateFromStream(stream);
}
internal XAudioSoundEffect(SoundEffect setParent, byte[] buffer, int offset, int count, int sampleRate,
AudioChannels channels, int loopStart, int loopLength)
{
parent = setParent;
using (MemoryStream stream = new MemoryStream())
{
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(buffer, offset, count);
stream.Position = 0;
CreateFromStream(stream);
}
}
~XAudioSoundEffect()
{
Dispose();
}
#endregion
#region CreateFromStream
private void CreateFromStream(Stream stream)
{
var soundStream = new SoundStream(stream);
waveFormat = soundStream.Format;
audioBuffer = new AudioBuffer
{
Stream = soundStream.ToDataStream(),
AudioBytes = (int)stream.Length,
Flags = BufferFlags.EndOfStream
};
float sizeMulBlockAlign = soundStream.Length / (waveFormat.Channels * 2);
duration = TimeSpan.FromMilliseconds((double)(sizeMulBlockAlign * 1000f / (float)waveFormat.SampleRate));
DecodedPacketsInfo = soundStream.DecodedPacketsInfo;
soundStream.Dispose();
}
#endregion
#region Dispose
public void Dispose()
{
waveFormat = null;
audioBuffer = null;
}
#endregion
}
}