Esempio n. 1
0
 public XACTSound(ushort track, byte waveBank)
 {
     INTERNAL_clips    = new XACTClip[1];
     INTERNAL_clips[0] = new XACTClip(track, waveBank);
     Category          = 0;
     Volume            = 0.0;
     HasLoadedTracks   = false;
 }
Esempio n. 2
0
 public override void Apply(Cue cue, XACTClip track, float elapsedTime)
 {
     // Only actually play if we are not in the process of stopping.
     if (!cue.IsStopping)
     {
         cue.PlayWave(this);
     }
     Played = true;
 }
Esempio n. 3
0
        public override void Apply(Cue cue, XACTClip track, float elapsedTime)
        {
            SetRandomValueEvent evt = (SetRandomValueEvent)Event;

            switch (evt.Property)
            {
            case CueProperty.Volume:
                cue.eventVolume = evt.GetVolume(cue.eventVolume);
                break;

            case CueProperty.Pitch:
                cue.eventPitch = evt.GetPitch(cue.eventPitch);
                break;
            }

            HandleRepeating();
        }
Esempio n. 4
0
        public override void Apply(Cue cue, XACTClip track, float elapsedTime)
        {
            StopEvent evt = (StopEvent)Event;

            AudioStopOptions stopOptions = evt.StopOptions;

            switch (evt.Scope)
            {
            case XACTClip.StopEventScope.Cue:
                cue.Stop(stopOptions);
                break;

            case XACTClip.StopEventScope.Track:
                /* FIXME: Need to stop this and ONLY this track
                 * track.Stop(stopOptions);
                 */
                break;
            }

            Played = true;
        }
Esempio n. 5
0
        public override void Apply(Cue cue, XACTClip track, float elapsedTime)
        {
            SetRampValueEvent evt = (SetRampValueEvent)Event;

            if (elapsedTime <= Timestamp / 1000.0f + evt.Duration)
            {
                switch (evt.Property)
                {
                case CueProperty.Volume:
                    cue.eventVolume = GetValue(evt, elapsedTime);
                    break;

                case CueProperty.Pitch:
                    cue.eventPitch = GetValue(evt, elapsedTime);
                    break;
                }
            }
            else
            {
                HandleRepeating();
            }
        }
Esempio n. 6
0
        public XACTClipInstance(XACTClip clip)
        {
            Clip = clip;

            // Create event instances for each event.
            foreach (XACTEvent evt in Clip.Events)
            {
                // TODO: How best to eliminate this switch? Factory template method? Table of delegates?
                EventInstance eventInstance = null;
                if (evt is PlayWaveEvent)
                {
                    eventInstance = new PlayWaveEventInstance((PlayWaveEvent)evt);
                }
                else if (evt is StopEvent)
                {
                    eventInstance = new StopEventInstance((StopEvent)evt);
                }
                else if (evt is SetValueEvent)
                {
                    eventInstance = new SetValueEventInstance((SetValueEvent)evt);
                }
                else if (evt is SetRandomValueEvent)
                {
                    eventInstance = new SetRandomValueEventInstance((SetRandomValueEvent)evt);
                }
                else if (evt is SetRampValueEvent)
                {
                    eventInstance = new SetRampValueEventInstance((SetRampValueEvent)evt);
                }
                else if (evt is MarkerEvent)
                {
                    eventInstance = new MarkerEventInstance((MarkerEvent)evt);
                }

                Debug.Assert(eventInstance != null);
                Events.Add(eventInstance);
            }
        }
