public EventInstance(XACTEvent evt) { Event = evt; Timestamp = ( Event.Timestamp + XACTEvent.Random.Next(0, Event.RandomOffset) ); LoopCount = Event.LoopCount; Played = false; }
public XACTClip(BinaryReader reader, double clipVolume) { // Number of XACT Events Events = new XACTEvent[reader.ReadByte()]; for (int i = 0; i < Events.Length; i += 1) { // Full Event information uint eventInfo = reader.ReadUInt32(); // XACT Event Type, Timestamp uint eventType = eventInfo & 0x0000001F; uint eventTimestamp = (eventInfo >> 5) & 0x0000FFFF; // uint eventUnknown = eventInfo >> 21; // Random offset, unused reader.ReadUInt16(); // Load the Event if (eventType == 0) { // TODO: Codename OhGodNo // Stop Event } else if (eventType == 1) { // Unknown value reader.ReadByte(); /* Event Flags * 0x01 = Break Loop * 0x02 = Use Speaker Position * 0x04 = Use Center Speaker * 0x08 = New Speaker Position On Loop */ reader.ReadByte(); // WaveBank Track Index ushort track = reader.ReadUInt16(); // WaveBank Index byte waveBank = reader.ReadByte(); // Number of times to loop wave (255 is infinite) byte loopCount = reader.ReadByte(); // Speaker position angle/arc, unused reader.ReadUInt16(); reader.ReadUInt16(); // Finally. Events[i] = new PlayWaveEvent( eventTimestamp, new ushort[] { track }, new byte[] { waveBank }, 0, 0, clipVolume, clipVolume, 0xFF, loopCount, 0, new byte[] { 0xFF } ); } else if (eventType == 3) { // Unknown value reader.ReadByte(); /* Event Flags * 0x01 = Break Loop * 0x02 = Use Speaker Position * 0x04 = Use Center Speaker * 0x08 = New Speaker Position On Loop */ reader.ReadByte(); // Number of times to loop wave (255 is infinite) byte loopCount = reader.ReadByte(); // Speaker position angle/arc, unused reader.ReadUInt16(); reader.ReadUInt16(); // Number of WaveBank tracks ushort numTracks = reader.ReadUInt16(); /* Variation Playlist Type. * First 4 bytes indicates Variation Type. * Next 4 bytes appear to indicate New Variation On Loop. * The rest is currently unknown. * -flibit */ ushort variationType = (ushort) (reader.ReadUInt16() & 0x000F); // Unknown values reader.ReadBytes(4); // Obtain WaveBank track information ushort[] tracks = new ushort[numTracks]; byte[] waveBanks = new byte[numTracks]; byte[] weights = new byte[numTracks]; for (ushort j = 0; j < numTracks; j += 1) { tracks[j] = reader.ReadUInt16(); waveBanks[j] = reader.ReadByte(); byte minWeight = reader.ReadByte(); byte maxWeight = reader.ReadByte(); weights[j] = (byte) (maxWeight - minWeight); } // Finally. Events[i] = new PlayWaveEvent( eventTimestamp, tracks, waveBanks, 0, 0, clipVolume, clipVolume, 0xFF, loopCount, variationType, weights ); } else if (eventType == 4) { // Unknown value reader.ReadByte(); /* Event Flags * 0x01 = Break Loop * 0x02 = Use Speaker Position * 0x04 = Use Center Speaker * 0x08 = New Speaker Position On Loop */ reader.ReadByte(); // WaveBank track ushort track = reader.ReadUInt16(); // WaveBank index, unconfirmed byte waveBank = reader.ReadByte(); // Loop Count, unconfirmed byte loopCount = reader.ReadByte(); // Speaker position angle/arc, unused reader.ReadUInt16(); reader.ReadUInt16(); // Pitch Variation short minPitch = reader.ReadInt16(); short maxPitch = reader.ReadInt16(); // Volume Variation double minVolume = XACTCalculator.ParseDecibel(reader.ReadByte()); double maxVolume = XACTCalculator.ParseDecibel(reader.ReadByte()); // Frequency Variation, unusued reader.ReadSingle(); reader.ReadSingle(); // Q Factor Variation, unused reader.ReadSingle(); reader.ReadSingle(); // Filter Type byte filterType = reader.ReadByte(); // Finally. Events[i] = new PlayWaveEvent( eventTimestamp, new ushort[] { track }, new byte[] { waveBank }, minPitch, maxPitch, minVolume, maxVolume, filterType, loopCount, 0, new byte[] { 0xFF } ); } else if (eventType == 6) { // Unknown value reader.ReadByte(); /* Event Flags * 0x01 = Break Loop * 0x02 = Use Speaker Position * 0x04 = Use Center Speaker * 0x08 = New Speaker Position On Loop */ reader.ReadByte(); // Number of times to loop wave (255 is infinite) byte loopCount = reader.ReadByte(); // Speaker position angle/arc, unused reader.ReadUInt16(); reader.ReadUInt16(); // Pitch variation short minPitch = reader.ReadInt16(); short maxPitch = reader.ReadInt16(); // Volume variation double minVolume = XACTCalculator.ParseDecibel(reader.ReadByte()); double maxVolume = XACTCalculator.ParseDecibel(reader.ReadByte()); // Frequency Variation, unusued reader.ReadSingle(); reader.ReadSingle(); // Q Factor Variation, unused reader.ReadSingle(); reader.ReadSingle(); // Filter Type byte filterType = reader.ReadByte(); // Variation flags // FIXME: There's probably more to these flags... byte varFlags = reader.ReadByte(); if ((varFlags & 0x20) != 0x20) { // Throw out the volume variation. minVolume = clipVolume; maxVolume = clipVolume; } if ((varFlags & 0x10) != 0x10) { // Throw out the pitch variation minPitch = 0; maxPitch = 0; } // Number of WaveBank tracks ushort numTracks = reader.ReadUInt16(); /* Variation Playlist Type. * First 4 bytes indicates Variation Type. * Next 4 bytes appear to indicate New Variation On Loop. * The rest is currently unknown. * -flibit */ ushort variationType = (ushort) (reader.ReadUInt16() & 0x000F); // Unknown values reader.ReadBytes(4); // Obtain WaveBank track information ushort[] tracks = new ushort[numTracks]; byte[] waveBanks = new byte[numTracks]; byte[] weights = new byte[numTracks]; for (ushort j = 0; j < numTracks; j += 1) { tracks[j] = reader.ReadUInt16(); waveBanks[j] = reader.ReadByte(); byte minWeight = reader.ReadByte(); byte maxWeight = reader.ReadByte(); weights[j] = (byte) (maxWeight - minWeight); } // Finally. Events[i] = new PlayWaveEvent( eventTimestamp, tracks, waveBanks, minPitch, maxPitch, minVolume, maxVolume, filterType, loopCount, variationType, weights ); } else if (eventType == 7) { // TODO: Codename OhGodNo -flibit // Pitch Event } else if (eventType == 8) { // Unknown values reader.ReadBytes(2); /* Event Flags * 0x01 = Add, rather than replace * Rest is unknown */ bool addVolume = (reader.ReadByte() & 0x01) == 0x01; // Operand Constant float constant = reader.ReadSingle() / 100.0f; if (addVolume) { constant += (float) clipVolume; } // Unknown values reader.ReadBytes(8); Events[i] = new SetVolumeEvent( eventTimestamp, XACTCalculator.CalculateAmplitudeRatio(constant) ); } else if (eventType == 15) { // TODO: Codename OhGodNo -flibit // Unknown Event! } else if (eventType == 17) { // TODO: Codename OhGodNo -flibit // Volume Repeat Event } else { /* TODO: All XACT Events. * The following type information is based on * third-party contributions: * Type 9 - Marker Event * -flibit */ throw new Exception( "EVENT TYPE " + eventType.ToString() + " NOT IMPLEMENTED!" ); } } }
public XACTClip(ushort track, byte waveBank) { Events = new XACTEvent[1]; Events[0] = new PlayWaveEvent( 0, new ushort[] { track }, new byte[] { waveBank }, 0, 0, 1.0, 1.0, 0xFF, 0, 0, new byte[] { 0xFF } ); }