Permalink
Browse files

Changes to allow AudioEngine, SoundBank and WaveBank to at least load…

… under Android.
  • Loading branch information...
CartBlanche authored and KonajuGames committed Oct 30, 2012
1 parent 52d5e16 commit a9be18b67e331ff3b9b63869db25cb31b517b090
Showing with 240 additions and 208 deletions.
  1. +83 −72 MonoGame.Framework/Audio/AudioEngine.cs
  2. +143 −134 MonoGame.Framework/Audio/SoundBank.cs
  3. +14 −2 MonoGame.Framework/Audio/WaveBank.cs
@@ -42,6 +42,8 @@ 1. Definitions
using System.IO;
using System.Collections.Generic;
+using Microsoft.Xna.Framework;
+
namespace Microsoft.Xna.Framework.Audio
{
public class AudioEngine : IDisposable
@@ -107,99 +109,108 @@ public AudioEngine (string settingsFile, TimeSpan lookAheadTime, string renderer
{
//Read the xact settings file
//Credits to alisci01 for initial format documentation
+#if !ANDROID
using (var stream = File.OpenRead (settingsFile))
- using (var reader = new BinaryReader(stream)) {
- uint magic = reader.ReadUInt32 ();
- if (magic != 0x46534758) { //'XGFS'
- throw new ArgumentException ("XGS format not recognized");
- }
+ {
+#else
+ using (var fileStream = Game.Activity.Assets.Open(settingsFile))
+ {
+ MemoryStream stream = new MemoryStream();
+ fileStream.CopyTo(stream);
+ stream.Position = 0;
+#endif
+ using (var reader = new BinaryReader(stream)) {
+ uint magic = reader.ReadUInt32 ();
+ if (magic != 0x46534758) { //'XGFS'
+ throw new ArgumentException ("XGS format not recognized");
+ }
- uint toolVersion = reader.ReadUInt16 ();
- uint formatVersion = reader.ReadUInt16 ();
+ uint toolVersion = reader.ReadUInt16 ();
+ uint formatVersion = reader.ReadUInt16 ();
#if DEBUG
- if (formatVersion != 42) {
- Console.WriteLine ("Warning: XGS format not supported");
- }
+ if (formatVersion != 42) {
+ Console.WriteLine ("Warning: XGS format not supported");
+ }
#endif
- uint crc = reader.ReadUInt16 (); //??
-
- uint lastModifiedLow = reader.ReadUInt32 ();
- uint lastModifiedHigh = reader.ReadUInt32 ();
+ uint crc = reader.ReadUInt16 (); //??
- reader.ReadByte (); //unkn, 0x03. Platform?
+ uint lastModifiedLow = reader.ReadUInt32 ();
+ uint lastModifiedHigh = reader.ReadUInt32 ();
- uint numCats = reader.ReadUInt16 ();
- uint numVars = reader.ReadUInt16 ();
+ reader.ReadByte (); //unkn, 0x03. Platform?
- reader.ReadUInt16 (); //unkn, 0x16
- reader.ReadUInt16 (); //unkn, 0x16
+ uint numCats = reader.ReadUInt16 ();
+ uint numVars = reader.ReadUInt16 ();
- uint numRpc = reader.ReadUInt16 ();
- uint numDspPresets = reader.ReadUInt16 ();
- uint numDspParams = reader.ReadUInt16 ();
+ reader.ReadUInt16 (); //unkn, 0x16
+ reader.ReadUInt16 (); //unkn, 0x16
- uint catsOffset = reader.ReadUInt32 ();
- uint varsOffset = reader.ReadUInt32 ();
+ uint numRpc = reader.ReadUInt16 ();
+ uint numDspPresets = reader.ReadUInt16 ();
+ uint numDspParams = reader.ReadUInt16 ();
- reader.ReadUInt32 (); //unknown, leads to a short with value of 1?
- uint catNameIndexOffset = reader.ReadUInt32 ();
- reader.ReadUInt32 (); //unknown, two shorts of values 2 and 3?
- uint varNameIndexOffset = reader.ReadUInt32 ();
+ uint catsOffset = reader.ReadUInt32 ();
+ uint varsOffset = reader.ReadUInt32 ();
- uint catNamesOffset = reader.ReadUInt32 ();
- uint varNamesOffset = reader.ReadUInt32 ();
- uint rpcOffset = reader.ReadUInt32 ();
- uint dspPresetsOffset = reader.ReadUInt32 ();
- uint dspParamsOffset = reader.ReadUInt32 ();
+ reader.ReadUInt32 (); //unknown, leads to a short with value of 1?
+ uint catNameIndexOffset = reader.ReadUInt32 ();
+ reader.ReadUInt32 (); //unknown, two shorts of values 2 and 3?
+ uint varNameIndexOffset = reader.ReadUInt32 ();
- reader.BaseStream.Seek (catNamesOffset, SeekOrigin.Begin);
- string[] categoryNames = readNullTerminatedStrings (numCats, reader);
+ uint catNamesOffset = reader.ReadUInt32 ();
+ uint varNamesOffset = reader.ReadUInt32 ();
+ uint rpcOffset = reader.ReadUInt32 ();
+ uint dspPresetsOffset = reader.ReadUInt32 ();
+ uint dspParamsOffset = reader.ReadUInt32 ();
+ reader.BaseStream.Seek (catNamesOffset, SeekOrigin.Begin);
+ string[] categoryNames = readNullTerminatedStrings (numCats, reader);
- categories = new AudioCategory[numCats];
- reader.BaseStream.Seek (catsOffset, SeekOrigin.Begin);
- for (int i=0; i<numCats; i++) {
- categories [i] = new AudioCategory (this, categoryNames [i], reader);
- categoryLookup.Add (categoryNames [i], i);
- }
+ categories = new AudioCategory[numCats];
+ reader.BaseStream.Seek (catsOffset, SeekOrigin.Begin);
+ for (int i=0; i<numCats; i++) {
+ categories [i] = new AudioCategory (this, categoryNames [i], reader);
+ categoryLookup.Add (categoryNames [i], i);
+ }
- reader.BaseStream.Seek (varNamesOffset, SeekOrigin.Begin);
- string[] varNames = readNullTerminatedStrings (numVars, reader);
+ reader.BaseStream.Seek (varNamesOffset, SeekOrigin.Begin);
+ string[] varNames = readNullTerminatedStrings (numVars, reader);
- variables = new Variable[numVars];
- reader.BaseStream.Seek (varsOffset, SeekOrigin.Begin);
- for (int i=0; i<numVars; i++) {
- variables [i].name = varNames [i];
+ variables = new Variable[numVars];
+ reader.BaseStream.Seek (varsOffset, SeekOrigin.Begin);
+ for (int i=0; i<numVars; i++) {
+ variables [i].name = varNames [i];
- byte flags = reader.ReadByte ();
- variables [i].isPublic = (flags & 0x1) != 0;
- variables [i].isReadOnly = (flags & 0x2) != 0;
- variables [i].isGlobal = (flags & 0x4) == 0;
- variables [i].isReserved = (flags & 0x8) != 0;
-
- variables [i].initValue = reader.ReadSingle ();
- variables [i].minValue = reader.ReadSingle ();
- variables [i].maxValue = reader.ReadSingle ();
+ byte flags = reader.ReadByte ();
+ variables [i].isPublic = (flags & 0x1) != 0;
+ variables [i].isReadOnly = (flags & 0x2) != 0;
+ variables [i].isGlobal = (flags & 0x4) == 0;
+ variables [i].isReserved = (flags & 0x8) != 0;
+
+ variables [i].initValue = reader.ReadSingle ();
+ variables [i].minValue = reader.ReadSingle ();
+ variables [i].maxValue = reader.ReadSingle ();
- variables [i].value = variables [i].initValue;
+ variables [i].value = variables [i].initValue;
- variableLookup.Add (varNames [i], i);
- }
+ variableLookup.Add (varNames [i], i);
+ }
- rpcCurves = new RpcCurve[numRpc];
- reader.BaseStream.Seek (rpcOffset, SeekOrigin.Begin);
- for (int i=0; i<numRpc; i++) {
- rpcCurves [i].variable = reader.ReadUInt16 ();
- int pointCount = (int)reader.ReadByte ();
- rpcCurves [i].parameter = (RpcParameter)reader.ReadUInt16 ();
-
- rpcCurves [i].points = new RpcPoint[pointCount];
- for (int j=0; j<pointCount; j++) {
- rpcCurves [i].points [j].x = reader.ReadSingle ();
- rpcCurves [i].points [j].y = reader.ReadSingle ();
- rpcCurves [i].points [j].type = (RpcPointType)reader.ReadByte ();
+ rpcCurves = new RpcCurve[numRpc];
+ reader.BaseStream.Seek (rpcOffset, SeekOrigin.Begin);
+ for (int i=0; i<numRpc; i++) {
+ rpcCurves [i].variable = reader.ReadUInt16 ();
+ int pointCount = (int)reader.ReadByte ();
+ rpcCurves [i].parameter = (RpcParameter)reader.ReadUInt16 ();
+
+ rpcCurves [i].points = new RpcPoint[pointCount];
+ for (int j=0; j<pointCount; j++) {
+ rpcCurves [i].points [j].x = reader.ReadSingle ();
+ rpcCurves [i].points [j].y = reader.ReadSingle ();
+ rpcCurves [i].points [j].type = (RpcPointType)reader.ReadByte ();
+ }
}
- }
+ }
}
}
Oops, something went wrong.

0 comments on commit a9be18b

Please sign in to comment.