public static unsafe void Initialize(AKB2Header *header) { header->Signature = 0x32424b41; header->Constant01 = 0x00100000; header->Constant02 = 0x00000001; header->Constant03 = 0x00100000; header->Constant04 = 0x00000020; header->Constant07 = 0x00300101; header->Constant08 = 0x3F800000; header->Constant10 = 0x0180007C; header->Constant11 = 0x000000FF; header->Constant12 = 0x00000001; header->Constant14 = 0x41F00000; header->Constant19 = 0x00100000; header->Constant20 = 0x000000C0; header->Constant23 = 0x00000002; AKB2UnknownSection.Initialize(&header->Section1); AKB2UnknownSection.Initialize(&header->Section2); AKB2UnknownSection.Initialize(&header->Section3); AKB2UnknownSection.Initialize(&header->Section4); header->Constant32 = 0x0500; header->Unknown33 = 0x0002; header->Constant34 = 0x0040; header->SampleRate = 44100; header->Constant36 = 0x00000010; header->Constant39 = 0x3F800000; header->Constant40 = 0x3F800000; header->Constant41 = 0x3F800000; header->Constant42 = 0x3F800000; }
private static unsafe void ReadAkbDataFromOgg(SoundProfile profile, String oggPath, out IntPtr result, out UInt32 resultSize) { using (FileStream input = File.OpenRead(oggPath)) { // Get size of content UInt32 contentSize = (UInt32)input.Length; UInt32 tailSize = contentSize % 16; UInt32 dataSize = AkbHeaderSize + contentSize; resultSize = dataSize + tailSize; if (tailSize > 0) { tailSize = 16 - tailSize; } // Make an unmanaged array CreateUnmanagedArray(out result, resultSize, tailSize, AkbHeaderSize); // Read file to unmanaged memory using (UnmanagedMemoryStream output = new UnmanagedMemoryStream((Byte *)result, resultSize, resultSize, FileAccess.Write)) { output.Seek(AkbHeaderSize, SeekOrigin.Begin); input.CopyTo(output, Math.Min(resultSize, 80000)); } // Prepare header AKB2Header *header = (AKB2Header *)result; AKB2Header.Initialize(header); // Initialize header header->FileSize = resultSize; header->ContentSize = contentSize; header->Unknown09 = 0x000004002; header->Unknown33 = 0x0002; ReadMetadataFromVorbis(profile, input, header); } }
private static unsafe void ReadMetadataFromVorbis(SoundProfile profile, FileStream input, AKB2Header *header) { input.Position = 0; using (VorbisReader vorbis = new VorbisReader(input, false)) { //header->SampleCount = checked((UInt32)vorbis.TotalSamples); header->SampleRate = checked ((UInt16)vorbis.SampleRate); Int32 desiredCount = 2; Int32 parsedCount = 0; foreach (String comment in vorbis.Comments) { if (TryParseLoopStart(comment, ref header->LoopStart)) { if (++parsedCount >= desiredCount) { break; } } else if (TryParseLoopEnd(comment, ref header->LoopEnd)) { if (++parsedCount >= desiredCount) { break; } } } if (profile.SoundProfileType == SoundProfileType.Music) { if (header->LoopEnd == 0) { header->LoopEnd = checked ((UInt32)(vorbis.TotalSamples - 1)); } } } }