Esempio n. 1
0
        /// <summary>
        /// Function that will parse other sound files(VAG?)
        /// </summary>
        /// <param name="fs">Stream of the file</param>
        /// <returns></returns>
        public static Wavo[] ReadIV(Stream fs)
        {
            var binaryReader = new BinaryReader(fs);
            var bER          = new BER(binaryReader);

            fs.Position = 12L;
            int num   = binaryReader.ReadInt32();
            var array = new KeyValuePair <int, int> [num];

            fs.Position = 16L;
            for (int i = 0; i < num; i++)
            {
                int num2 = binaryReader.ReadInt32();
                if (num2 >= 0)
                {
                    num2 += 16 + 8 * num;
                }
                int value = binaryReader.ReadInt32();
                array[i] = new KeyValuePair <int, int>(num2, value);
            }
            var list = new List <Wavo>();

            for (int j = 0; j < array.Length; j++)
            {
                int key = array[j].Key;
                if (key >= 0)
                {
                    fs.Position = key + 12;
                    int count = bER.ReadInt32() - 32;
                    fs.Position = key + 16;
                    int nSamplesPerSec = bER.ReadInt32();
                    fs.Position = key + 64;
                    list.Add(new Wavo(j.ToString("00") + ".wav",
                                      SPUConv.ToWave(new MemoryStream(binaryReader.ReadBytes(count)), nSamplesPerSec)));
                }
            }
            return(list.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// Function that will parse the WD(instruments)file
        /// </summary>
        /// <param name="fs">Stream of the WD file</param>
        /// <returns></returns>
        public static Wavo[] ReadWD(Stream fs)
        {
            var binaryReader = new BinaryReader(fs);

            fs.Position = 8L;
            int num   = binaryReader.ReadInt32();
            int num2  = binaryReader.ReadInt32();
            var array = new int[num];

            fs.Position = 32L;
            for (int i = 0; i < num; i++)
            {
                array[i] = binaryReader.ReadInt32();
            }
            int gakki = 0;
            int num3  = 0;
            var list  = new List <Wavi>();

            for (int j = 0; j < num2; j++)
            {
                int num4 = 32 + 4 * (num + 3 & -4) + 32 * j;
                int num5 = Array.IndexOf(array, num4);
                if (num5 >= 0)
                {
                    gakki = num5;
                    num3  = 0;
                }
                fs.Position = num4 + 16;
                if (binaryReader.ReadInt64() != 0L || binaryReader.ReadInt64() != 0L)
                {
                    fs.Position = num4 + 4;
                    var wavi = new Wavi();
                    wavi.off   = binaryReader.ReadInt32();
                    wavi.gakki = gakki;
                    wavi.ontei = num3;
                    num3++;
                    fs.Position = num4 + 22;
                    wavi.sps    = binaryReader.ReadUInt16();
                    list.Add(wavi);
                }
            }
            var list2 = new List <Wavo>();

            for (int k = 0; k < list.Count; k++)
            {
                Wavi wavi2 = list[k];
                int  num6  = 32 + 16 * (num + 3 & -4) + 32 * num2 + wavi2.off;
                fs.Position = num6;
                while (fs.Position < fs.Length)
                {
                    byte[] array2 = binaryReader.ReadBytes(16);
                    int    num7   = 0;
                    while (num7 < 16 && array2[num7] == 0)
                    {
                        num7++;
                    }
                    if (num7 == 16)
                    {
                        break;
                    }
                }
                int sps   = wavi2.sps;
                int count = Convert.ToInt32(fs.Position) - num6 - 32;
                fs.Position = num6;
                list2.Add(new Wavo(wavi2.gakki.ToString("000") + "." + wavi2.ontei.ToString("00") + ".wav",
                                   SPUConv.ToWave(new MemoryStream(binaryReader.ReadBytes(count)), sps)));
            }
            return(list2.ToArray());
        }