public OggVorbisExtraData(MaterialSection.MaterialEntry entry, BinaryReader reader) { var extraDataOffset = entry.ExtraDataOffset; /* extradata: */ /* 0x00: version */ /* 0x01: reserved */ /* 0x02: size */ /* 0x04: loop start offset */ /* 0x08: loop end offset */ /* 0x0c: num samples */ /* 0x10: header size */ /* 0x14: seek table size */ /* 0x18: reserved x2 */ /* 0x20: seek table */ Version = reader.ReadByteAt(extraDataOffset); var unknownAt1 = reader.ReadByteAt(extraDataOffset + 0x01); var badSize = reader.ReadUInt16At(extraDataOffset + 0x02); LoopStart = reader.ReadUInt32At(extraDataOffset + 0x04); LoopEnd = reader.ReadUInt32At(extraDataOffset + 0x08); NumberOfSamples = reader.ReadUInt32At(extraDataOffset + 0x0c); HeaderSize = reader.ReadUInt32At(extraDataOffset + 0x10); SeekTableSize = reader.ReadUInt32At(extraDataOffset + 0x14); UnknownAt18 = reader.ReadUInt16At(extraDataOffset + 0x18); //seek table at 20 }
public override void ExtractAsWav(IApplicationLogger logger, MaterialSection.MaterialEntry entry, byte[] fullFileBytes, string wavPath) { var rawContentBytes = fullFileBytes.SubArray(entry.InnerStreamStartPosition, entry.InnerStreamSize); var vorbis = Vorbis.FromMemory(rawContentBytes); WavWriterLoopPoint[] loopPoints = null; if (entry.IsLooping) { loopPoints = new[] { new WavWriterLoopPoint { StartSample = entry.LoopStart, EndSample = entry.LoopEnd } } } ; var wavWriter = new CustomWavWriter(); wavWriter.WriteWav(new CustomWavWriterRequest() { WavPath = wavPath, Channels = vorbis.Channels, SampleRate = vorbis.SampleRate, WavSampleWriter = new OggVorbisToWavSampleWriter(vorbis), LoopPoints = loopPoints, }); logger.Log($"Created wav audio track at: {wavPath}"); }
private static void DecryptHCA(MaterialSection.MaterialEntry entry, byte[] hcaFileBytes, BinaryReader fullBinaryReader) { var extraDataId = entry.ExtraDataId; var key_start = extraDataId & 0xff; var header_size = fullBinaryReader.ReadUInt16At(entry.ExtraDataOffset + 0x02); var start = header_size; var offset = 0; for (int byteIndex = 0; byteIndex < hcaFileBytes.Length; byteIndex++) { var hcaByte = hcaFileBytes[byteIndex]; bool canSwap = byteIndex >= start + offset; if (!canSwap) { continue; } var encryptionIndex = key_start + offset + byteIndex - start; var wrappedEncryptionIndex = encryptionIndex % HcaEncryptionKey.Length; hcaByte ^= HcaEncryptionKey[wrappedEncryptionIndex]; hcaFileBytes[byteIndex] = hcaByte; } }
public HcaExtraData(MaterialSection.MaterialEntry entry, BinaryReader reader) { var extraDataOffset = entry.ExtraDataOffset; Encryption = reader.ReadByteAt(extraDataOffset + 0x0d); Size = ReadBigEndian16(reader, extraDataOffset, 0x16); }
public override void ExtractOriginal(IApplicationLogger logger, MaterialSection.MaterialEntry entry, byte[] fullFileBytes, string outputPath) { var rawBytes = fullFileBytes.SubArray(entry.InnerStreamStartPosition, entry.InnerStreamSize); var rawPath = ExtensionMethods.ChangeExtension(outputPath, FileFormat); File.WriteAllBytes(rawPath, rawBytes); logger.Log($"Created ogg audio track at: {rawPath}"); }
public override void ExtractOriginal(IApplicationLogger logger, MaterialSection.MaterialEntry entry, byte[] fullFileBytes, string outputPath) { var rawContentBytes = fullFileBytes.SubArray(entry.InnerStreamStartPosition, entry.InnerStreamSize); BinaryReader fullBinaryReader = new BinaryReader(new MemoryStream(fullFileBytes)); var encryption = fullBinaryReader.ReadByteAt(entry.ExtraDataOffset + 0x0d); if (encryption == 1) { DecryptHCA(entry, rawContentBytes, fullBinaryReader); } var rawPath = ExtensionMethods.ChangeExtension(outputPath, FileFormat); File.WriteAllBytes(rawPath, rawContentBytes); logger.Log($"Created hca audio track at: {rawPath}"); }
private void WriteOutAudioFile(byte[] fileBytes, string outputFolder, MaterialSection.MaterialEntry entry) { var extractedFilePath = Path.Combine(outputFolder, _materialIndexToFileName[entry.EntryIndex]); var fullFilePath = Path.GetFullPath(extractedFilePath); var fullFolderPath = Path.GetDirectoryName(fullFilePath); if (!Directory.Exists(fullFolderPath)) { Directory.CreateDirectory(fullFolderPath); Logger.Log($"Created folder at: {fullFolderPath}"); } var codec = AvailableCodecs.GetCodec(entry.Codec); if (codec == null) { Logger.Error( $"The track ({_materialIndexToFileName[entry.EntryIndex]}) uses the {entry.Codec} Codec, but AudioMog has no handler to extract it! Skipping!"); return; } if (Settings.AudioExtractor.ExtractAsRaw) { var rawPath = ExtensionMethods.ChangeExtension(fullFilePath, codec.FileFormat); codec.ExtractOriginal(Logger, entry, fileBytes, rawPath); } if (Settings.AudioExtractor.ExtractAsWav) { try { var wavPath = ExtensionMethods.ChangeExtension(fullFilePath, ".wav"); codec.ExtractAsWav(Logger, entry, fileBytes, wavPath); } catch (Exception e) { Logger.Error("Failed to convert to wav! Will attempt to continue extraction!"); Logger.Error(e.ToString()); } } }
public override void ExtractAsWav(IApplicationLogger logger, MaterialSection.MaterialEntry entry, byte[] fullFileBytes, string wavPath) { var rawContentBytes = fullFileBytes.SubArray(entry.InnerStreamStartPosition, entry.InnerStreamSize); AudioData audioData = null; HcaReader reader = new HcaReader(); BinaryReader fullBinaryReader = new BinaryReader(new MemoryStream(fullFileBytes)); var encryption = fullBinaryReader.ReadByteAt(entry.ExtraDataOffset + 0x0d); if (encryption == 1) { DecryptHCA(entry, rawContentBytes, fullBinaryReader); } audioData = reader.Read(rawContentBytes); WaveWriter writer = new WaveWriter(); var wavBytes = writer.GetFile(audioData); File.WriteAllBytes(wavPath, wavBytes); logger.Log($"Created wav audio track at: {wavPath}"); }
public abstract void ExtractAsWav(IApplicationLogger logger, MaterialSection.MaterialEntry entry, byte[] fullFileBytes, string wavPath);
public abstract void ExtractOriginal(IApplicationLogger logger, MaterialSection.MaterialEntry entry, byte[] fullFileBytes, string outputPath);