- Moved the Wave loading/conversion to an extra project (WaveUtils)
- Started implementation of the Wave Content Pipeline - Fixed GraphicsDeviceWindowsGL3
This commit is contained in:
parent
f0a9bf34fa
commit
67c9efa6cf
@ -21,6 +21,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@ -29,6 +30,7 @@
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
@ -104,6 +106,7 @@
|
||||
<Compile Include="IContentImporter.cs" />
|
||||
<Compile Include="IContentProcessor.cs" />
|
||||
<Compile Include="Importer\TextureImporter.cs" />
|
||||
<Compile Include="Importer\WavImporter.cs" />
|
||||
<Compile Include="InvalidContentException.cs" />
|
||||
<Compile Include="NamedValueDictionary.cs" />
|
||||
<Compile Include="OpaqueDataDictionary.cs" />
|
||||
@ -158,6 +161,7 @@
|
||||
<Compile Include="Serialization\Compiler\MathTypeWriters\RayWriter.cs" />
|
||||
<Compile Include="Serialization\Compiler\MathTypeWriters\PointWriter.cs" />
|
||||
<Compile Include="Serialization\Compiler\MathTypeWriters\MatrixWriter.cs" />
|
||||
<Compile Include="Serialization\Compiler\MediaTypeWriters\SoundEffectWriter.cs" />
|
||||
<Compile Include="Serialization\Compiler\PrimitiveTypeWriters\ByteWriter.cs" />
|
||||
<Compile Include="Serialization\Compiler\PrimitiveTypeWriters\CharWriter.cs" />
|
||||
<Compile Include="Serialization\Compiler\PrimitiveTypeWriters\BooleanWriter.cs" />
|
||||
@ -189,6 +193,10 @@
|
||||
<Project>{EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}</Project>
|
||||
<Name>ANX.RenderSystem.Windows.GL3</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Tools\WaveUtils\WaveUtils.csproj">
|
||||
<Project>{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}</Project>
|
||||
<Name>WaveUtils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
@ -1,11 +1,6 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
#endregion
|
||||
using WaveUtils;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -24,14 +19,32 @@ namespace ANX.Framework.Content.Pipeline.Audio
|
||||
public int LoopLength { get; internal set; }
|
||||
public int LoopStart { get; internal set; }
|
||||
|
||||
internal WaveInfo LoadedWaveData { get; private set; }
|
||||
|
||||
internal AudioContent(WaveInfo setLoadedWaveData)
|
||||
{
|
||||
LoadedWaveData = setLoadedWaveData;
|
||||
}
|
||||
|
||||
public void ConvertFormat(ConversionFormat formatType, ConversionQuality quality, string targetFileName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var converter = new WaveConverter(LoadedWaveData);
|
||||
|
||||
int resultChannelCount = LoadedWaveData.Channels;
|
||||
// Make mono on mobile devices which is totally enough.
|
||||
if (quality == ConversionQuality.Low)
|
||||
resultChannelCount = 1;
|
||||
|
||||
if (formatType == ConversionFormat.Pcm)
|
||||
converter.ConvertToPcm(resultChannelCount);
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
|
||||
Data = new ReadOnlyCollection<byte>(LoadedWaveData.Data);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,22 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
|
||||
#endregion
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// 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.Framework.Content.Pipeline.Audio
|
||||
{
|
||||
public enum ConversionQuality
|
||||
{
|
||||
Low,
|
||||
Medium,
|
||||
Best,
|
||||
}
|
||||
public enum ConversionQuality
|
||||
{
|
||||
/// <summary>
|
||||
/// 96 KBit/s
|
||||
/// </summary>
|
||||
Low,
|
||||
/// <summary>
|
||||
/// 128 KBit/s
|
||||
/// </summary>
|
||||
Medium,
|
||||
/// <summary>
|
||||
/// 192 KBit/s
|
||||
/// </summary>
|
||||
Best,
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,4 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
#endregion
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// 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
|
||||
|
||||
|
@ -1,10 +1,6 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ANX.Framework.Content.Pipeline.Graphics;
|
||||
using System.IO;
|
||||
using ANX.Framework.Content.Pipeline.Graphics;
|
||||
using ANX.Framework.NonXNA;
|
||||
|
||||
#endregion
|
||||
|
28
ANX.Framework.Content.Pipeline/Importer/WavImporter.cs
Normal file
28
ANX.Framework.Content.Pipeline/Importer/WavImporter.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System.IO;
|
||||
using ANX.Framework.Content.Pipeline.Audio;
|
||||
using WaveUtils;
|
||||
|
||||
// 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.Framework.Content.Pipeline.Importer
|
||||
{
|
||||
[ContentImporter(new string[] { ".wav" }, DefaultProcessor = "SoundEffectProcessor")]
|
||||
public class WavImporter : ContentImporter<AudioContent>
|
||||
{
|
||||
public override AudioContent Import(string filename, ContentImporterContext context)
|
||||
{
|
||||
WaveInfo loadedData;
|
||||
using (Stream filestream = File.OpenRead(filename))
|
||||
loadedData = WaveFile.LoadData(filestream);
|
||||
|
||||
return new AudioContent(loadedData)
|
||||
{
|
||||
FileName = filename,
|
||||
Identity = new ContentIdentity(filename, null, null),
|
||||
FileType = AudioFileType.Wav,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,5 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
#endregion
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -13,6 +8,20 @@ using System.Text;
|
||||
namespace ANX.Framework.Content.Pipeline.Processors
|
||||
{
|
||||
public sealed class SoundEffectContent
|
||||
{
|
||||
{
|
||||
internal List<byte> Format { get; private set; }
|
||||
internal List<byte> Data { get; private set; }
|
||||
internal int LoopStart { get; private set; }
|
||||
internal int LoopLength { get; private set; }
|
||||
internal int Duration { get; private set; }
|
||||
|
||||
internal SoundEffectContent(List<byte> setFormat, List<byte> setData, int setLoopStart, int setLoopLength, int setDuration)
|
||||
{
|
||||
Format = setFormat;
|
||||
Data = setData;
|
||||
LoopStart = setLoopStart;
|
||||
LoopLength = setLoopLength;
|
||||
Duration = setDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using ANX.Framework.Content.Pipeline.Audio;
|
||||
|
||||
#endregion
|
||||
using WaveUtils;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -13,18 +11,48 @@ using ANX.Framework.Content.Pipeline.Audio;
|
||||
|
||||
namespace ANX.Framework.Content.Pipeline.Processors
|
||||
{
|
||||
[ContentProcessor]
|
||||
[ContentProcessor(DisplayName = "Sound Effect - ANX Framework")]
|
||||
public class SoundEffectProcessor : ContentProcessor<AudioContent, SoundEffectContent>
|
||||
{
|
||||
public ConversionQuality Quality
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
{
|
||||
private struct WAVEFORMATEX
|
||||
{
|
||||
public ushort wFormatTag;
|
||||
public ushort nChannels;
|
||||
public int nSamplesPerSec;
|
||||
public int nAvgBytesPerSec;
|
||||
public ushort nBlockAlign;
|
||||
public ushort wBitsPerSample;
|
||||
public ushort cbSize;
|
||||
}
|
||||
|
||||
[DefaultValue(ConversionQuality.Medium)]
|
||||
public ConversionQuality Quality { get; set; }
|
||||
|
||||
public override SoundEffectContent Process(AudioContent input, ContentProcessorContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
input.ConvertFormat(ConversionFormat.Pcm, Quality, null);
|
||||
|
||||
var waveHeader = new WAVEFORMATEX()
|
||||
{
|
||||
wFormatTag = (ushort)WaveFormat.PCM,
|
||||
nChannels = (ushort)input.LoadedWaveData.Channels,
|
||||
nSamplesPerSec = input.LoadedWaveData.SampleRate,
|
||||
nAvgBytesPerSec = 0, // TODO
|
||||
nBlockAlign = (ushort)input.LoadedWaveData.BlockAlign,
|
||||
wBitsPerSample = (ushort)input.LoadedWaveData.BitsPerSample,
|
||||
cbSize = 0, // TODO
|
||||
};
|
||||
|
||||
int length = Marshal.SizeOf(waveHeader.GetType());
|
||||
byte[] array = new byte[length];
|
||||
|
||||
IntPtr ptr = Marshal.AllocHGlobal(length);
|
||||
Marshal.StructureToPtr(waveHeader, ptr, true);
|
||||
Marshal.Copy(ptr, array, 0, length);
|
||||
Marshal.FreeHGlobal(ptr);
|
||||
|
||||
return new SoundEffectContent(new List<byte>(array), new List<byte>(input.Data), input.LoopStart, input.LoopLength,
|
||||
(int)input.Duration.TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ANX.Framework.Content.Pipeline.Processors;
|
||||
using System.Reflection;
|
||||
using ANX.Framework.Content.Pipeline.Processors;
|
||||
using ANX.Framework.Graphics;
|
||||
|
||||
#endregion
|
||||
|
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using ANX.Framework.Audio;
|
||||
using ANX.Framework.Content.Pipeline.Processors;
|
||||
|
||||
// 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.Framework.Content.Pipeline.Serialization.Compiler
|
||||
{
|
||||
[ContentTypeWriter]
|
||||
internal class SoundEffectWriter : BuiltinTypeWriter<SoundEffectContent>
|
||||
{
|
||||
protected internal override void Write(ContentWriter output, SoundEffectContent value)
|
||||
{
|
||||
if (output == null)
|
||||
throw new ArgumentNullException("ouput");
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("value");
|
||||
|
||||
output.Write(value.Format.Count);
|
||||
output.Write(value.Format.ToArray());
|
||||
|
||||
output.Write(value.Data.Count);
|
||||
output.Write(value.Data.ToArray());
|
||||
|
||||
output.Write(value.LoopStart);
|
||||
output.Write(value.LoopLength);
|
||||
output.Write(value.Duration);
|
||||
}
|
||||
|
||||
protected internal override bool ShouldCompressContent(TargetPlatform targetPlatform, object value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string GetRuntimeType(TargetPlatform targetPlatform)
|
||||
{
|
||||
return ContentTypeWriter.GetStrongTypeName(typeof(SoundEffect), targetPlatform);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using ANX.Framework.NonXNA.Reflection;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -21,9 +22,10 @@ namespace ANX.Framework.Content.Pipeline.Tasks
|
||||
{
|
||||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (Type type in assembly.GetTypes())
|
||||
|
||||
foreach (Type type in TypeHelper.SafelyExtractTypesFrom(assembly))
|
||||
{
|
||||
ContentImporterAttribute[] value = (ContentImporterAttribute[]) type.GetCustomAttributes(typeof(ContentImporterAttribute), true);
|
||||
ContentImporterAttribute[] value = (ContentImporterAttribute[])type.GetCustomAttributes(typeof(ContentImporterAttribute), true);
|
||||
if (value.Length > 0)
|
||||
{
|
||||
importerTypes[type.Name] = type;
|
||||
|
@ -179,6 +179,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.SoundSystem.PsVita", "S
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AudioSample", "Samples\AudioSample\AudioSample.csproj", "{4A048A8C-C31D-4FC8-AAF3-C387B9E0309B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaveUtils", "Tools\WaveUtils\WaveUtils.csproj", "{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.ContentCompiler.GUI", "Tools\ANXContentCompilerGUI\ANX.ContentCompiler.GUI.csproj", "{45DD7B40-C498-4DD2-A16B-FD6C4E6991B3}"
|
||||
EndProject
|
||||
Global
|
||||
@ -691,6 +693,18 @@ Global
|
||||
{4A048A8C-C31D-4FC8-AAF3-C387B9E0309B}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{4A048A8C-C31D-4FC8-AAF3-C387B9E0309B}.Release|x86.ActiveCfg = Release|x86
|
||||
{4A048A8C-C31D-4FC8-AAF3-C387B9E0309B}.Release|x86.Build.0 = Release|x86
|
||||
<<<<<<< .mine
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
=======
|
||||
{45DD7B40-C498-4DD2-A16B-FD6C4E6991B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{45DD7B40-C498-4DD2-A16B-FD6C4E6991B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{45DD7B40-C498-4DD2-A16B-FD6C4E6991B3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
@ -701,6 +715,7 @@ Global
|
||||
{45DD7B40-C498-4DD2-A16B-FD6C4E6991B3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{45DD7B40-C498-4DD2-A16B-FD6C4E6991B3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{45DD7B40-C498-4DD2-A16B-FD6C4E6991B3}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
>>>>>>> .r17804
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -715,7 +730,11 @@ Global
|
||||
{10F7894D-E8B5-4DCA-BB08-5C99FA792388} = {B24A8593-562A-4A25-BB08-46C163F10F3F}
|
||||
{938D5F88-B888-4B04-BEEE-EE701FBA51EF} = {B24A8593-562A-4A25-BB08-46C163F10F3F}
|
||||
{14B39F89-C9B0-407E-877A-B515C985E96E} = {B24A8593-562A-4A25-BB08-46C163F10F3F}
|
||||
<<<<<<< .mine
|
||||
{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C} = {B24A8593-562A-4A25-BB08-46C163F10F3F}
|
||||
=======
|
||||
{45DD7B40-C498-4DD2-A16B-FD6C4E6991B3} = {B24A8593-562A-4A25-BB08-46C163F10F3F}
|
||||
>>>>>>> .r17804
|
||||
{5BE49183-2F6F-4527-AC90-D816911FCF90} = {D421509A-9AE3-4D7E-881B-EAFED598B028}
|
||||
{EB8258E0-6741-4DB9-B756-1EBDF67B1ED6} = {D421509A-9AE3-4D7E-881B-EAFED598B028}
|
||||
{B30DE9C2-0926-46B6-8351-9AF276C472D5} = {D421509A-9AE3-4D7E-881B-EAFED598B028}
|
||||
|
@ -2,8 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.Framework.NonXNA.SoundSystem;
|
||||
using ANX.Framework.NonXNA.Development;
|
||||
using ANX.Framework.NonXNA.SoundSystem;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -12,6 +12,8 @@ using ANX.Framework.NonXNA.Development;
|
||||
namespace ANX.Framework.Audio
|
||||
{
|
||||
[PercentageComplete(100)]
|
||||
[TestState(TestStateAttribute.TestState.InProgress)]
|
||||
[Developer("AstrorEnales")]
|
||||
public sealed class SoundEffect : IDisposable
|
||||
{
|
||||
#region Static
|
||||
|
@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.Framework.NonXNA.SoundSystem;
|
||||
using ANX.Framework.NonXNA.Development;
|
||||
using ANX.Framework.NonXNA.SoundSystem;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -11,6 +10,8 @@ using ANX.Framework.NonXNA.Development;
|
||||
namespace ANX.Framework.Audio
|
||||
{
|
||||
[PercentageComplete(100)]
|
||||
[TestState(TestStateAttribute.TestState.InProgress)]
|
||||
[Developer("AstrorEnales")]
|
||||
public class SoundEffectInstance : IDisposable
|
||||
{
|
||||
#region Private
|
||||
|
@ -36,7 +36,7 @@ namespace ANX.Framework.Content
|
||||
int loopStart = input.ReadInt32();
|
||||
int loopLength = input.ReadInt32();
|
||||
|
||||
int num = input.ReadInt32();
|
||||
int duration = input.ReadInt32();
|
||||
|
||||
byte[] soundData = null;
|
||||
using (MemoryStream mStream = new MemoryStream(20 + header.Length + 8 + data.Length))
|
||||
|
@ -1,14 +1,7 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.Framework.NonXNA.Development;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.Framework.NonXNA.RenderSystem;
|
||||
|
||||
#endregion
|
||||
|
||||
// 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
|
||||
|
@ -48,4 +48,5 @@ using System.Runtime.InteropServices;
|
||||
[assembly: InternalsVisibleTo("ANX.PlatformSystem.Linux")]
|
||||
[assembly: InternalsVisibleTo("ANX.PlatformSystem.Metro")]
|
||||
[assembly: InternalsVisibleTo("ANX.PlatformSystem.PsVita")]
|
||||
[assembly: InternalsVisibleTo("ANX.Tools.XNBInspector")]
|
||||
[assembly: InternalsVisibleTo("ANX.Tools.XNBInspector")]
|
||||
[assembly: InternalsVisibleTo("ANX.Framework.Content.Pipeline")]
|
@ -14,46 +14,27 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
{
|
||||
/// <summary>
|
||||
/// Native OpenGL Effect implementation.
|
||||
///
|
||||
/// http://wiki.delphigl.com/index.php/Tutorial_glsl
|
||||
/// </summary>
|
||||
public class EffectGL3 : INativeEffect
|
||||
{
|
||||
#region Private
|
||||
/// <summary>
|
||||
/// The managed effect instance of this shader.
|
||||
/// </summary>
|
||||
private Effect managedEffect;
|
||||
|
||||
/// <summary>
|
||||
/// The loaded shader data from the shader file.
|
||||
/// </summary>
|
||||
private ShaderData shaderData;
|
||||
|
||||
/// <summary>
|
||||
/// The available techniques of this shader.
|
||||
/// </summary>
|
||||
private List<EffectParameter> parameters;
|
||||
private List<EffectTechnique> techniques;
|
||||
internal bool IsDisposed;
|
||||
|
||||
/// <summary>
|
||||
/// The current native technique.
|
||||
/// </summary>
|
||||
internal EffectTechniqueGL3 CurrentTechnique
|
||||
{
|
||||
get
|
||||
{
|
||||
if (managedEffect.CurrentTechnique == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return managedEffect.CurrentTechnique.NativeTechnique as EffectTechniqueGL3;
|
||||
}
|
||||
}
|
||||
|
||||
private List<EffectParameter> parameters;
|
||||
|
||||
internal bool IsDisposed;
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
@ -92,7 +73,6 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
/// <summary>
|
||||
/// Private helper constructor for the basic initialization.
|
||||
/// </summary>
|
||||
/// <param name="setManagedEffect"></param>
|
||||
private EffectGL3(Effect setManagedEffect)
|
||||
{
|
||||
GraphicsResourceManager.UpdateResource(this, true);
|
||||
@ -112,8 +92,7 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
/// </summary>
|
||||
/// <param name="vertexShaderByteCode">The vertex shader code.</param>
|
||||
/// <param name="pixelShaderByteCode">The fragment shader code.</param>
|
||||
public EffectGL3(Effect setManagedEffect, Stream vertexShaderByteCode,
|
||||
Stream pixelShaderByteCode)
|
||||
public EffectGL3(Effect setManagedEffect, Stream vertexShaderByteCode, Stream pixelShaderByteCode)
|
||||
: this(setManagedEffect)
|
||||
{
|
||||
// TODO: this is probably not right!
|
||||
@ -153,16 +132,13 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
#region Compile vertex shaders
|
||||
foreach (string vertexName in shaderData.VertexShaderCodes.Keys)
|
||||
{
|
||||
string vertexSource = shaderData.VertexGlobalCode +
|
||||
shaderData.VertexShaderCodes[vertexName];
|
||||
string vertexSource = shaderData.VertexGlobalCode + shaderData.VertexShaderCodes[vertexName];
|
||||
|
||||
int vertexShader = GL.CreateShader(ShaderType.VertexShader);
|
||||
string vertexError = CompileShader(vertexShader, vertexSource);
|
||||
if (String.IsNullOrEmpty(vertexError) == false)
|
||||
{
|
||||
throw new InvalidDataException("Failed to compile the vertex " +
|
||||
"shader '" + vertexName + "' because of: " + vertexError);
|
||||
}
|
||||
throw new InvalidDataException("Failed to compile the vertex shader '" + vertexName + "' cause of: " +
|
||||
vertexError);
|
||||
|
||||
vertexShaders.Add(vertexName, vertexShader);
|
||||
}
|
||||
@ -171,16 +147,13 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
#region Compile fragment shaders
|
||||
foreach (string fragmentName in shaderData.FragmentShaderCodes.Keys)
|
||||
{
|
||||
string fragmentSource = shaderData.FragmentGlobalCode +
|
||||
shaderData.FragmentShaderCodes[fragmentName];
|
||||
string fragmentSource = shaderData.FragmentGlobalCode + shaderData.FragmentShaderCodes[fragmentName];
|
||||
|
||||
int fragmentShader = GL.CreateShader(ShaderType.FragmentShader);
|
||||
string vertexError = CompileShader(fragmentShader, fragmentSource);
|
||||
if (String.IsNullOrEmpty(vertexError) == false)
|
||||
{
|
||||
throw new InvalidDataException("Failed to compile the fragment " +
|
||||
"shader '" + fragmentName + "' because of: " + vertexError);
|
||||
}
|
||||
string fragmentError = CompileShader(fragmentShader, fragmentSource);
|
||||
if (String.IsNullOrEmpty(fragmentError) == false)
|
||||
throw new InvalidDataException("Failed to compile the fragment shader '" + fragmentName + "' cause of: " +
|
||||
fragmentError);
|
||||
|
||||
fragmentShaders.Add(fragmentName, fragmentShader);
|
||||
}
|
||||
@ -210,8 +183,7 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
programName + "' because of: " + programError);
|
||||
}
|
||||
|
||||
EffectTechniqueGL3 technique =
|
||||
new EffectTechniqueGL3(managedEffect, programName, programHandle);
|
||||
EffectTechniqueGL3 technique = new EffectTechniqueGL3(managedEffect, programName, programHandle);
|
||||
techniques.Add(new EffectTechnique(managedEffect, technique));
|
||||
AddParametersFrom(programHandle, parameterNames, technique);
|
||||
}
|
||||
|
@ -90,28 +90,16 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
#endregion
|
||||
|
||||
#region ResetDevice
|
||||
/// <summary>
|
||||
/// Reset the graphics device with the given presentation paramters.
|
||||
/// If a device is currently set, then we dispose the old one.
|
||||
/// </summary>
|
||||
/// <param name="presentationParameters">Parameters for the
|
||||
/// graphics device.</param>
|
||||
private void ResetDevice(PresentationParameters presentationParameters)
|
||||
{
|
||||
#region Validation
|
||||
if (nativeContext != null)
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
#endregion
|
||||
|
||||
// Reset the previous set buffers, effects and targets.
|
||||
boundVertexBuffers = new VertexBufferGL3[0];
|
||||
boundRenderTargets = new RenderTarget2DGL3[0];
|
||||
boundIndexBuffer = null;
|
||||
activeEffect = null;
|
||||
|
||||
// OpenGL Depth Buffer Size: 0/16/24/32
|
||||
int depth = 0;
|
||||
int stencil = 0;
|
||||
switch (presentationParameters.DepthStencilFormat)
|
||||
@ -133,52 +121,28 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
break;
|
||||
}
|
||||
|
||||
graphicsMode = new GraphicsMode(
|
||||
DatatypesMapping.SurfaceToColorFormat(
|
||||
presentationParameters.BackBufferFormat),
|
||||
depth,
|
||||
stencil,
|
||||
// AntiAlias Samples: 2/4/8/16/32
|
||||
presentationParameters.MultiSampleCount);
|
||||
ResizeRenderWindow(presentationParameters);
|
||||
|
||||
CreateWindowInfo(presentationParameters.DeviceWindowHandle,
|
||||
graphicsMode.Index.Value);
|
||||
var colorFormat = DatatypesMapping.SurfaceToColorFormat(presentationParameters.BackBufferFormat);
|
||||
graphicsMode = new GraphicsMode(colorFormat, depth, stencil, presentationParameters.MultiSampleCount);
|
||||
|
||||
GetOpenGLVersion();
|
||||
CreateWindowInfo(presentationParameters.DeviceWindowHandle, graphicsMode.Index.Value);
|
||||
|
||||
//ResizeRenderWindow(presentationParameters);
|
||||
|
||||
nativeContext = new GraphicsContext(graphicsMode, nativeWindowInfo,
|
||||
cachedVersionMajor, cachedVersionMinor, GraphicsContextFlags.Default);
|
||||
nativeContext = new GraphicsContext(graphicsMode, nativeWindowInfo);
|
||||
nativeContext.MakeCurrent(nativeWindowInfo);
|
||||
nativeContext.LoadAll();
|
||||
|
||||
string version = GL.GetString(StringName.Version);
|
||||
string[] parts = version.Split(new char[] { '.', ' ' });
|
||||
cachedVersionMajor = int.Parse(parts[0]);
|
||||
cachedVersionMinor = int.Parse(parts[1]);
|
||||
|
||||
GL.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight);
|
||||
|
||||
GraphicsResourceManager.RecreateAllResources();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetOpenGLVersion
|
||||
private void GetOpenGLVersion()
|
||||
{
|
||||
if (cachedVersionMinor == -1 &&
|
||||
cachedVersionMajor == -1)
|
||||
{
|
||||
GraphicsContext context = new GraphicsContext(
|
||||
graphicsMode, nativeWindowInfo);
|
||||
context.MakeCurrent(nativeWindowInfo);
|
||||
context.LoadAll();
|
||||
|
||||
string version = GL.GetString(StringName.Version);
|
||||
string[] parts = version.Split(new char[] { '.', ' ' });
|
||||
cachedVersionMajor = int.Parse(parts[0]);
|
||||
cachedVersionMinor = int.Parse(parts[1]);
|
||||
|
||||
context.Dispose();
|
||||
context = null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateWindowInfo
|
||||
private void CreateWindowInfo(IntPtr windowHandle, IntPtr graphicsModeHandle)
|
||||
{
|
||||
@ -288,10 +252,10 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
/// </summary>
|
||||
public void Present()
|
||||
{
|
||||
if (nativeContext != null)
|
||||
{
|
||||
nativeContext.SwapBuffers();
|
||||
}
|
||||
if (nativeContext != null)
|
||||
{
|
||||
nativeContext.SwapBuffers();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -375,17 +339,17 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SetConstantBuffer (TODO)
|
||||
#if XNAEXT
|
||||
public void SetConstantBuffer(int slot, ANX.Framework.Graphics.ConstantBuffer constantBuffer)
|
||||
{
|
||||
if (constantBuffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("constantBuffer");
|
||||
}
|
||||
public void SetConstantBuffer(int slot, ConstantBuffer constantBuffer)
|
||||
{
|
||||
if (constantBuffer == null)
|
||||
throw new ArgumentNullException("constantBuffer");
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region SetVertexBuffers
|
||||
public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
|
||||
@ -432,7 +396,7 @@ namespace ANX.RenderSystem.Windows.GL3
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region SetRenderTargets
|
||||
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
|
||||
{
|
||||
|
@ -1,24 +1,28 @@
|
||||
#define USE_GL3
|
||||
|
||||
using System;
|
||||
using ANX.Framework.NonXNA;
|
||||
|
||||
namespace WindowsGame1
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
AddInSystemFactory.Instance.SetPreferredSystem(
|
||||
//AddInType.RenderSystem, "OpenGL3");
|
||||
AddInType.RenderSystem, "DirectX10");
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
#if USE_GL3
|
||||
AddInSystemFactory.Instance.SetPreferredSystem(AddInType.RenderSystem, "OpenGL3");
|
||||
#else
|
||||
AddInSystemFactory.Instance.SetPreferredSystem(AddInType.RenderSystem, "DirectX10");
|
||||
#endif
|
||||
|
||||
using (Game1 game = new Game1())
|
||||
{
|
||||
game.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
using (Game1 game = new Game1())
|
||||
{
|
||||
game.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,18 +70,16 @@
|
||||
<Compile Include="OpenALSoundEffectInstance.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SupportedPlatformsImpl.cs" />
|
||||
<Compile Include="Wave\ALaw.cs" />
|
||||
<Compile Include="Wave\MsAdpcm.cs" />
|
||||
<Compile Include="Wave\MuLaw.cs" />
|
||||
<Compile Include="Wave\WaveFile.cs" />
|
||||
<Compile Include="Wave\WaveFormat.cs" />
|
||||
<Compile Include="Wave\WaveInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\ANX.Framework\ANX.Framework.csproj">
|
||||
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
|
||||
<Name>ANX.Framework</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Tools\WaveUtils\WaveUtils.csproj">
|
||||
<Project>{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}</Project>
|
||||
<Name>WaveUtils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
@ -3,6 +3,8 @@ using System.IO;
|
||||
using ANX.Framework.Audio;
|
||||
using ANX.Framework.NonXNA.SoundSystem;
|
||||
using OpenTK.Audio;
|
||||
using WaveUtils;
|
||||
using ALFormat = OpenTK.Audio.ALFormat;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -14,11 +16,8 @@ namespace ANX.SoundSystem.OpenAL
|
||||
{
|
||||
#region Private
|
||||
internal SoundEffect parent;
|
||||
|
||||
private WaveInfo waveInfo;
|
||||
|
||||
private TimeSpan duration;
|
||||
|
||||
internal int bufferHandle;
|
||||
#endregion
|
||||
|
||||
@ -36,14 +35,7 @@ namespace ANX.SoundSystem.OpenAL
|
||||
internal OpenALSoundEffect(SoundEffect setParent, Stream stream)
|
||||
{
|
||||
parent = setParent;
|
||||
|
||||
waveInfo = WaveFile.LoadData(stream);
|
||||
|
||||
float sizeMulBlockAlign = waveInfo.Data.Length / ((int)waveInfo.Channels * 2);
|
||||
duration = TimeSpan.FromMilliseconds((double)(sizeMulBlockAlign * 1000f / (float)waveInfo.SampleRate));
|
||||
|
||||
bufferHandle = AL.GenBuffer();
|
||||
AL.BufferData(bufferHandle, waveInfo.OpenALFormat, waveInfo.Data, waveInfo.Data.Length, waveInfo.SampleRate);
|
||||
CreateFromStream(stream);
|
||||
}
|
||||
|
||||
internal OpenALSoundEffect(SoundEffect setParent, byte[] buffer, int offset, int count, int sampleRate,
|
||||
@ -51,18 +43,31 @@ namespace ANX.SoundSystem.OpenAL
|
||||
{
|
||||
parent = setParent;
|
||||
|
||||
MemoryStream stream = new MemoryStream();
|
||||
BinaryWriter writer = new BinaryWriter(stream);
|
||||
writer.Write(buffer, offset, count);
|
||||
stream.Position = 0;
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
BinaryWriter writer = new BinaryWriter(stream);
|
||||
writer.Write(buffer, offset, count);
|
||||
stream.Position = 0;
|
||||
|
||||
CreateFromStream(stream);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateFromStream
|
||||
private void CreateFromStream(Stream stream)
|
||||
{
|
||||
waveInfo = WaveFile.LoadData(stream);
|
||||
if (waveInfo.WaveFormat != WaveFormat.PCM)
|
||||
{
|
||||
WaveConverter converter = new WaveConverter(waveInfo);
|
||||
converter.ConvertToPcm();
|
||||
}
|
||||
|
||||
float sizeMulBlockAlign = waveInfo.Data.Length / ((int)waveInfo.Channels * 2);
|
||||
duration = TimeSpan.FromMilliseconds((double)(sizeMulBlockAlign * 1000f / (float)waveInfo.SampleRate));
|
||||
duration = waveInfo.CalculateDuration();
|
||||
|
||||
bufferHandle = AL.GenBuffer();
|
||||
AL.BufferData(bufferHandle, waveInfo.OpenALFormat, waveInfo.Data, waveInfo.Data.Length, waveInfo.SampleRate);
|
||||
AL.BufferData(bufferHandle, (ALFormat)waveInfo.ALFormat, waveInfo.Data, waveInfo.Data.Length, waveInfo.SampleRate);
|
||||
|
||||
ALError error = AL.GetError();
|
||||
if (error != ALError.NoError)
|
||||
|
@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using OpenTK.Audio;
|
||||
|
||||
// This file is part of the ANX.Framework and originally taken from
|
||||
// the AC.AL OpenAL library, released under the MIT License.
|
||||
// For details see: http://acal.codeplex.com/license
|
||||
|
||||
namespace ANX.SoundSystem.OpenAL
|
||||
{
|
||||
public class WaveInfo
|
||||
{
|
||||
public WaveFormat WaveFormat
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public byte[] Data
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public ALFormat OpenALFormat
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public int SampleRate
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public short BitsPerSample
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public short BlockAlign
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public int Channels
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public short ExtSamplesPerBlock
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
}
|
||||
}
|
10
Tools/WaveUtils/ALFormat.cs
Normal file
10
Tools/WaveUtils/ALFormat.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace WaveUtils
|
||||
{
|
||||
public enum ALFormat
|
||||
{
|
||||
Mono8 = 4352,
|
||||
Mono16 = 4353,
|
||||
Stereo8 = 4354,
|
||||
Stereo16 = 4355,
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using OpenTK.Audio;
|
||||
|
||||
// This file is part of the ANX.Framework and originally taken from
|
||||
// the AC.AL OpenAL library, released under the MIT License.
|
||||
// For details see: http://acal.codeplex.com/license
|
||||
|
||||
namespace ANX.SoundSystem.OpenAL
|
||||
namespace WaveUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// http://www.threejacks.com/?q=node/176
|
||||
@ -102,20 +101,24 @@ namespace ANX.SoundSystem.OpenAL
|
||||
#endregion
|
||||
|
||||
#region ConvertToPcm
|
||||
public static void ConvertToPcm(WaveInfo info)
|
||||
public static void ConvertToPcm(WaveInfo info, int resultChannelCount)
|
||||
{
|
||||
info.OpenALFormat = info.Channels == 1 ?
|
||||
ALFormat.Mono16 :
|
||||
ALFormat.Stereo16;
|
||||
MemoryStream destStream = new MemoryStream();
|
||||
BinaryWriter destWriter = new BinaryWriter(destStream);
|
||||
for (int index = 0; index < info.Data.Length; index++)
|
||||
using (MemoryStream destStream = new MemoryStream())
|
||||
{
|
||||
destWriter.Write(DecodeTable[info.Data[index]]);
|
||||
BinaryWriter destWriter = new BinaryWriter(destStream);
|
||||
|
||||
int increment = 1;
|
||||
if (info.Channels == 2 && resultChannelCount == 1)
|
||||
increment = 2;
|
||||
|
||||
info.Channels = resultChannelCount;
|
||||
info.ALFormat = info.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16;
|
||||
|
||||
for (int index = 0; index < info.Data.Length; index += increment)
|
||||
destWriter.Write(DecodeTable[info.Data[index]]);
|
||||
|
||||
info.Data = destStream.ToArray();
|
||||
}
|
||||
destWriter.Close();
|
||||
info.Data = destStream.ToArray();
|
||||
destStream.Dispose();
|
||||
}
|
||||
#endregion
|
||||
}
|
40
Tools/WaveUtils/IEEEFloat.cs
Normal file
40
Tools/WaveUtils/IEEEFloat.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
// This file is part of the ANX.Framework and originally taken from
|
||||
// the AC.AL OpenAL library, released under the MIT License.
|
||||
// For details see: http://acal.codeplex.com/license
|
||||
|
||||
namespace WaveUtils
|
||||
{
|
||||
public static class IEEEFloat
|
||||
{
|
||||
public static void ConvertToPcm(WaveInfo data, int resultChannelCount)
|
||||
{
|
||||
bool is64BitFloat = data.BitsPerSample == 64;
|
||||
|
||||
using (BinaryReader sourceReader = new BinaryReader(new MemoryStream(data.Data)))
|
||||
{
|
||||
MemoryStream destStream = new MemoryStream();
|
||||
BinaryWriter destWriter = new BinaryWriter(destStream);
|
||||
|
||||
int length = data.Data.Length / (is64BitFloat ? 8 : 4);
|
||||
|
||||
int increment = 1;
|
||||
if (data.Channels == 2 && resultChannelCount == 1)
|
||||
increment = 2;
|
||||
|
||||
data.Channels = resultChannelCount;
|
||||
data.ALFormat = data.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16;
|
||||
|
||||
for (int index = 0; index < length; index += increment)
|
||||
{
|
||||
double value = is64BitFloat ? sourceReader.ReadDouble() : sourceReader.ReadSingle();
|
||||
destWriter.Write((short)(value * 32767));
|
||||
}
|
||||
|
||||
data.Data = destStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ using System.IO;
|
||||
// the AC.AL OpenAL library, released under the MIT License.
|
||||
// For details see: http://acal.codeplex.com/license
|
||||
|
||||
namespace ANX.SoundSystem.OpenAL
|
||||
namespace WaveUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// http://wiki.multimedia.cx/index.php?title=Microsoft_ADPCM
|
@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using OpenTK.Audio;
|
||||
|
||||
// This file is part of the ANX.Framework and originally taken from
|
||||
// the AC.AL OpenAL library, released under the MIT License.
|
||||
// For details see: http://acal.codeplex.com/license
|
||||
|
||||
namespace ANX.SoundSystem.OpenAL
|
||||
namespace WaveUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// http://www.threejacks.com/?q=node/176
|
||||
@ -91,20 +90,24 @@ namespace ANX.SoundSystem.OpenAL
|
||||
#endregion
|
||||
|
||||
#region ConvertToPcm
|
||||
public static void ConvertToPcm(WaveInfo info)
|
||||
public static void ConvertToPcm(WaveInfo info, int resultChannelCount)
|
||||
{
|
||||
info.OpenALFormat = info.Channels == 1 ?
|
||||
ALFormat.Mono16 :
|
||||
ALFormat.Stereo16;
|
||||
MemoryStream destStream = new MemoryStream();
|
||||
BinaryWriter destWriter = new BinaryWriter(destStream);
|
||||
for (int index = 0; index < info.Data.Length; index++)
|
||||
using (MemoryStream destStream = new MemoryStream())
|
||||
{
|
||||
destWriter.Write(DecodeTable[info.Data[index]]);
|
||||
BinaryWriter destWriter = new BinaryWriter(destStream);
|
||||
|
||||
int increment = 1;
|
||||
if (info.Channels == 2 && resultChannelCount == 1)
|
||||
increment = 2;
|
||||
|
||||
info.Channels = resultChannelCount;
|
||||
info.ALFormat = info.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16;
|
||||
|
||||
for (int index = 0; index < info.Data.Length; index += increment)
|
||||
destWriter.Write(DecodeTable[info.Data[index]]);
|
||||
|
||||
info.Data = destStream.ToArray();
|
||||
}
|
||||
destWriter.Close();
|
||||
info.Data = destStream.ToArray();
|
||||
destStream.Dispose();
|
||||
}
|
||||
#endregion
|
||||
}
|
36
Tools/WaveUtils/Properties/AssemblyInfo.cs
Normal file
36
Tools/WaveUtils/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
[assembly: AssemblyTitle("WaveUtils")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("ANX.Framework Team")]
|
||||
[assembly: AssemblyProduct("WaveUtils")]
|
||||
[assembly: AssemblyCopyright("Copyright © ANX.Framework Team 2012")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("fae37998-9305-495a-a72f-005a3ab28746")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
50
Tools/WaveUtils/WaveConverter.cs
Normal file
50
Tools/WaveUtils/WaveConverter.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
// This file is part of the ANX.Framework and originally taken from
|
||||
// the AC.AL OpenAL library, released under the MIT License.
|
||||
// For details see: http://acal.codeplex.com/license
|
||||
|
||||
namespace WaveUtils
|
||||
{
|
||||
public class WaveConverter
|
||||
{
|
||||
private WaveInfo loadedData;
|
||||
|
||||
public WaveConverter(WaveInfo setLoadedData)
|
||||
{
|
||||
setLoadedData = loadedData;
|
||||
}
|
||||
|
||||
public void ConvertToPcm()
|
||||
{
|
||||
ConvertToPcm(loadedData.Channels);
|
||||
}
|
||||
|
||||
public void ConvertToPcm(int resultChannelCount)
|
||||
{
|
||||
switch (loadedData.WaveFormat)
|
||||
{
|
||||
case WaveFormat.ALAW:
|
||||
ALaw.ConvertToPcm(loadedData, resultChannelCount);
|
||||
break;
|
||||
|
||||
case WaveFormat.MULAW:
|
||||
MuLaw.ConvertToPcm(loadedData, resultChannelCount);
|
||||
break;
|
||||
|
||||
case WaveFormat.IEEE_FLOAT:
|
||||
IEEEFloat.ConvertToPcm(loadedData, resultChannelCount);
|
||||
break;
|
||||
|
||||
case WaveFormat.MS_ADPCM:
|
||||
MsAdpcm.ConvertToPcm(loadedData);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException("The WAVE format " + loadedData.WaveFormat +
|
||||
" is not supported yet. Unable to load!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ANX.Framework.NonXNA;
|
||||
using OpenTK.Audio;
|
||||
|
||||
// This file is part of the ANX.Framework and originally taken from
|
||||
// the AC.AL OpenAL library, released under the MIT License.
|
||||
// For details see: http://acal.codeplex.com/license
|
||||
|
||||
namespace ANX.SoundSystem.OpenAL
|
||||
namespace WaveUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains all the loading process of a wave file.
|
||||
@ -28,11 +28,7 @@ namespace ANX.SoundSystem.OpenAL
|
||||
public static class WaveFile
|
||||
{
|
||||
#region LoadData
|
||||
/// <summary>
|
||||
/// Load all information from a wave file.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream containing the wave file data.</param>
|
||||
public static WaveInfo LoadData(Stream stream)
|
||||
public static WaveInfo LoadData(Stream stream, bool rememberUnloadedChunks = false)
|
||||
{
|
||||
WaveInfo result = new WaveInfo();
|
||||
|
||||
@ -85,7 +81,7 @@ namespace ANX.SoundSystem.OpenAL
|
||||
}
|
||||
}
|
||||
|
||||
result.OpenALFormat = (result.Channels == 1 ?
|
||||
result.ALFormat = (result.Channels == 1 ?
|
||||
(result.BitsPerSample == 8 ?
|
||||
ALFormat.Mono8 :
|
||||
ALFormat.Mono16) :
|
||||
@ -109,6 +105,14 @@ namespace ANX.SoundSystem.OpenAL
|
||||
case "data":
|
||||
result.Data = reader.ReadBytes(chunkLength);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (rememberUnloadedChunks)
|
||||
{
|
||||
var value = new KeyValuePair<string, byte[]>(identifier, reader.ReadBytes(chunkLength));
|
||||
result.UnloadedChunks.Add(value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// If some chunks are incorrect in data length, we ensure that we
|
||||
@ -129,8 +133,6 @@ namespace ANX.SoundSystem.OpenAL
|
||||
return null;
|
||||
}
|
||||
|
||||
ConvertFormat(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
@ -156,80 +158,5 @@ namespace ANX.SoundSystem.OpenAL
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ConvertFormat
|
||||
private static void ConvertFormat(WaveInfo info)
|
||||
{
|
||||
switch (info.WaveFormat)
|
||||
{
|
||||
case WaveFormat.PCM:
|
||||
#region Convert 32 to 16 bps (TODO)
|
||||
//if (info.BitsPerSample == 32)
|
||||
//{
|
||||
// BinaryReader sourceReader =
|
||||
// new BinaryReader(new MemoryStream(info.Data));
|
||||
// MemoryStream destStream = new MemoryStream();
|
||||
// BinaryWriter destWriter = new BinaryWriter(destStream);
|
||||
|
||||
// int length = info.Data.Length / 4;
|
||||
// for (int index = 0; index < length; index++)
|
||||
// {
|
||||
// int value = sourceReader.ReadInt32();
|
||||
// destWriter.Write((short)(value / 2));
|
||||
// }
|
||||
// sourceReader.Close();
|
||||
// destWriter.Close();
|
||||
// info.Data = destStream.ToArray();
|
||||
// destStream.Dispose();
|
||||
//}
|
||||
#endregion
|
||||
break;
|
||||
|
||||
case WaveFormat.ALAW:
|
||||
ALaw.ConvertToPcm(info);
|
||||
break;
|
||||
|
||||
case WaveFormat.MULAW:
|
||||
MuLaw.ConvertToPcm(info);
|
||||
break;
|
||||
|
||||
case WaveFormat.IEEE_FLOAT:
|
||||
{
|
||||
#region Convert float to pcm
|
||||
bool is64BitFloat = info.BitsPerSample == 64;
|
||||
|
||||
BinaryReader sourceReader =
|
||||
new BinaryReader(new MemoryStream(info.Data));
|
||||
MemoryStream destStream = new MemoryStream();
|
||||
BinaryWriter destWriter = new BinaryWriter(destStream);
|
||||
|
||||
int length = info.Data.Length / (is64BitFloat ? 8 : 4);
|
||||
for (int index = 0; index < length; index++)
|
||||
{
|
||||
double value = is64BitFloat ?
|
||||
sourceReader.ReadDouble() :
|
||||
sourceReader.ReadSingle();
|
||||
|
||||
destWriter.Write((short)(value * 32767));
|
||||
}
|
||||
|
||||
sourceReader.Close();
|
||||
destWriter.Close();
|
||||
info.Data = destStream.ToArray();
|
||||
destStream.Dispose();
|
||||
#endregion
|
||||
}
|
||||
break;
|
||||
|
||||
case WaveFormat.MS_ADPCM:
|
||||
MsAdpcm.ConvertToPcm(info);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException("The WAVE format " +
|
||||
info.WaveFormat + " is not supported yet. Unable to load!");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
// the AC.AL OpenAL library, released under the MIT License.
|
||||
// For details see: http://acal.codeplex.com/license
|
||||
|
||||
namespace ANX.SoundSystem.OpenAL
|
||||
namespace WaveUtils
|
||||
{
|
||||
public enum WaveFormat
|
||||
{
|
36
Tools/WaveUtils/WaveInfo.cs
Normal file
36
Tools/WaveUtils/WaveInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// This file is part of the ANX.Framework and originally taken from
|
||||
// the AC.AL OpenAL library, released under the MIT License.
|
||||
// For details see: http://acal.codeplex.com/license
|
||||
|
||||
namespace WaveUtils
|
||||
{
|
||||
public class WaveInfo
|
||||
{
|
||||
public List<KeyValuePair<string, byte[]>> UnloadedChunks { get; internal set; }
|
||||
public WaveFormat WaveFormat { get; internal set; }
|
||||
public byte[] Data { get; internal set; }
|
||||
public ALFormat ALFormat { get; internal set; }
|
||||
public int SampleRate { get; internal set; }
|
||||
public short BitsPerSample { get; internal set; }
|
||||
public short BlockAlign { get; internal set; }
|
||||
public int Channels { get; internal set; }
|
||||
public short ExtSamplesPerBlock { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// NOTE: This only works with standard PCM data!
|
||||
/// </summary>
|
||||
public TimeSpan CalculateDuration()
|
||||
{
|
||||
float sizeMulBlockAlign = Data.Length / ((int)Channels * 2);
|
||||
return TimeSpan.FromMilliseconds((double)(sizeMulBlockAlign * 1000f / (float)SampleRate));
|
||||
}
|
||||
|
||||
public WaveInfo()
|
||||
{
|
||||
UnloadedChunks = new List<KeyValuePair<string, byte[]>>();
|
||||
}
|
||||
}
|
||||
}
|
65
Tools/WaveUtils/WaveUtils.csproj
Normal file
65
Tools/WaveUtils/WaveUtils.csproj
Normal file
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{1986B0ED-3D28-4FEE-82D0-BCC39C87C18C}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WaveUtils</RootNamespace>
|
||||
<AssemblyName>WaveUtils</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ALaw.cs" />
|
||||
<Compile Include="ALFormat.cs" />
|
||||
<Compile Include="IEEEFloat.cs" />
|
||||
<Compile Include="MsAdpcm.cs" />
|
||||
<Compile Include="MuLaw.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WaveConverter.cs" />
|
||||
<Compile Include="WaveFile.cs" />
|
||||
<Compile Include="WaveFormat.cs" />
|
||||
<Compile Include="WaveInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\ANX.Framework\ANX.Framework.csproj">
|
||||
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
|
||||
<Name>ANX.Framework</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\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>
|
||||
-->
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user