Пример #1
0
        private static bool LoadANdMergeWAV(BlamSound blamSound)
        {
            uint length = (uint)(2 * blamSound.SampleCount * Encoding.GetChannelCount(blamSound.Encoding));

            byte[] WAVFLR = null;
            //byte[] WAVRLR = null;
            //byte[] WAVCCL = null;
            switch (Encoding.GetChannelCount(blamSound.Encoding))
            {
            case 1:
            case 2:
                byte[] data = LoadWAVData(WAVFile, (int)length, false);
                blamSound.UpdateFormat(Compression.PCM, data);
                uint newSampleCount = (uint)(data.Length / (Encoding.GetChannelCount(blamSound.Encoding) * 2));
                blamSound.SampleCount = newSampleCount;
                break;

            case 4:
                WAVFLR = LoadWAVData(WAV1FlUnk, (int)length / 2);
                //WAVRLR = LoadWAVData(WAV2BlUnk, (int)length / 2);
                blamSound.UpdateFormat(Compression.PCM, WAVFLR);     //MergeChannels(length, WAVFLR, WAVRLR)
                blamSound.Encoding = EncodingValue.Stereo;
                break;

            case 6:
                WAVFLR = LoadWAVData(WAV1FlUnk, (int)length / 3);
                //WAVCCL = LoadWAVData(WAV2CUnk, (int)length / 3);
                //WAVRLR = LoadWAVData(WAV3BlUnk, (int)length / 3);
                blamSound.UpdateFormat(Compression.PCM, WAVFLR);     //MergeChannels(length, WAVFLR, WAVCCL, WAVRLR)
                blamSound.Encoding = EncodingValue.Stereo;
                break;
            }
            return(true);
        }
Пример #2
0
 private static void WriteFSBFile(BlamSound blamSound)
 {
     using (EndianWriter output = new EndianWriter(new FileStream(FSBFile, FileMode.Create, FileAccess.Write, FileShare.None), EndianFormat.BigEndian))
     {
         FSB4File FSB4File = new FSB4File(blamSound);
         FSB4File.Write(output);
     }
 }
Пример #3
0
        private static void LoadMP3Data(BlamSound blamSound)
        {
            byte[] data       = File.ReadAllBytes(MP3File);
            var    dataLength = data.Length - 0x51;

            byte[] result = new byte[dataLength];
            // remove ID3 header from mp3 file
            Array.Copy(data, 0x51, result, 0, dataLength);
            blamSound.UpdateFormat(Compression.MP3, result);
        }
Пример #4
0
        public static BlamSound ConvertGen3Sound(CacheFile cache, SoundCacheFileGestalt soundGestalt, Sound sound, int pitchRangeIndex, int permutationIndex, byte[] data)
        {
            ClearFiles();
            BlamSound blamSound = GetXMA(cache, soundGestalt, sound, pitchRangeIndex, permutationIndex, data);

            if (blamSound.Compression == Compression.UnknownWTF)
            {
                throw new Exception("Unknown compression");
            }

            var loop         = sound.Flags.HasFlag(Sound.FlagsValue.LoopingSound);
            var channelCount = Encoding.GetChannelCount(blamSound.Encoding);
            var sampleRate   = blamSound.SampleRate.GetSampleRateHz();

            WriteXMAFile(blamSound);

            if (channelCount > 2)
            {
                // channelCount is 4 or 6, ignore looping
                ConvertToWAV(XMAFile, false);
                byte[] originalWAVdata  = File.ReadAllBytes(WAVFile);
                byte[] truncatedWAVdata = TruncateWAVFile(originalWAVdata, sampleRate, channelCount, 0x4E);
                blamSound.UpdateFormat(Compression.PCM, truncatedWAVdata);
                WriteWAVFile(blamSound);
                ConvertToMP3(WAVFile);
                LoadMP3Data(blamSound);
            }
            else if (!loop)
            {
                // not looping stereo or mono
                ConvertToWAV(XMAFile, true);
                blamSound.UpdateFormat(Compression.PCM, LoadWAVData(WAVFile, -1, false));
                WriteWAVFile(blamSound);
                ConvertToMP3(WAVFile);
                LoadMP3Data(blamSound);
            }
            else
            {
                ConvertToWAV(XMAFile, true);
                blamSound.UpdateFormat(Compression.PCM, LoadWAVData(WAVFile, -1, false));
                WriteWAVFile(blamSound);
                ConvertWAVToMP3Looping(WAVFile);
                blamSound.UpdateFormat(Compression.MP3, File.ReadAllBytes(MP3File));
            }
            ClearFiles();
            return(blamSound);
        }
Пример #5
0
 private static void CreateFSB4(BlamSound blamSound)
 {
     blamSound.UpdateFormat(Compression.FSB4, null);
 }