Exemple #1
0
        protected override At9Structure ReadFile(Stream stream, bool readAudioData = true)
        {
            var structure = new At9Structure();
            var parser    = new RiffParser {
                ReadDataChunk = readAudioData
            };

            parser.RegisterSubChunk("fact", At9FactChunk.ParseAt9);
            parser.RegisterSubChunk("data", At9DataChunk.ParseAt9);
            parser.FormatExtensibleParser = At9WaveExtensible.ParseAt9;
            parser.ParseRiff(stream);

            ValidateAt9File(parser);

            var fmt  = parser.GetSubChunk <WaveFmtChunk>("fmt ");
            var ext  = (At9WaveExtensible)fmt.Ext;
            var fact = parser.GetSubChunk <At9FactChunk>("fact");
            var data = parser.GetSubChunk <At9DataChunk>("data");
            var smpl = parser.GetSubChunk <WaveSmplChunk>("smpl");

            structure.Config          = new Atrac9Config(ext.ConfigData);
            structure.SampleCount     = fact.SampleCount;
            structure.EncoderDelay    = fact.EncoderDelaySamples;
            structure.Version         = ext.VersionInfo;
            structure.AudioData       = data.AudioData;
            structure.SuperframeCount = data.FrameCount;

            if (smpl?.Loops?.FirstOrDefault() != null)
            {
                structure.LoopStart = smpl.Loops[0].Start - structure.EncoderDelay;
                structure.LoopEnd   = smpl.Loops[0].End - structure.EncoderDelay;
                structure.Looping   = structure.LoopEnd > structure.LoopStart;
            }

            return(structure);
        }