Beispiel #1
0
        public void merge_headers(WemFile original)
        {
            var ms = new MemoryStream();

            ms.Write(buffer, 0, buffer.Length);
            using (var bw = new BinaryWriter(ms))
            {
                if (!fake_vorb)
                {
                    throw new Exception("Not supported.");
                }

                riff_size = 0;
                subtype   = original.subtype;

                bw.Write(riff_head.ToCharArray());
                bw.Write(riff_size);
                bw.Write(wave_head.ToCharArray());

                bw.Write("fmt ".ToCharArray());
                bw.Write(fmt_size);
                bw.Write(codecid);
                bw.Write(channels);
                bw.Write(sample_rate);
                bw.Write(avg_bytes_per_second);
                bw.Write(block_alignment);
                bw.Write(bps);
                bw.Write(extra_fmt_length);
                bw.Write(ext_unk);
                bw.Write(subtype);
                bw.Write(sample_count);
                bw.Write(mod_signal);
                bw.Write(fmt_unk_field32_1);
                bw.Write(fmt_unk_field32_2);
                bw.Write(pre_data.Length);
                bw.Write((UInt32)(pre_data.Length + (first_audio_packet_offset - setup_packet_offset)));
                bw.Write(fmt_unk_field32_3);
                bw.Write(fmt_unk_field32_4);
                bw.Write(fmt_unk_field32_5);
                bw.Write(uid);
                bw.Write(blocksize_0_pow);
                bw.Write(blocksize_1_pow);

                if (cue_offset != 0)
                {
                    bw.Write("cue ".ToCharArray());
                    bw.Write(cue_size);
                    bw.Write(cue_count);
                    bw.Write(cue_id);
                    bw.Write(cue_position);
                    bw.Write(cue_datachunkid);
                    bw.Write(cue_chunkstart);
                    bw.Write(cue_blockstart);
                    bw.Write(cue_sampleoffset);
                }
            }
            buffer = ms.ToArray();
            ms.Flush();
        }
Beispiel #2
0
        public void Merge_Datas(WemFile original)
        {
            var ms = new MemoryStream();

            ms.Write(buffer, 0, buffer.Length);
            using (var bw = new BinaryWriter(ms))
            {
                bw.Write("data".ToCharArray());
                bw.Write((UInt32)(pre_data.Length + data_setup.Length + data.Length));
                bw.Write(pre_data);
                bw.Write(data_setup);
                bw.Write(data);
            }
            buffer = ms.ToArray();
            ms.Flush();
        }
Beispiel #3
0
        public uint add_music(string file)
        {
            string s   = Path.GetFileNameWithoutExtension(file);
            uint   mid = 0;

            if (!uint.TryParse(s, out mid))
            {
                Console.WriteLine("Soundbank : add_music -- Invalid WEM ID");
                Environment.Exit(0);
            }
            if (mid < 1 || mid > 0xFFFFFFFF)
            {
                Console.WriteLine("Soundbank : add_music -- Invalid WEM ID");
                Environment.Exit(0);
            }

            WemFile wem = new WemFile();

            wem.LoadFromFile(file, WwAudioFileType.Wem);

            double   new_time = (wem.sample_count / wem.sample_rate) * 1000;
            SBObject segment  = null;

            foreach (var obj in _objects._objects)
            {
                if (obj._type == SBObject.TYPE_MUSIC_TRACK)
                {
                    if (obj._obj_mto._id1 == mid)
                    {
                        Console.WriteLine("Add new music : ID " + mid + " is already used");
                        Environment.Exit(0);
                    }
                }
                else if (obj._type == SBObject.TYPE_MUSIC_SEGMENT)
                {
                    if (segment == null)
                    {
                        segment = obj;
                    }
                }
            }
            if (segment != null)
            {
                Console.WriteLine("No music segments within the soundbank");
                Environment.Exit(0);
            }

            uint     musicTrackId     = _objects.get_new_id();
            SBObject musicTrackObject = new SBObject();

            musicTrackObject._type           = SBObject.TYPE_MUSIC_TRACK;
            musicTrackObject._id             = musicTrackId;
            musicTrackObject._obj_mto_custom = new SBMusicTrackCustomObject(mid, new_time, 0);
            musicTrackObject._current_obj    = "MusicTrackCustom";
            musicTrackObject.calculateLength();

            _objects._objects.Add(musicTrackObject);

            uint musicSegmentId = _objects.get_new_id();

            musicTrackObject._obj_mto_custom._parent = musicSegmentId;

            SBObject musicSegmentObject = segment;

            musicSegmentObject._id = musicSegmentId;
            musicSegmentObject._obj_mso._children  = 1;
            musicSegmentObject._obj_mso._child_ids = new List <uint>();
            musicSegmentObject._obj_mso._child_ids.Add(musicTrackId);
            musicSegmentObject._obj_mso._unk_double_1               = 1000;
            musicSegmentObject._obj_mso._unk_field64_1              = 0;
            musicSegmentObject._obj_mso._unk_field64_2              = 0;
            musicSegmentObject._obj_mso._time_length                = new_time;
            musicSegmentObject._obj_mso._time_length_next           = new_time;
            musicSegmentObject._obj_mso._sound_structure._parent_id = 0;
            musicSegmentObject.calculateLength();

            _objects._objects.Add(musicSegmentObject);
            _objects.calculate_length();

            return(musicSegmentId);
        }
