protected override WaveStructure ReadFile(Stream stream, bool readAudioData = true) { var structure = new WaveStructure(); var parser = new RiffParser { ReadDataChunk = readAudioData }; parser.ParseRiff(stream); ValidateWaveFile(parser); WaveFmtChunk fmt = parser.GetSubChunk <WaveFmtChunk>("fmt "); WaveDataChunk data = parser.GetSubChunk <WaveDataChunk>("data"); WaveSmplChunk smpl = parser.GetSubChunk <WaveSmplChunk>("smpl"); int bytesPerSample = fmt.BitsPerSample.DivideByRoundUp(8); structure.RiffSubChunks = parser.GetAllSubChunks(); structure.SampleCount = data.SubChunkSize / bytesPerSample / fmt.ChannelCount; structure.SampleRate = fmt.SampleRate; structure.BitsPerSample = fmt.BitsPerSample; structure.ChannelCount = fmt.ChannelCount; if (smpl?.Loops?.FirstOrDefault() != null) { structure.LoopStart = smpl.Loops[0].Start; structure.LoopEnd = smpl.Loops[0].End; structure.Looping = structure.LoopEnd > structure.LoopStart; } if (!readAudioData) { return(structure); } switch (fmt.BitsPerSample) { case 16: structure.AudioData16 = data.Data.InterleavedByteToShort(fmt.ChannelCount); break; case 8: structure.AudioData8 = data.Data.DeInterleave(bytesPerSample, fmt.ChannelCount); break; } return(structure); }
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); }