Ejemplo n.º 1
0
        public override void FixHeader(TemporaryTrack track)
        {
            using (var stream = new MemoryStream(track.RawPortion))
                using (var reader = new VorbisReader(stream))
                {
                    int loopStart = 0;
                    int loopEnd   = 0;

                    var tags = reader.Tags;
                    TryGettingVariable(tags, "LOOPSTART", ref loopStart);
                    TryGettingVariable(tags, "LOOPEND", ref loopEnd);

                    var headerSize       = 0;
                    var newExtraDataSize = track.OriginalEntry.NoStreamHeaderExtraDataSize + headerSize;
                    var streamSize       = track.RawPortion.Length - headerSize;

                    var headerBytes = track.HeaderPortion;
                    WriteByte(headerBytes, 0x04, (byte)reader.Channels);
                    WriteUint(headerBytes, 0x08, (uint)reader.SampleRate);
                    WriteUint(headerBytes, 0x0c, (uint)loopStart);
                    WriteUint(headerBytes, 0x10, (uint)loopEnd);
                    WriteUint(headerBytes, 0x14, (uint)newExtraDataSize);
                    WriteUint(headerBytes, 0x18, (uint)streamSize);
                }
        }
Ejemplo n.º 2
0
        private void TryReplacingTrackContents(Blackboard blackboard, TemporaryTrack track)
        {
            if (track.ExpectedName == null)
            {
                return;
            }

            var originalCodec = AvailableCodecs.GetCodec(track.CurrentCodec);

            if (originalCodec == null)
            {
                blackboard.Logger.Error($"The track ({track.ExpectedName}) uses the {track.OriginalEntry.Codec} Codec, but AudioMog has no handler to replace it! Skipping!");
                return;
            }

            var typelessFilePath = Path.Combine(_hcaFilesFolder, track.ExpectedName);

            if (blackboard.Settings.UseWavFilesIfAvailable)
            {
                var wavFilePath = AddExtension(typelessFilePath, ".wav");
                if (File.Exists(wavFilePath))
                {
                    blackboard.Logger.Log($"Appending {AddExtension(track.ExpectedName, ".wav")}!");
                    var wavFileBytes = File.ReadAllBytes(wavFilePath);
                    var wavReader    = new WaveReader();
                    var audioData    = wavReader.Read(wavFileBytes);
                    var hcaWriter    = new HcaWriter();
                    var hcaFileBytes = hcaWriter.GetFile(audioData);
                    track.RawPortion   = hcaFileBytes;
                    track.CurrentCodec = MaterialCodecType.HCA;
                    return;
                }
            }


            var hcaFilePath = AddExtension(typelessFilePath, ".hca");

            if (File.Exists(hcaFilePath))
            {
                blackboard.Logger.Log($"Appending {AddExtension(track.ExpectedName, ".hca")}!");
                var hcaFileBytes = File.ReadAllBytes(hcaFilePath);
                track.RawPortion   = hcaFileBytes;
                track.CurrentCodec = MaterialCodecType.HCA;
                return;
            }

            var rawFilePath = AddExtension(typelessFilePath, originalCodec.FileFormat);

            if (File.Exists(rawFilePath))
            {
                blackboard.Logger.Log($"Appending {AddExtension(track.ExpectedName, originalCodec.FileFormat)}!");
                var hcaFileBytes = File.ReadAllBytes(rawFilePath);
                track.RawPortion   = hcaFileBytes;
                track.CurrentCodec = track.OriginalEntry.Codec;
                return;
            }

            blackboard.Logger.Log($"Found no replacement to {track.ExpectedName}, using original track from uexp!");
        }
Ejemplo n.º 3
0
        private void FixHeader(TemporaryTrack track)
        {
            var codec = AvailableCodecs.GetCodec(track.CurrentCodec);

            if (codec == null)
            {
                return;
            }

            codec.FixHeader(track);
        }
Ejemplo n.º 4
0
 public abstract void FixHeader(TemporaryTrack track);
Ejemplo n.º 5
0
        public override void FixHeader(TemporaryTrack track)
        {
            ExposedHcaReader reader = new ExposedHcaReader();
            var data = reader.GetStructure(track.RawPortion);


            if (track.OriginalEntry.Codec != track.CurrentCodec)
            {
                var tempMaterialData = track.HeaderPortion.SubArray(0, 32);
                WriteByte(tempMaterialData, 0x05, (byte)MaterialCodecType.HCA);

                var tempHCAData = new byte[16];
                WriteByte(tempHCAData, 0x00, 1);
                WriteByte(tempHCAData, 0x01, 16);                  //extraDataSize
                WriteUshort(tempHCAData, 0x02, (ushort)data.HeaderSize);
                WriteUshort(tempHCAData, 0x04, (ushort)data.Hca.FrameSize);
                WriteUshort(tempHCAData, 0x06, (ushort)data.Hca.LoopStartFrame);
                WriteUshort(tempHCAData, 0x08, (ushort)data.Hca.LoopEndFrame);
                WriteUshort(tempHCAData, 0x0a, (ushort)data.Hca.InsertedSamples);
                WriteByte(tempHCAData, 0x0c, 0);                 //remove mixer flag!
                WriteByte(tempHCAData, 0x0d, 0);                 //remove encryption flag!
                WriteUshort(tempHCAData, 0x0e, 0);               //clean reserves!

                var tempMerged = new byte[48];
                tempMaterialData.CopyTo(tempMerged, 0);
                tempHCAData.CopyTo(tempMerged, 32);

                track.HeaderPortion = tempMerged;
            }


            int loopStart = 0;
            int loopEnd   = 0;

            if (data.Hca.Looping)
            {
                loopStart = data.Hca.LoopStartSample;
                loopEnd   = data.Hca.LoopEndSample;
            }

            var hcaHeaderSize    = data.HeaderSize;
            var newExtraDataSize = 16 + hcaHeaderSize;
            var streamSize       = track.RawPortion.Length - hcaHeaderSize;

            var headerBytes = track.HeaderPortion;

            WriteByte(headerBytes, 0x04, (byte)data.Hca.ChannelCount);
            WriteUint(headerBytes, 0x08, (uint)data.Hca.SampleRate);
            WriteUint(headerBytes, 0x0c, (uint)loopStart);
            WriteUint(headerBytes, 0x10, (uint)loopEnd);
            WriteUint(headerBytes, 0x14, (uint)newExtraDataSize);
            WriteUint(headerBytes, 0x18, (uint)streamSize);

            var extraData = 0x20;

            WriteByte(headerBytes, extraData + 0x00, 1);
            //WriteByte(headerBytes, extraData + 0x01, 16); //extraDataSize
            WriteUshort(headerBytes, extraData + 0x02, (ushort)data.HeaderSize);
            WriteUshort(headerBytes, extraData + 0x04, (ushort)data.Hca.FrameSize);
            WriteUshort(headerBytes, extraData + 0x06, (ushort)data.Hca.LoopStartFrame);
            WriteUshort(headerBytes, extraData + 0x08, (ushort)data.Hca.LoopEndFrame);
            WriteUshort(headerBytes, extraData + 0x0a, (ushort)data.Hca.InsertedSamples);
            // 0x0c: "use mixer" flag
            WriteByte(headerBytes, extraData + 0x0d, 0);             //remove encryption flag!
            // 0x0e: reserved x2
        }