Ejemplo n.º 1
0
        public Frequency[][] LoadFrequencies(string path)
        {
            string[] files  = Directory.GetFiles(path, "*hca");
            var      freq   = Helpers.CreateJaggedArray <Frequency[][]>(30, 0x100);
            var      counts = Helpers.CreateJaggedArray <int[][]>(30, 0x100);
            int      total  = 0;

            Progress.SetTotal(files.Length);

            var reader = new HcaReader {
                Decrypt = false
            };

            foreach (string file in files)
            {
                CriHcaFormat hca;
                using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read))
                {
                    hca = (CriHcaFormat)reader.ReadFormat(stream);
                }

                foreach (byte[] frame in hca.AudioData)
                {
                    for (int position = 0; position < 30; position++)
                    {
                        counts[position][frame[position]]++;
                    }
                    total++;
                }

                Progress.ReportAdd(1);
            }

            for (int position = 0; position < 30; position++)
            {
                for (int value = 0; value < 0x100; value++)
                {
                    freq[position][value] = new Frequency((byte)value, (float)counts[position][value] / total);
                }
                freq[position] = freq[position].OrderByDescending(x => x.Freq).ToArray();
            }

            return(freq);
        }