Beispiel #4
0
        public void rebuild_music(string file)
        {
            uint mid = 0;

            if (!uint.TryParse(Path.GetFileNameWithoutExtension(file), out mid))
            {
                Console.WriteLine("Soundbank : rebuild_music -- wrong file");
                return;
            }
            if (mid < 1 || mid > 0xFFFFFFFF)
            {
                Console.WriteLine("Soundbank : rebuild_music -- Invalid WEM ID");
                return;
            }

            WemFile wem = new WemFile();

            wem.LoadFromFile(file, WwAudioFileType.Wem);

            double new_time = (wem.sample_count / (float)wem.sample_rate) * 1000;

            Dictionary <uint, List <uint> > trackids = new Dictionary <uint, List <uint> >();
            uint i = 0;

            foreach (var obj in _objects._objects)
            {
                if (obj._type == SBObject.TYPE_MUSIC_TRACK)
                {
                    if (obj._obj_mto._id1 == mid)
                    {
                        List <uint> v = new List <uint> {
                            i, 0
                        };
                        trackids.Add(obj._id, v);
                    }
                }
                i++;
            }
            if (trackids.Count == 0)
            {
                Console.WriteLine("Could not find ID " + mid + " within soundbank -- rebuild_music");
                return;
            }
            foreach (var obj in _objects._objects)
            {
                if (obj._type == SBObject.TYPE_MUSIC_SEGMENT)
                {
                    if (obj._obj_mso._child_ids.Count == 1)
                    {
                        obj._obj_mso._unk_double_1              = 1000;
                        obj._obj_mso._unk_field64_1             = 0;
                        obj._obj_mso._unk_field64_2             = 0;
                        obj._obj_mso._time_length               = new_time;
                        obj._obj_mso._time_length_next          = new_time;
                        trackids[obj._obj_mso._child_ids[0]][1] = obj._id;
                    }
                    else
                    {
                        long hasTrack = -1;
                        foreach (var trackid in trackids)
                        {
                            if (obj._obj_mso._child_ids.Contains(trackid.Key))
                            {
                                hasTrack = (long)trackid.Key;
                            }
                        }
                        if (hasTrack != -1)
                        {
                            obj._obj_mso._children  = 1;
                            obj._obj_mso._child_ids = new List <uint>();
                            obj._obj_mso._child_ids.Add((uint)hasTrack);
                            obj._obj_mso._unk_double_1     = 1000;
                            obj._obj_mso._unk_field64_1    = 0;
                            obj._obj_mso._unk_field64_2    = 0;
                            obj._obj_mso._time_length      = new_time;
                            obj._obj_mso._time_length_next = new_time;
                            obj.calculateLength();
                            trackids[(uint)hasTrack][1] = obj._id;
                        }
                    }
                }
            }

            foreach (var t in trackids)
            {
                if (t.Value[1] != 0)
                {
                    _objects._objects[(int)t.Value[0]]._obj_mto_custom = new SBMusicTrackCustomObject(mid, new_time, t.Value[1]);
                    _objects._objects[(int)t.Value[0]].calculateLength();
                }
            }

            _objects.calculate_length();
        }