protected override void DoFinalTasks(FileStream sourceFileStream, Dictionary <uint, FileStream> outputFiles, bool addHeader) { byte[] headerBytes; byte[] aa3HeaderBytes; uint headerBlock; string sourceFile; foreach (uint streamId in outputFiles.Keys) { if (this.IsThisAnAudioBlock(BitConverter.GetBytes(streamId)) && outputFiles[streamId].Name.EndsWith(Atrac3AudioExtension)) { headerBytes = ParseFile.ParseSimpleOffset(outputFiles[streamId], 0, 0x8); // remove all header chunks string cleanedFile = FileUtil.RemoveAllChunksFromFile(outputFiles[streamId], headerBytes); // close stream and rename file sourceFile = outputFiles[streamId].Name; outputFiles[streamId].Close(); outputFiles[streamId].Dispose(); File.Delete(sourceFile); File.Move(cleanedFile, sourceFile); // add header if (addHeader) { Array.Reverse(headerBytes); headerBlock = BitConverter.ToUInt32(headerBytes, 4); string headeredFile = Path.ChangeExtension(sourceFile, Atrac3Plus.FileExtensionPsp); aa3HeaderBytes = Atrac3Plus.GetAa3Header(headerBlock); FileUtil.AddHeaderToFile(aa3HeaderBytes, sourceFile, headeredFile); File.Delete(sourceFile); } } //else if (this.IsThisAnAudioBlock(BitConverter.GetBytes(streamId)) && // outputFiles[streamId].Name.EndsWith(SubTitleExtension)) //{ // this.ConvertSubtitles(streamId, outputFiles[streamId]); //} } }
protected override void DoFinalTasks(FileStream sourceFileStream, Dictionary <uint, FileStream> outputFiles, bool addHeader) { byte[] headerBytes; byte[] aa3HeaderBytes; uint headerBlock; string sourceFile; long streamInfoOffset; byte streamIdByte; byte streamIdCheckByte; byte channelCount; GenhCreationStruct gcStruct; string genhFile; foreach (uint streamId in outputFiles.Keys) { if (this.IsThisAnAudioBlock(BitConverter.GetBytes(streamId))) { if (outputFiles[streamId].Name.EndsWith(Atrac3AudioExtension)) { headerBytes = ParseFile.ParseSimpleOffset(outputFiles[streamId], 0, 0x8); // remove all header chunks string cleanedFile = FileUtil.RemoveAllChunksFromFile(outputFiles[streamId], headerBytes); // close stream and rename file sourceFile = outputFiles[streamId].Name; outputFiles[streamId].Close(); outputFiles[streamId].Dispose(); File.Delete(sourceFile); File.Move(cleanedFile, sourceFile); // add header if (addHeader) { Array.Reverse(headerBytes); headerBlock = BitConverter.ToUInt32(headerBytes, 4); string headeredFile = Path.ChangeExtension(sourceFile, Atrac3Plus.FileExtension); aa3HeaderBytes = Atrac3Plus.GetAa3Header(headerBlock); FileUtil.AddHeaderToFile(aa3HeaderBytes, sourceFile, headeredFile); File.Delete(sourceFile); } } else if (addHeader && outputFiles[streamId].Name.EndsWith(LpcmAudioExtension)) { // get this block's stream id streamIdByte = BitConverter.GetBytes(streamId)[0]; // get location of first audio stream info block streamInfoOffset = ParseFile.GetNextOffset(sourceFileStream, 0, PamAudioStreamInfoStartBytes); // find matching info block while ((streamInfoOffset > -1)) { streamIdCheckByte = ParseFile.ParseSimpleOffset(sourceFileStream, streamInfoOffset + 0x4, 1)[0]; if (streamIdCheckByte == streamIdByte) { // get channel count channelCount = ParseFile.ParseSimpleOffset(sourceFileStream, streamInfoOffset + 0x11, 1)[0]; // close stream and build GENH file sourceFile = outputFiles[streamId].Name; outputFiles[streamId].Close(); outputFiles[streamId].Dispose(); gcStruct = new GenhCreationStruct(); gcStruct.Format = "0x03"; gcStruct.HeaderSkip = "0"; gcStruct.Interleave = "0x2"; gcStruct.Channels = channelCount.ToString(); gcStruct.Frequency = "48000"; gcStruct.NoLoops = true; genhFile = GenhUtil.CreateGenhFile(sourceFile, gcStruct); // delete original file if (!String.IsNullOrEmpty(genhFile)) { File.Delete(sourceFile); } break; } streamInfoOffset = ParseFile.GetNextOffset(sourceFileStream, streamInfoOffset + 1, PamAudioStreamInfoStartBytes); } } } } }