public override void PrintSpecificMetadata(object metadata, StringBuilder builder) { var hcaStructure = metadata as HcaStructure; HcaInfo hca = hcaStructure?.Hca; if (hcaStructure == null || hca == null) { throw new InvalidDataException("Could not parse file metadata."); } builder.AppendLine(); builder.AppendLine($"HCA version: {hcaStructure.Version >> 8}.{hcaStructure.Version & 0xf}"); builder.AppendLine($"Frame size: {hca.FrameSize} bytes"); builder.AppendLine($"Frame count: {hca.FrameCount}"); builder.AppendLine($"Inserted samples: {hca.InsertedSamples}"); builder.AppendLine($"Base band count: {hca.BaseBandCount}"); builder.AppendLine($"Joint stereo band count: {hca.StereoBandCount}"); builder.AppendLine($"HFR band count: {hca.HfrBandCount}"); builder.AppendLine($"Total band count: {hca.TotalBandCount}"); // ReSharper disable once CompareOfFloatsByEqualityOperator if (hca.Volume != 1) { builder.AppendLine($"Volume: {hca.Volume}"); } if (!string.IsNullOrWhiteSpace(hca.Comment)) { builder.AppendLine($"Comment: {hca.Comment}"); } }
public CriHcaFormatBuilder(byte[][] audioData, HcaInfo hca) { AudioData = audioData; Hca = hca; SampleRate = hca.SampleRate; SampleCount = hca.SampleCount; if (hca.Looping) { Looping = true; LoopStart = hca.LoopStartSample; LoopEnd = hca.LoopEndSample; } }
public override Common ToCommon(object metadata) { var hcaStructure = metadata as HcaStructure; HcaInfo hca = hcaStructure?.Hca; if (hcaStructure == null || hca == null) { throw new InvalidDataException("Could not parse file metadata."); } return(new Common { SampleCount = hca.SampleCount, SampleRate = hca.SampleRate, ChannelCount = hca.ChannelCount, Format = AudioFormat.CriHca, Looping = hca.Looping, LoopStart = hca.LoopStartSample, LoopEnd = hca.LoopEndSample }); }
private static void ReadHcaHeader(BinaryReader reader, HcaStructure structure) { HcaInfo hca = structure.Hca; string signature = ReadChunkId(reader); structure.Version = reader.ReadInt16(); structure.HeaderSize = reader.ReadInt16(); if (signature != "HCA\0") { throw new InvalidDataException("Not a valid HCA file"); } bool hasAthChunk = false; while (reader.BaseStream.Position < structure.HeaderSize) { string chunkId = ReadChunkId(reader); switch (chunkId) { case "fmt\0": ReadFmtChunk(reader, structure); break; case "comp": ReadCompChunk(reader, structure); break; case "dec\0": ReadDecChunk(reader, structure); break; case "loop": ReadLoopChunk(reader, structure); break; case "ath\0": ReadAthChunk(reader, structure); hasAthChunk = true; break; case "ciph": ReadCiphChunk(reader, structure); break; case "rva\0": ReadRvaChunk(reader, structure); break; case "vbr\0": ReadVbrChunk(reader, structure); break; case "comm": ReadCommChunk(reader, structure); reader.BaseStream.Position = structure.HeaderSize; break; case "pad\0": reader.BaseStream.Position = structure.HeaderSize; break; default: throw new NotSupportedException($"Chunk {chunkId} is not supported."); } } if (structure.Version < 0x0200 && !hasAthChunk) { hca.UseAthCurve = true; } if (hca.TrackCount < 1) { hca.TrackCount = 1; } hca.CalculateHfrValues(); }