当前位置: 首页>>代码示例>>C#>>正文


C# BinaryWriter.WriteDelta方法代码示例

本文整理汇总了C#中BinaryWriter.WriteDelta方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.WriteDelta方法的具体用法?C# BinaryWriter.WriteDelta怎么用?C# BinaryWriter.WriteDelta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryWriter的用法示例。


在下文中一共展示了BinaryWriter.WriteDelta方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetBGM

            public void GetBGM(string nme)
            {
                #region vars

                //I really hate jscript .net(GovanifY's Rewriting BGM2MIDI in c# atm)
                //Setting the vars(incomplete b\c I dunno at all the jscript .net language)
                //Concept: Write in a "temp" folder the files like music066.bgm.mid or image1.imgd.bmp, for debug usage.
                //If this concept should be adopted, we'll need to do only a return of a byte and then write this byte on a new file in the temp folder, in the openkh binaries, not in libkh
                int t = 0;
                byte cmd;
                byte trackC;
                var track = new byte();
                ushort ppqn;
                long tSzT;
                int delta = 0;
                FileStream bgmS = File.Open(nme, FileMode.Open, FileAccess.Read);
                var bgm = new BinaryReader(bgmS);
                FileStream midS = File.Open(nme + ".mid", FileMode.Create, FileAccess.Write);
                var mid = new BinaryWriter(midS);

                #endregion

                try
                {
                    #region checks&info

                    //Check for the debug log/console
                    if (bgm.ReadUInt32() != 0x204D4742)
                    {
                        Console.WriteLine("BAD HEADER!(MIDI: {0} )", nme);
                        return;
                    }
                    Console.WriteLine("Seq ID:         {0}", bgm.ReadUInt16());
                    Console.WriteLine("WD  ID:         {0}", bgm.ReadUInt16());
                    Console.WriteLine("# of Tracks:    {0}", trackC = bgm.ReadByte());
                    Console.WriteLine("Unknown:        {0}", bgm.ReadBytes(3));
                    Console.WriteLine("In-game volume: {0}", bgm.ReadByte());
                    Console.WriteLine("Unknown2:       {0:x2}", bgm.ReadByte());
                    Console.WriteLine("PPQN:           {0}", ppqn = bgm.ReadUInt16());
                    Console.WriteLine("File-Size:      {0}", bgm.ReadUInt32());

                    #endregion

                    bgmS.Position += 12; //padding
                    //Now writing the new midi file

                    #region Header

                    mid.Write(0x6468544D); //header
                    mid.Write(0x06000000); //header length
                    mid.Write(0x0100); //track play type
                    mid.Write(trackC); //# tracks
                    mid.Write(ppqn); //PPQN

                    #endregion

                    for (byte i = track; track < trackC; ++i)
                    {
                        tSzT = bgm.ReadUInt32();
                        Console.WriteLine("Track {0}; Length = {1}", track, tSzT);
                        mid.Write(0x6b72544d); //header
                        long trackLenOffset = midS.Position;
                        mid.Write(0x00000000); //len

                        int tdelta = 0;
                        byte channel = track;
                        for (tSzT += bgmS.Position; bgmS.Position < tSzT - 1;)
                        {
                            delta = t = 0;
                            do
                            {
                                delta = (delta << 7) + ((t = bgm.ReadByte()) & 0x7F);
                            } while (t & 0x80); //I have no idea to what to do with this while
                            tdelta += delta;
                            cmd = bgm.ReadByte();

                            #region cases commands
                //This part need to be rewroted for c#, should take some time. Already changed some little things
                            //If you have the time to(Xeeynamo)can you refactor this part please?^^"
                #if NOTSTABLE
                            switch (cmd)
                            {
                                case 0x00:
                                    mid.WriteDelta(delta);
                                    mid.WriteBytes([0xFF, 0x2F, 0x00])
开发者ID:Truthkey,项目名称:OpenKH,代码行数:85,代码来源:BGM.cs


注:本文中的BinaryWriter.WriteDelta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。