Skip to content

Commit

Permalink
X360: Fix SoundBank variation mishandling, diff between X360 & PC
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ade committed Oct 23, 2017
1 parent ae3223f commit 5113314
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Content/SoundBank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
namespace XnaToFna {
public static partial class ContentHelper {

// Many thanks to Ethan Lee and everyone else involved for his reverse-engineering work that powers this!
// This is heavily based on FNA / FACT.

public enum SoundBankEventType : uint {
Stop = 0,
PlayWave = 1,
Expand Down Expand Up @@ -306,9 +309,10 @@ public static void UpdateSoundBank(string path, BinaryReader reader, BinaryWrite
writer.Write(reader.ReadBytesUntil(cuesComplexPos));
for (ushort i = 0; i < cuesComplex; i++) {
byte flags = reader.ReadByte();
writer.Write(flags);
if ((flags & 0x04) == 0x04)
if ((flags & 0x04) == 0x00) {
variations++;
}
writer.Write(flags);
writer.Write(SwapEndian(x360, reader.ReadUInt32()));
writer.Write(SwapEndian(x360, reader.ReadUInt32()));
writer.Write(reader.ReadByte());
Expand All @@ -318,17 +322,24 @@ public static void UpdateSoundBank(string path, BinaryReader reader, BinaryWrite
}

if (variations != 0) {
// Variation data seems to... vary... between X360 and PC.
writer.Write(reader.ReadBytesUntil(variationsPos));
for (ushort i = 0; i < variations; i++) {
ushort count = SwapEndian(x360, reader.ReadUInt16());
ushort count;
ushort flags;
if (platform == 1) {
count = SwapEndian(x360, reader.ReadUInt16());
flags = SwapEndian(x360, reader.ReadUInt16());
} else {
flags = SwapEndian(x360, reader.ReadUInt16());
count = SwapEndian(x360, reader.ReadUInt16());
}
writer.Write(count);
ushort flags = SwapEndian(x360, reader.ReadUInt16());
writer.Write(flags);
flags = (ushort) ((short) (flags >> 3) & 0x7);
writer.Write(SwapEndian(x360, reader.ReadUInt16()));
writer.Write(SwapEndian(x360, reader.ReadUInt16()));

switch (flags) {
switch ((flags >> 3) & 0x07) {
case 0:
for (ushort ci = 0; ci < count; ci++) {
writer.Write(SwapEndian(x360, reader.ReadUInt16()));
Expand Down
3 changes: 3 additions & 0 deletions src/Content/WaveBank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
namespace XnaToFna {
public static partial class ContentHelper {

// Many thanks to Ethan Lee and everyone else involved for his reverse-engineering work that powers this!
// This is heavily based on FNA / FACT.

public static class XWMAInfo {
public readonly static int[] BytesPerSecond = { 12000, 24000, 4000, 6000, 8000, 20000 };
public readonly static short[] BlockAlign = { 929, 1487, 1280, 2230, 8917, 8192, 4459, 5945, 2304, 1536, 1485, 1008, 2731, 4096, 6827, 5462 };
Expand Down
3 changes: 3 additions & 0 deletions src/Content/XACTGlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
namespace XnaToFna {
public static partial class ContentHelper {

// Many thanks to Ethan Lee and everyone else involved for his reverse-engineering work that powers this!
// This is heavily based on FNA / FACT.

public enum CrossfadeType : byte {
Linear,
Logarithmic,
Expand Down

0 comments on commit 5113314

Please sign in to comment.