Esempio n. 7
0
        public XACTSound(BinaryReader reader)
        {
            // Sound Effect Flags
            byte soundFlags = reader.ReadByte();
            bool complex    = (soundFlags & 0x01) != 0;

            // AudioCategory Index
            Category = reader.ReadUInt16();

            // Sound Volume
            Volume = XACTCalculator.ParseDecibel(reader.ReadByte());

            // Sound Pitch
            Pitch = (reader.ReadInt16() / 1000.0f);

            // Unknown value
            reader.ReadByte();

            // Length of Sound Entry, unused
            reader.ReadUInt16();

            // Number of Sound Clips
            if (complex)
            {
                INTERNAL_clips = new XACTClip[reader.ReadByte()];
            }
            else
            {
                // Simple Sounds always have 1 PlayWaveEvent.
                INTERNAL_clips = new XACTClip[1];
                ushort track    = reader.ReadUInt16();
                byte   waveBank = reader.ReadByte();
                INTERNAL_clips[0] = new XACTClip(track, waveBank);
            }

            // Parse RPC Properties
            List <uint> rpcCodeList = new List <uint>();

            if ((soundFlags & 0x0E) != 0)
            {
                // RPC data length
                ushort rpcDataLength = reader.ReadUInt16();
                ushort totalDataRead = 2;

                /* For some reason XACT can have separate sets of codes.
                 * I dunno why, but I bet we should be separating them too.
                 * -flibit
                 */
                while (totalDataRead < rpcDataLength)
                {
                    // Number of RPC Presets (in this block)
                    byte numCodes = reader.ReadByte();

                    // Obtain RPC curve codes (in this block)
                    for (byte i = 0; i < numCodes; i += 1)
                    {
                        rpcCodeList.Add(reader.ReadUInt32());
                    }

                    totalDataRead += (ushort)(1 + (4 * numCodes));
                }
            }
            RPCCodes = rpcCodeList.ToArray();             // Array may be empty! It's okay!

            // Parse DSP Presets
            DSPCodes = new uint[0];             // Eww... -flibit
            if ((soundFlags & 0x10) != 0)
            {
                // DSP Presets Length, unused
                reader.ReadUInt16();

                // Number of DSP Presets
                DSPCodes = new uint[reader.ReadByte()];

                // Obtain DSP Preset codes
                for (byte j = 0; j < DSPCodes.Length; j += 1)
                {
                    DSPCodes[j] = reader.ReadUInt32();
                }
            }

            // Parse Sound Events
            if (complex)
            {
                for (int i = 0; i < INTERNAL_clips.Length; i += 1)
                {
                    // XACT Clip volume
                    double clipVolume = XACTCalculator.ParseDecibel(reader.ReadByte());

                    // XACT Clip Offset in Bank
                    uint offset = reader.ReadUInt32();

                    // Unknown value
                    reader.ReadUInt32();

                    // Store this for when we're done reading the clip.
                    long curPos = reader.BaseStream.Position;

                    // Go to the Clip in the Bank.
                    reader.BaseStream.Seek(offset, SeekOrigin.Begin);

                    // Parse the Clip.
                    INTERNAL_clips[i] = new XACTClip(reader, clipVolume);

                    // Back to where we were...
                    reader.BaseStream.Seek(curPos, SeekOrigin.Begin);
                }
            }

            HasLoadedTracks = false;
        }
