Beispiel #1
0
        public static Stream AddXMAHeader(SndAssetBankEntry entry)
        {
            var data   = entry.Data.Get();
            var ms     = new MemoryStream();
            var writer = new BinaryWriter(ms);

            writer.Write(new[] { (byte)'R', (byte)'I', (byte)'F', (byte)'F' });
            writer.Write(data.Length + 0x34); // ChunkSize
            writer.Write(new[] { (byte)'W', (byte)'A', (byte)'V', (byte)'E' });
            writer.Write(new[] { (byte)'f', (byte)'m', (byte)'t', (byte)' ' });
            writer.Write(0x20); // SubChunk1Size
            writer.Write(new byte[] {
                0x65, 0x01, 0x10, 0x00, 0xD6, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03,
                0xE3, 0x9A, 0x00, 0x00
            }); // Unknown XMA header data.
            writer.Write(entry.SampleRate);
            writer.Write(new byte[] {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            }); // Unknown XMA header data.
            writer.Write(entry.ChannelCount);
            writer.Write((short)2);
            writer.Write(new[] { (byte)'d', (byte)'a', (byte)'t', (byte)'a' });
            writer.Write(data.Length); // SubChunk2Size
            writer.Write(data);        // Data
            ms.Position = 0;
            return(ms);
        }
        private Stream DecodeFLAC(SndAssetBankEntry entry)
        {
            var wavOutput = new MemoryStream();

            try
            {
                using (var input = new MemoryStream(entry.Data.Get()))
                    using (var wavWriter = new WavWriter(wavOutput))
                        using (var reader = new FlacReader(input, wavWriter))
                        {
                            reader.SampleProcessed += (s, args) =>
                                                      BeginInvoke(new MethodInvoker(() =>
                                                                                    currentTimetoolStripLabel.Text = "Please wait, decoding audio... " + args.Progress + "%"));
                            reader.Process();
                        }
                wavOutput.Position = 0;
                return(wavOutput);
            }
            catch (Exception e)
            {
                // Ignore exception for headerless FLAC
                if (e.Message.IndexOf("until eof", StringComparison.InvariantCulture) != -1 &&
                    entry.Data is AudioDataStream && ((AudioDataStream)entry.Data).Stream is HeaderlessFLACStream)
                {
                    wavOutput.Position = 0;
                    return(wavOutput);
                }
                return(null);
            }
        }
        private void ReplaceAudio(SndAssetBankEntry entry, string inputFile)
        {
            // Begin conversion here.
            var options = new ConvertOptions {
                AudioChannels = entry.ChannelCount, SampleRate = entry.SampleRate
            };

            OnAudioReplaced(entry, ConvertProgressForm.Convert(inputFile, entry.Format, options));
        }
        private void OnAudioReplaced(SndAssetBankEntry entry, Stream newData)
        {
            if (newData == null || newData.Length == 0)
            {
                MessageBox.Show("Conversion failed, ensure the file you provided is valid.",
                                "Black Ops II Sound Studio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                if (newData != null)
                {
                    newData.Close();
                }
                return;
            }

            if (entry.Format == AudioFormat.PCMS16)
            {
                var sampleCount = newData.Length / (entry.ChannelCount * 2);
                var duration    = TimeSpan.FromMilliseconds(1000 * (float)sampleCount / entry.SampleRate);
                if (duration > entry.Duration && duration.Subtract(entry.Duration).TotalSeconds >= 1)
                {
                    if (MessageBox.Show(
                            "Duration mismatch detected. This is known to cause loading problems on single-player missions " +
                            "and has not been tested on multiplayer.\n\n" +
                            "Original Duration: " + FormatDuration(entry.Duration) + "\n" +
                            "New Duration: " + FormatDuration(duration) + "\n\n" +
                            "Are you sure you want to continue?",
                            "Black Ops II Sound Studio", MessageBoxButtons.YesNo,
                            MessageBoxIcon.Exclamation) == DialogResult.No)
                    {
                        newData.Close();
                        return;
                    }
                }
                entry.Duration = duration;
            }
            else
            {
                var helper = new ConvertHelper();
                entry.Duration = helper.GetDuration(newData);
            }

            entry.Data = new AudioDataStream(newData, (int)newData.Length);

            foreach (DataGridViewRow row in audioEntriesDataGridView.Rows)
            {
                if (row.Tag != entry)
                {
                    continue;
                }
                foreach (DataGridViewCell cell in row.Cells)
                {
                    cell.Style.BackColor = Color.LightBlue;
                }
                MessageBox.Show("Audio data has been successfully replaced.",
                                "Black Ops II Sound Studio", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;
            }
        }
Beispiel #5
0
        public static Stream GetAudioStreamFromEntry(SndAssetBankEntry entry)
        {
            if (entry.Format == AudioFormat.FLAC ||
                entry.Format == AudioFormat.MP3)
            {
                return(new MemoryStream(entry.Data.Get()));
            }

            if (entry.Format == AudioFormat.PCMS16)
            {
                return(DecodeHeaderlessWav(entry));
            }
            return(AddXMAHeader(entry));
        }
Beispiel #6
0
        public static Stream DecodeHeaderlessWav(SndAssetBankEntry entry)
        {
            var data = entry.Data.Get();
            var ms   = new MemoryStream();

            // Write the header.
            using (var writer = new WavWriter(ms))
            {
                writer.WriteHeader(48000, 16, entry.ChannelCount);
                writer.AudioDataBytes = data.Length;
            }

            // Write the data.
            ms.Write(data, 0, data.Length);
            data = ms.ToArray();

            ms.Position = 0;
            return(ms);
        }