示例#1
0
文件: Audio.cs 项目: pepster98/FreeSO
        /// <summary>
        /// Gets a audio file from a DBPF using its InstanceID.
        /// </summary>
        /// <param name="InstanceID">The InstanceID of the audio.</param>
        /// <param name="dbpf">The DBPF to search.</param>
        /// <returns>The audio as a stream of bytes.</returns>
        private byte[] GetAudioFrom(uint InstanceID, DBPFFile dbpf)
        {
            if (InstanceID == 0)
            {
                return(null);
            }

            //all game sfx has type id 0x2026960B
            byte[] dat = dbpf.GetItemByID((ulong)DBPFTypeID.SoundFX + (((ulong)InstanceID) << 32));

            if (dat != null)
            {
                string head = new string(new char[] { (char)dat[0], (char)dat[1], (char)dat[2], (char)dat[3] });
                if (head.StartsWith("XA"))
                {
                    return(new XAFile(dat).DecompressedData);
                }
                else if (head.StartsWith("UTM0"))
                {
                    var utk = new UTKFile2(dat);
                    utk.UTKDecode();
                    return(utk.DecompressedWav);
                }
                else
                {
                    return(dat); //either wav or mp3, bass.net can explicitly read these.
                }
            }
            else
            {
                Debug.WriteLine("Couldn't find sound!");
            }
            return(null);
        }
示例#2
0
        private byte[] GetAudioFrom(uint id, DBPF dbpf)
        {
            //all game sfx has type id 0x2026960B
            var dat = dbpf.GetItemByID((ulong)0x2026960B + (((ulong)id) << 32));

            if (dat != null)
            {
                string head = new string(new char[] { (char)dat[0], (char)dat[1], (char)dat[2], (char)dat[3] });
                if (head.StartsWith("XA"))
                {
                    return(new XAFile(dat).DecompressedData);
                }
                else if (head.StartsWith("UTM0"))
                {
                    var utk = new UTKFile2(dat);
                    utk.UTKDecode();
                    return(utk.DecompressedWav);
                }
                else
                {
                    return(dat); //either wav or mp3, bass.net can explicitly read these.
                }
            }
            return(null);
        }
示例#3
0
        public override object GenDecode(Stream stream)
        {
            var dat = new byte[4];

            stream.Read(dat, 0, 4);
            stream.Seek(-4, SeekOrigin.Current);
            string head = new string(new char[] { (char)dat[0], (char)dat[1], (char)dat[2], (char)dat[3] });

            if (head.StartsWith("XA"))
            {
                return(new DecodedSFX(1, new XAFile(ReadAllBytes(stream)).DecompressedData));
            }
            else if (head.StartsWith("UTM0"))
            {
                var utk = new UTKFile2(ReadAllBytes(stream));
                utk.UTKDecode();
                return(new DecodedSFX(2, utk.DecompressedWav));
            }
            else
            {
                return(new DecodedSFX(3, ReadAllBytes(stream))); //either wav or mp3.
            }
        }
示例#4
0
        /// <summary>
        /// Gets a audio file from a DBPF using its InstanceID.
        /// </summary>
        /// <param name="InstanceID">The InstanceID of the audio.</param>
        /// <param name="dbpf">The DBPF to search.</param>
        /// <returns>The audio as a stream of bytes.</returns>
        private byte[] GetAudioFrom(uint InstanceID, DBPFFile dbpf)
        {
            if (InstanceID == 0)
                return null;

            //all game sfx has type id 0x2026960B
            byte[] dat = dbpf.GetItemByID((ulong)DBPFTypeID.SoundFX + (((ulong)InstanceID)<<32));

            if (dat != null)
            {
                string head = new string(new char[] { (char)dat[0], (char)dat[1], (char)dat[2], (char)dat[3] });
                if (head.StartsWith("XA"))
                    return new XAFile(dat).DecompressedData;
                else if (head.StartsWith("UTM0"))
                {
                    var utk = new UTKFile2(dat);
                    utk.UTKDecode();
                    return utk.DecompressedWav;
                }
                else
                    return dat; //either wav or mp3.
            }
            else
                Debug.WriteLine("Couldn't find sound!");
            return null;
        }