Esempio n. 8
0
        public XACTSound(BinaryReader reader)
        {
            // Sound Effect Flags
            byte soundFlags = reader.ReadByte();
            bool complex = (soundFlags & 0x01) != 0;

            // AudioCategory Index
            Category = reader.ReadUInt16();

            // Sound Volume
            Volume = XACTCalculator.ParseDecibel(reader.ReadByte());

            // Sound Pitch
            Pitch = (reader.ReadInt16() / 1000.0f);

            // Unknown value
            reader.ReadByte();

            // Length of Sound Entry, unused
            reader.ReadUInt16();

            // Number of Sound Clips
            if (complex)
            {
                INTERNAL_clips = new XACTClip[reader.ReadByte()];
            }
            else
            {
                // Simple Sounds always have 1 PlayWaveEvent.
                INTERNAL_clips = new XACTClip[1];
                ushort track = reader.ReadUInt16();
                byte waveBank = reader.ReadByte();
                INTERNAL_clips[0] = new XACTClip(track, waveBank);
            }

            // Parse RPC Properties
            List<uint> rpcCodeList = new List<uint>();
            if ((soundFlags & 0x0E) != 0)
            {
                // RPC data length
                ushort rpcDataLength = reader.ReadUInt16();
                ushort totalDataRead = 2;

                /* For some reason XACT can have separate sets of codes.
                 * I dunno why, but I bet we should be separating them too.
                 * -flibit
                 */
                while (totalDataRead < rpcDataLength)
                {
                    // Number of RPC Presets (in this block)
                    byte numCodes = reader.ReadByte();

                    // Obtain RPC curve codes (in this block)
                    for (byte i = 0; i < numCodes; i += 1)
                    {
                        rpcCodeList.Add(reader.ReadUInt32());
                    }

                    totalDataRead += (ushort) (1 + (4 * numCodes));
                }
            }
            RPCCodes = rpcCodeList.ToArray(); // Array may be empty! It's okay!

            // Parse DSP Presets
            DSPCodes = new uint[0]; // Eww... -flibit
            if ((soundFlags & 0x10) != 0)
            {
                // DSP Presets Length, unused
                reader.ReadUInt16();

                // Number of DSP Presets
                DSPCodes = new uint[reader.ReadByte()];

                // Obtain DSP Preset codes
                for (byte j = 0; j < DSPCodes.Length; j += 1)
                {
                    DSPCodes[j] = reader.ReadUInt32();
                }
            }

            // Parse Sound Events
            if (complex)
            {
                for (int i = 0; i < INTERNAL_clips.Length; i += 1)
                {
                    // XACT Clip volume
                    double clipVolume = XACTCalculator.ParseDecibel(reader.ReadByte());

                    // XACT Clip Offset in Bank
                    uint offset = reader.ReadUInt32();

                    // Unknown value
                    reader.ReadUInt32();

                    // Store this for when we're done reading the clip.
                    long curPos = reader.BaseStream.Position;

                    // Go to the Clip in the Bank.
                    reader.BaseStream.Seek(offset, SeekOrigin.Begin);

                    // Parse the Clip.
                    INTERNAL_clips[i] = new XACTClip(reader, clipVolume);

                    // Back to where we were...
                    reader.BaseStream.Seek(curPos, SeekOrigin.Begin);
                }
            }

            HasLoadedTracks = false;
        }
Esempio n. 9
0
 public XACTSound(ushort track, byte waveBank)
 {
     INTERNAL_clips = new XACTClip[1];
     INTERNAL_clips[0] = new XACTClip(track, waveBank);
     Category = 0;
     Volume = 0.0;
     HasLoadedTracks = false;
 }
Esempio n. 10
0
        public XACTSound(BinaryReader reader)
        {
            // Sound Effect Flags
            byte soundFlags = reader.ReadByte();
            bool complex    = (soundFlags & 0x01) != 0;

            // AudioCategory Index
            Category = reader.ReadUInt16();

            // Sound Volume
            Volume = XACTCalculator.ParseDecibel(reader.ReadByte());

            // Sound Pitch
            Pitch = (reader.ReadInt16() / 1000.0f);

            // Unknown value
            reader.ReadByte();

            // Length of Sound Entry, unused
            reader.ReadUInt16();

            // Number of Sound Clips
            if (complex)
            {
                INTERNAL_clips = new XACTClip[reader.ReadByte()];
            }
            else
            {
                // Simple Sounds always have 1 PlayWaveEvent.
                INTERNAL_clips = new XACTClip[1];
                ushort track    = reader.ReadUInt16();
                byte   waveBank = reader.ReadByte();
                INTERNAL_clips[0] = new XACTClip(track, waveBank);
            }

            // Parse RPC Properties
            RPCCodes = new List <uint[]>();
            if ((soundFlags & 0x0E) != 0)
            {
                // RPC data length
                ushort rpcDataLength = reader.ReadUInt16();
                ushort totalDataRead = 2;

                while (totalDataRead < rpcDataLength)
                {
                    // Number of RPC Presets (for this track)
                    uint[] codeList = new uint[reader.ReadByte()];

                    // Obtain RPC curve codes (in this block)
                    for (int i = 0; i < codeList.Length; i += 1)
                    {
                        codeList[i] = reader.ReadUInt32();
                    }

                    // Add this track's code list to the master list
                    RPCCodes.Add(codeList);

                    totalDataRead += (ushort)(1 + (4 * codeList.Length));
                }
            }

            // Parse DSP Presets
            DSPCodes = new uint[0];             // Eww... -flibit
            if ((soundFlags & 0x10) != 0)
            {
                // DSP Presets Length, unused
                reader.ReadUInt16();

                // Number of DSP Presets
                DSPCodes = new uint[reader.ReadByte()];

                // Obtain DSP Preset codes
                for (byte j = 0; j < DSPCodes.Length; j += 1)
                {
                    DSPCodes[j] = reader.ReadUInt32();
                }
            }

            // Parse Sound Events
            if (complex)
            {
                for (int i = 0; i < INTERNAL_clips.Length; i += 1)
                {
                    // XACT Clip volume
                    double clipVolume = XACTCalculator.ParseDecibel(reader.ReadByte());

                    // XACT Clip Offset in Bank
                    uint offset = reader.ReadUInt32();

                    // XACT Clip filter
                    byte filterFlags = reader.ReadByte();
                    byte filterType;
                    if ((filterFlags & 0x01) == 0x01)
                    {
                        filterType = (byte)((filterFlags >> 1) & 0x02);
                    }
                    else
                    {
                        filterType = 0xFF;
                    }
                    reader.ReadByte();                     // QFactor?
                    reader.ReadUInt16();                   // Frequency

                    // Store this for when we're done reading the clip.
                    long curPos = reader.BaseStream.Position;

                    // Go to the Clip in the Bank.
                    reader.BaseStream.Seek(offset, SeekOrigin.Begin);

                    // Parse the Clip.
                    INTERNAL_clips[i] = new XACTClip(reader, clipVolume, filterType);

                    // Back to where we were...
                    reader.BaseStream.Seek(curPos, SeekOrigin.Begin);
                }
            }

            HasLoadedTracks = false;
        }
