From ec9da154ad70001fe76640c697a38840ca49c623 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 11 Aug 2010 22:04:55 +1200 Subject: [PATCH] add crap broken sound support for vqa --- OpenRA.FileFormats/FileFormats/AudLoader.cs | 27 +++++++++++++++++++++ OpenRA.FileFormats/Graphics/VqaReader.cs | 18 +++++++++----- OpenRA.Game/Sound.cs | 11 +++++++++ OpenRA.Game/Widgets/VqaPlayerWidget.cs | 4 ++- mods/ra/chrome/mainmenu.yaml | 12 ++++----- 5 files changed, 59 insertions(+), 13 deletions(-) diff --git a/OpenRA.FileFormats/FileFormats/AudLoader.cs b/OpenRA.FileFormats/FileFormats/AudLoader.cs index bb0ced6e84..bf9a06410b 100644 --- a/OpenRA.FileFormats/FileFormats/AudLoader.cs +++ b/OpenRA.FileFormats/FileFormats/AudLoader.cs @@ -76,6 +76,33 @@ namespace OpenRA.FileFormats return (short)current; } + public static byte[] LoadSound(byte[] raw) + { + var br = new BinaryReader(new MemoryStream(raw)); + var dataSize = raw.Length; + var outputSize = raw.Length * 4; + + var output = new byte[outputSize]; + var offset = 0; + var index = 0; + var currentSample = 0; + + while (dataSize-- > 0) + { + 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); + } + + return output; + } + public static byte[] LoadSound(Stream s) { var br = new BinaryReader(s); diff --git a/OpenRA.FileFormats/Graphics/VqaReader.cs b/OpenRA.FileFormats/Graphics/VqaReader.cs index 3a66514b41..a38f140f89 100644 --- a/OpenRA.FileFormats/Graphics/VqaReader.cs +++ b/OpenRA.FileFormats/Graphics/VqaReader.cs @@ -45,7 +45,10 @@ namespace OpenRA.FileFormats byte[] origData; // Final frame output - int[,] frameData; + int[,] frameData; + byte[] audioData; // audio for this frame: 22050Hz 16bit mono pcm, uncompressed. + + public byte[] AudioData { get { return audioData; } } public VqaReader( Stream stream ) { @@ -124,11 +127,14 @@ namespace OpenRA.FileFormats var length = Swap(reader.ReadUInt32()); switch(type) - { - case "SND2": - // Don't parse sound (yet); skip data - reader.ReadBytes((int)length); - break; + { + case "SND2": + // Don't parse sound (yet); skip data + { + var rawAudio = reader.ReadBytes((int)length); + audioData = AudLoader.LoadSound(rawAudio); + } + break; case "VQFR": DecodeVQFR(reader); break; diff --git a/OpenRA.Game/Sound.cs b/OpenRA.Game/Sound.cs index c139cf0553..d113c17bb8 100644 --- a/OpenRA.Game/Sound.cs +++ b/OpenRA.Game/Sound.cs @@ -32,6 +32,11 @@ namespace OpenRA return soundEngine.AddSoundSourceFromMemory(data, 1, 16, 22050); } + static ISoundSource LoadSoundRaw(byte[] rawData) + { + return soundEngine.AddSoundSourceFromMemory(rawData, 1, 16, 22050); + } + public static void Initialize() { soundEngine = new OpenAlSoundEngine(); @@ -43,6 +48,12 @@ namespace OpenRA public static void SetListenerPosition(float2 position) { soundEngine.SetListenerPosition(position); } + public static void PlayRaw(byte[] raw) + { + var sound = LoadSoundRaw(raw); + soundEngine.Play2D(sound, false, true, float2.Zero, SoundVolume); + } + public static void Play(string name) { if (name == "" || name == null) diff --git a/OpenRA.Game/Widgets/VqaPlayerWidget.cs b/OpenRA.Game/Widgets/VqaPlayerWidget.cs index 8a6228622b..932e307625 100644 --- a/OpenRA.Game/Widgets/VqaPlayerWidget.cs +++ b/OpenRA.Game/Widgets/VqaPlayerWidget.cs @@ -47,7 +47,9 @@ namespace OpenRA.Widgets if (advanceNext) { advanceNext = false; - video.AdvanceFrame(); + video.AdvanceFrame(); + + Sound.PlayRaw(video.AudioData); } if (dt > timestep) diff --git a/mods/ra/chrome/mainmenu.yaml b/mods/ra/chrome/mainmenu.yaml index 122726398d..ed6ebb71ca 100644 --- a/mods/ra/chrome/mainmenu.yaml +++ b/mods/ra/chrome/mainmenu.yaml @@ -1,9 +1,9 @@ -#VqaPlayer: -# X:WINDOW_RIGHT - 400 -# Y:WINDOW_BOTTOM - 200 -# Width:200 -# Height:200 -# Video:aagun.vqa +VqaPlayer: + X:WINDOW_RIGHT - 400 + Y:WINDOW_BOTTOM - 200 + Width:200 + Height:200 + Video:aagun.vqa Background@MAINMENU_BG: Id:MAINMENU_BG X:(WINDOW_RIGHT - WIDTH)/2