sound works
This commit is contained in:
108
OpenRa.FileFormats/AudLoader.cs
Normal file
108
OpenRa.FileFormats/AudLoader.cs
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace OpenRa.FileFormats
|
||||||
|
{
|
||||||
|
[Flags]
|
||||||
|
enum SoundFlags
|
||||||
|
{
|
||||||
|
Stereo = 0x1,
|
||||||
|
_16Bit = 0x2,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SoundFormat
|
||||||
|
{
|
||||||
|
WestwoodCompressed = 1,
|
||||||
|
ImaAdpcm = 99,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Chunk
|
||||||
|
{
|
||||||
|
public int CompressedSize;
|
||||||
|
public int OutputSize;
|
||||||
|
|
||||||
|
public static Chunk Read(BinaryReader r)
|
||||||
|
{
|
||||||
|
Chunk c;
|
||||||
|
c.CompressedSize = r.ReadUInt16();
|
||||||
|
c.OutputSize = r.ReadUInt16();
|
||||||
|
if (0xdeaf != r.ReadUInt32())
|
||||||
|
throw new InvalidDataException("Chunk header is bogus");
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AudLoader
|
||||||
|
{
|
||||||
|
static int[] IndexAdjust = { -1, -1, -1, -1, 2, 4, 6, 8 };
|
||||||
|
static int[] StepTable = {
|
||||||
|
7, 8, 9, 10, 11, 12, 13, 14, 16,
|
||||||
|
17, 19, 21, 23, 25, 28, 31, 34, 37,
|
||||||
|
41, 45, 50, 55, 60, 66, 73, 80, 88,
|
||||||
|
97, 107, 118, 130, 143, 157, 173, 190, 209,
|
||||||
|
230, 253, 279, 307, 337, 371, 408, 449, 494,
|
||||||
|
544, 598, 658, 724, 796, 876, 963, 1060, 1166,
|
||||||
|
1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749,
|
||||||
|
3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
|
||||||
|
7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289,
|
||||||
|
16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 };
|
||||||
|
|
||||||
|
static short DecodeSample(byte b, ref int index, ref int current)
|
||||||
|
{
|
||||||
|
var sb = (b & 8) != 0;
|
||||||
|
b &= 7;
|
||||||
|
|
||||||
|
var delta = (StepTable[index] * b) / 4 + StepTable[index] / 8;
|
||||||
|
if (sb) delta = -delta;
|
||||||
|
|
||||||
|
current += delta;
|
||||||
|
if (current > short.MaxValue) current = short.MaxValue;
|
||||||
|
if (current < short.MinValue) current = short.MinValue;
|
||||||
|
|
||||||
|
index += IndexAdjust[b];
|
||||||
|
if (index < 0) index = 0;
|
||||||
|
if (index > 88) index = 88;
|
||||||
|
|
||||||
|
return (short)current;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] LoadSound(Stream s)
|
||||||
|
{
|
||||||
|
var br = new BinaryReader(s);
|
||||||
|
var sampleRate = br.ReadUInt16();
|
||||||
|
var dataSize = br.ReadInt32();
|
||||||
|
var outputSize = br.ReadInt32();
|
||||||
|
var flags = (SoundFlags)br.ReadByte();
|
||||||
|
var format = (SoundFormat)br.ReadByte();
|
||||||
|
|
||||||
|
var output = new byte[outputSize];
|
||||||
|
var offset = 0;
|
||||||
|
var index = 0;
|
||||||
|
var currentSample = 0;
|
||||||
|
|
||||||
|
while (dataSize > 0)
|
||||||
|
{
|
||||||
|
var chunk = Chunk.Read(br);
|
||||||
|
for (int n = 0; n < chunk.CompressedSize; n++)
|
||||||
|
{
|
||||||
|
var b = br.ReadByte();
|
||||||
|
|
||||||
|
var t = DecodeSample(b, ref index, ref currentSample);
|
||||||
|
output[offset++] = (byte)t;
|
||||||
|
output[offset++] = (byte)(t >> 8);
|
||||||
|
|
||||||
|
t = DecodeSample((byte)(b >> 4), ref index, ref currentSample);
|
||||||
|
output[offset++] = (byte)t;
|
||||||
|
output[offset++] = (byte)(t >> 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
dataSize -= 8 + chunk.CompressedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,6 +44,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="AudLoader.cs" />
|
||||||
<Compile Include="Blowfish.cs" />
|
<Compile Include="Blowfish.cs" />
|
||||||
<Compile Include="BlowfishKeyProvider.cs" />
|
<Compile Include="BlowfishKeyProvider.cs" />
|
||||||
<Compile Include="Dune2ShpReader.cs" />
|
<Compile Include="Dune2ShpReader.cs" />
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ using OpenRa.FileFormats;
|
|||||||
using OpenRa.Game.Graphics;
|
using OpenRa.Game.Graphics;
|
||||||
using OpenRa.TechTree;
|
using OpenRa.TechTree;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using IrrKlang;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -24,7 +25,9 @@ namespace OpenRa.Game
|
|||||||
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
|
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
|
||||||
|
|
||||||
public Player LocalPlayer { get { return players[localPlayerIndex]; } }
|
public Player LocalPlayer { get { return players[localPlayerIndex]; } }
|
||||||
public BuildingInfluenceMap LocalPlayerBuildings;
|
public BuildingInfluenceMap LocalPlayerBuildings;
|
||||||
|
|
||||||
|
ISoundEngine soundEngine;
|
||||||
|
|
||||||
public Game(string mapName, Renderer renderer, int2 clientSize)
|
public Game(string mapName, Renderer renderer, int2 clientSize)
|
||||||
{
|
{
|
||||||
@@ -52,7 +55,22 @@ namespace OpenRa.Game
|
|||||||
network = new Network();
|
network = new Network();
|
||||||
|
|
||||||
controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL
|
controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL
|
||||||
worldRenderer = new WorldRenderer(renderer, this);
|
worldRenderer = new WorldRenderer(renderer, this);
|
||||||
|
|
||||||
|
var sound = AudLoader.LoadSound(FileSystem.Open("intro.aud"));
|
||||||
|
|
||||||
|
soundEngine = new ISoundEngine();
|
||||||
|
|
||||||
|
var soundSource = soundEngine.AddSoundSourceFromPCMData(sound, "intro.aud",
|
||||||
|
new AudioFormat()
|
||||||
|
{
|
||||||
|
ChannelCount = 1,
|
||||||
|
FrameCount = sound.Length / 2,
|
||||||
|
Format = SampleFormat.Signed16Bit,
|
||||||
|
SampleRate = 22050
|
||||||
|
});
|
||||||
|
|
||||||
|
soundEngine.Play2D(soundSource, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ namespace OpenRa.Game
|
|||||||
FileSystem.Mount(new Package("redalert.mix"));
|
FileSystem.Mount(new Package("redalert.mix"));
|
||||||
FileSystem.Mount(new Package("conquer.mix"));
|
FileSystem.Mount(new Package("conquer.mix"));
|
||||||
FileSystem.Mount(new Package("hires.mix"));
|
FileSystem.Mount(new Package("hires.mix"));
|
||||||
FileSystem.Mount(new Package("general.mix"));
|
FileSystem.Mount(new Package("general.mix"));
|
||||||
|
FileSystem.Mount(new Package("local.mix"));
|
||||||
|
|
||||||
FormBorderStyle = FormBorderStyle.None;
|
FormBorderStyle = FormBorderStyle.None;
|
||||||
BackColor = Color.Black;
|
BackColor = Color.Black;
|
||||||
|
|||||||
@@ -60,6 +60,10 @@
|
|||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\Ijw.DirectX\Ijw.Framework\IjwFramework\bin\Debug\IjwFramework.dll</HintPath>
|
<HintPath>..\Ijw.DirectX\Ijw.Framework\IjwFramework\bin\Debug\IjwFramework.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="irrKlang.NET2.0, Version=1.1.3.0, Culture=neutral, PublicKeyToken=a854741bd80517c7, processorArchitecture=x86">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\thirdparty\irrKlang.NET2.0.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core">
|
<Reference Include="System.Core">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
|
||||||
{
|
{
|
||||||
var point = new float2(mi.Location.X, mi.Location.Y);
|
var point = mi.Location.ToFloat2();
|
||||||
var item = GetItem(point);
|
var item = GetItem(point);
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
@@ -162,7 +162,7 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
else if( mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down )
|
else if( mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down )
|
||||||
{
|
{
|
||||||
var point = new float2(mi.Location.X, mi.Location.Y);
|
var point = mi.Location.ToFloat2();
|
||||||
var item = GetItem(point);
|
var item = GetItem(point);
|
||||||
if( item != null )
|
if( item != null )
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
thirdparty/irrKlang.NET2.0.dll
vendored
Normal file
BIN
thirdparty/irrKlang.NET2.0.dll
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user