Esempio n. 11
0
        public XACTSound(BinaryReader reader)
        {
            // Sound Effect Flags
            byte soundFlags = reader.ReadByte();
            bool complex    = (soundFlags & 0x01) != 0;

            // AudioCategory Index
            Category = reader.ReadUInt16();

            // Sound Volume
            Volume = XACTCalculator.ParseDecibel(reader.ReadByte());

            // Sound Pitch
            Pitch = (reader.ReadInt16() / 1000.0f);

            // Unknown value
            reader.ReadByte();

            // Length of Sound Entry, unused
            reader.ReadUInt16();

            // Number of Sound Clips
            if (complex)
            {
                INTERNAL_clips = new XACTClip[reader.ReadByte()];
            }
            else
            {
                // Simple Sounds always have 1 PlayWaveEvent.
                INTERNAL_clips = new XACTClip[1];
                ushort track    = reader.ReadUInt16();
                byte   waveBank = reader.ReadByte();
                INTERNAL_clips[0] = new XACTClip(track, waveBank);
            }

            // Parse RPC Properties
            RPCCodes = new uint[0];             // Eww... -flibit
            if ((soundFlags & 0x0E) != 0)
            {
                // RPC data length, unused
                ushort rpcDataLength = reader.ReadUInt16();

                // Number of RPC Presets
                RPCCodes = new uint[reader.ReadByte()];

                // Obtain RPC curve codes
                for (byte i = 0; i < RPCCodes.Length; i += 1)
                {
                    RPCCodes[i] = reader.ReadUInt32();
                }

                // Seek past the rest - we dunno what it is yet.
                reader.BaseStream.Seek(
                    rpcDataLength - 2 - 1 - (4 * RPCCodes.Length),
                    SeekOrigin.Current
                    );
            }

            // Parse DSP Presets
            DSPCodes = new uint[0];             // Eww... -flibit
            if ((soundFlags & 0x10) != 0)
            {
                // DSP Presets Length, unused
                reader.ReadUInt16();

                // Number of DSP Presets
                DSPCodes = new uint[reader.ReadByte()];

                // Obtain DSP Preset codes
                for (byte j = 0; j < DSPCodes.Length; j += 1)
                {
                    DSPCodes[j] = reader.ReadUInt32();
                }
            }

            // Parse Sound Events
            if (complex)
            {
                for (int i = 0; i < INTERNAL_clips.Length; i += 1)
                {
                    // XACT Clip volume
                    double clipVolume = XACTCalculator.ParseDecibel(reader.ReadByte());

                    // XACT Clip Offset in Bank
                    uint offset = reader.ReadUInt32();

                    // Unknown value
                    reader.ReadUInt32();

                    // Store this for when we're done reading the clip.
                    long curPos = reader.BaseStream.Position;

                    // Go to the Clip in the Bank.
                    reader.BaseStream.Seek(offset, SeekOrigin.Begin);

                    // Parse the Clip.
                    INTERNAL_clips[i] = new XACTClip(reader, clipVolume);

                    // Back to where we were...
                    reader.BaseStream.Seek(curPos, SeekOrigin.Begin);
                }
            }

            HasLoadedTracks = false;
        }
