Ejemplo n.º 1
0
        private void Menu_ReplaceSoundWav()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter   = "WAV|*.wav";
            ofd.FileName = Data.ID.ToString();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                using (FileStream file = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read))
                    using (BinaryReader reader = new BinaryReader(file))
                    {
                        file.Position = 0x16;
                        UInt16 channels  = reader.ReadUInt16();
                        UInt32 frequency = reader.ReadUInt32();
                        file.Position = 0x28;
                        int    len = reader.ReadInt32();
                        Byte[] PCM = reader.ReadBytes(len);
                        if (channels == 1)
                        {
                            Data.Freq = (ushort)frequency;
                            Byte[] newData = ADPCM.FromPCMMono(PCM);
                            UInt32 newSize = (uint)newData.Length;
                            InjectData(Data.SoundOffset, Data.SoundSize, newData);
                            Data.SoundSize = newSize;
                        }
                        else
                        {
                            throw new ArgumentException("ATM only mono, sorry fam");
                        }
                        LoadSoundData();
                        GenText();
                    }
            }
        }
Ejemplo n.º 2
0
        private void addTrackToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "WAV files|*.wav";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                BinaryReader reader = new BinaryReader(new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read));
                if (new string(reader.ReadChars(4)) != "RIFF" ||
                    reader.ReadInt32() != reader.BaseStream.Length - 8 ||
                    new string(reader.ReadChars(4)) != "WAVE" ||
                    new string(reader.ReadChars(4)) != "fmt " ||
                    reader.ReadInt32() != 16 ||
                    reader.ReadInt16() != 1)
                {
                    return;
                }
                ushort channels   = reader.ReadUInt16();
                int    samplerate = reader.ReadInt32();
                if (channels > 2 ||
                    reader.ReadInt32() != samplerate * channels * 2 ||
                    reader.ReadInt16() != channels * 2 ||
                    reader.ReadInt16() != 16 ||
                    new string(reader.ReadChars(4)) != "data")
                {
                    return;
                }
                BinaryWriter mb            = new BinaryWriter(new FileStream(mb_name, FileMode.Append, FileAccess.Write));
                long         mb_start_seek = mb.BaseStream.Position;
                if (mb_start_seek > uint.MaxValue)
                {
                    return;
                }
                int    readsize = reader.ReadInt32();
                byte[] vag_data;
                if (channels == 1)
                {
                    vag_data = ADPCM.FromPCMMono(reader.ReadBytes(readsize));
                    mb.Write("MSVp".ToCharArray());
                    mb.Write(0x20000000);
                    mb.Write(0);
                    mb.Write(BitConv.FlipBytes(vag_data.Length));
                    mb.Write(BitConv.FlipBytes(samplerate));
                    mb.Write(0);
                    mb.Write(0);
                    mb.Write(0);
                    string fname_no_ext = ofd.SafeFileName.Substring(0, ofd.SafeFileName.LastIndexOf('.'));
                    for (int i = 0; i < 16; ++i)
                    {
                        if (i < fname_no_ext.Length)
                        {
                            mb.Write(fname_no_ext[i]);
                        }
                        else
                        {
                            mb.Write(0);
                        }
                    }
                    mb.Write(vag_data);
                }
                else if (channels == 2)
                {
                    vag_data = ADPCM.FromPCMStereo(reader.ReadBytes(readsize), interleave);
                    mb.Write(vag_data);
                }
            }
        }