Beispiel #1
0
        public static bool ExtractRawFromSourceToFile(string outfile, string afcPath, int dataSize, int dataOffset)
        {
            var ms = ExternalFileHelper.ReadExternalData(afcPath, dataOffset, dataSize);

            if (ms is null)
            {
                return(false);
            }
            if (File.Exists(outfile))
            {
                File.Delete(outfile);
            }
            ms.WriteToFile(outfile);
            return(true);
        }
Beispiel #2
0
        public void DeserializeLargeDynamic()
        {
            dynamic d;

            using (var jsonFile = System.IO.File.OpenText(ExternalFileHelper.GetFilePath("large.json")))
                using (JsonTextReader jsonTextReader = new JsonTextReader(jsonFile))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    d = serializer.Deserialize(jsonTextReader);
                }

            IDictionary <string, int> counts = new Dictionary <string, int>();

            Stopwatch sw = new Stopwatch();

            sw.Start();

            int count = 0;

            foreach (dynamic o in d)
            {
                if (count > 10)
                {
                    break;
                }

                foreach (dynamic friend in o.friends)
                {
                    UpdateValueCount(counts, friend.id);
                    UpdateValueCount(counts, ((string)friend.name).Split(' ')[0]);
                }

                count++;
            }

            Console.WriteLine("Time (secs): " + sw.Elapsed.TotalSeconds);
        }
Beispiel #3
0
            private AudioInfo GetAudioInfo(string afc)
            {
                try
                {
                    AudioInfo ai         = new AudioInfo();
                    var       dataStream = ExternalFileHelper.ReadExternalData(afc, DataOffset, DataSize);

                    using EndianReader er = new EndianReader(dataStream);
                    var header = er.ReadStringASCII(4);
                    if (header == "RIFX")
                    {
                        er.Endian = Endian.Big;
                    }
                    if (header == "RIFF")
                    {
                        er.Endian = Endian.Little;
                    }
                    // Position 4

                    er.Seek(0xC, SeekOrigin.Current); // Post 'fmt ', get fmt size
                    var fmtSize            = er.ReadInt32();
                    var postFormatPosition = er.Position;
                    ai.CodecID = er.ReadUInt16();

                    switch (ai.CodecID)
                    {
                    case 0xFFFF:
                        ai.CodecName = "Vorbis";
                        break;

                    case 0x0166:
                        ai.CodecName = "XMA2";
                        break;

                    default:
                        ai.CodecName = $"Unknown codec ID {ai.CodecID}";
                        break;
                    }

                    ai.Channels   = er.ReadUInt16();
                    ai.SampleRate = er.ReadUInt32();
                    er.ReadInt32();                     //Average bits per second
                    er.ReadUInt16();                    //Alignment. VGMStream shows this is 16bit but that doesn't seem right
                    ai.BitsPerSample = er.ReadUInt16(); //Bytes per sample. For vorbis this is always 0!
                    var extraSize = er.ReadUInt16();
                    if (extraSize == 0x30)
                    {
                        // Newer Wwise
                        er.Seek(postFormatPosition + 0x18, SeekOrigin.Begin);
                        ai.SampleCount = er.ReadUInt32();
                    }
                    else
                    {
                        if (ai.CodecID == 0xFFFF)
                        {
                            // Vorbis
                            er.Seek(0x14 + fmtSize, SeekOrigin.Begin);
                            var chunkName = er.ReadStringASCII(4);
                            while (!chunkName.Equals("vorb", StringComparison.InvariantCultureIgnoreCase))
                            {
                                er.Seek(er.ReadInt32(), SeekOrigin.Current);
                                chunkName = er.ReadStringASCII(4);
                            }

                            er.SkipInt32(); //Skip vorb size
                            ai.SampleCount = er.ReadUInt32();
                        }
                        else if (ai.CodecID == 0x0166)
                        {
                            // XMA2 (360)

                            // This calculation is wrong.
                            // See https://github.com/losnoco/vgmstream/blob/master/src/meta/wwise.c#L484
                            // and
                            // https://github.com/losnoco/vgmstream/blob/b61908f3af892714dda09c143a52fe0d65228985/src/coding/coding_utils.c#L767
                            // Seems correct, but will need to investigate why it's wrong. Example file is 543 in BioSnd_OmgPrA.xxx Xenon ME2
                            er.Seek(0x14 + 0x18, SeekOrigin.Begin); //Start of fmt + 0x18
                            ai.SampleCount = er.ReadUInt32();
                        }
                        else
                        {
                            // UNKNOWN!!
                            Debug.WriteLine("Unknown codec ID!");
                        }
                    }

                    // We don't care about the rest.
                    return(ai);
                }
                catch (Exception)
                {
                    return(null);
                }
            }