Esempio n. 12
0
        public override void Apply(Cue cue, XACTClip track, float elapsedTime)
        {
            // FIXME: Implement action for a marker event. Some kind of callback?

            HandleRepeating();
        }
Esempio n. 13
0
 public abstract void Apply(Cue cue, XACTClip track, float elapsedTime);
Esempio n. 14
0
		public XACTSound(BinaryReader reader)
		{
			// Sound Effect Flags
			byte soundFlags = reader.ReadByte();
			bool complex = (soundFlags & 0x01) != 0;

			// AudioCategory Index
			Category = reader.ReadUInt16();

			// Sound Volume
			Volume = XACTCalculator.ParseDecibel(reader.ReadByte());

			// Sound Pitch
			Pitch = (reader.ReadInt16() / 1000.0f);

			// Unknown value
			reader.ReadByte();

			// Length of Sound Entry, unused
			reader.ReadUInt16();

			// Number of Sound Clips
			if (complex)
			{
				INTERNAL_clips = new XACTClip[reader.ReadByte()];
			}
			else
			{
				// Simple Sounds always have 1 PlayWaveEvent.
				INTERNAL_clips = new XACTClip[1];
				ushort track = reader.ReadUInt16();
				byte waveBank = reader.ReadByte();
				INTERNAL_clips[0] = new XACTClip(track, waveBank);
			}

			// Parse RPC Properties
			RPCCodes = new List<uint[]>();
			if ((soundFlags & 0x0E) != 0)
			{
				// RPC data length
				ushort rpcDataLength = reader.ReadUInt16();
				ushort totalDataRead = 2;

				while (totalDataRead < rpcDataLength)
				{
					// Number of RPC Presets (for this track)
					uint[] codeList = new uint[reader.ReadByte()];

					// Obtain RPC curve codes (in this block)
					for (int i = 0; i < codeList.Length; i += 1)
					{
						codeList[i] = reader.ReadUInt32();
					}

					// Add this track's code list to the master list
					RPCCodes.Add(codeList);

					totalDataRead += (ushort) (1 + (4 * codeList.Length));
				}
			}

			// Parse DSP Presets
			DSPCodes = new uint[0]; // Eww... -flibit
			if ((soundFlags & 0x10) != 0)
			{
				// DSP Presets Length, unused
				reader.ReadUInt16();

				// Number of DSP Presets
				DSPCodes = new uint[reader.ReadByte()];

				// Obtain DSP Preset codes
				for (byte j = 0; j < DSPCodes.Length; j += 1)
				{
					DSPCodes[j] = reader.ReadUInt32();
				}
			}

			// Parse Sound Events
			if (complex)
			{
				for (int i = 0; i < INTERNAL_clips.Length; i += 1)
				{
					// XACT Clip volume
					double clipVolume = XACTCalculator.ParseDecibel(reader.ReadByte());

					// XACT Clip Offset in Bank
					uint offset = reader.ReadUInt32();

					// XACT Clip filter
					byte filterFlags = reader.ReadByte();
					byte filterType;
					if ((filterFlags & 0x01) == 0x01)
					{
						filterType = (byte) ((filterFlags >> 1) & 0x02);
					}
					else
					{
						filterType = 0xFF;
					}
					reader.ReadByte(); // QFactor?
					reader.ReadUInt16(); // Frequency

					// Store this for when we're done reading the clip.
					long curPos = reader.BaseStream.Position;

					// Go to the Clip in the Bank.
					reader.BaseStream.Seek(offset, SeekOrigin.Begin);

					// Parse the Clip.
					INTERNAL_clips[i] = new XACTClip(reader, clipVolume, filterType);

					// Back to where we were...
					reader.BaseStream.Seek(curPos, SeekOrigin.Begin);
				}
			}

			HasLoadedTracks = false;
		}