예제 #1
0
        public override byte[] Read_File()
        {
            XElement xml = XElement.Load(Application.StartupPath + Path.DirectorySeparatorChar + "Plugins" +
                                         Path.DirectorySeparatorChar + "SoundLang.xml");

            xml = xml.Element(lang).Element("Messages");

            sadl = new sSADL();
            BinaryReader br = new BinaryReader(File.OpenRead(soundFile));

            sadl.id = br.ReadChars(4);

            br.BaseStream.Position = 0x31;
            sadl.loopFlag          = br.ReadByte();
            sadl.channel           = br.ReadByte();

            byte coding = br.ReadByte();

            sadl.coding = (Coding)(coding & 0xF0);
            Console.WriteLine(xml.Element("S03").Value + ' ' + sadl.coding.ToString());
            switch (coding & 0x06)
            {
            case 4:
                sadl.sample_rate = 32728;
                break;

            case 2:
                sadl.sample_rate = 16364;
                break;
            }

            br.BaseStream.Position = 0x40;
            sadl.file_size         = br.ReadUInt32();

            uint startOffset = 0x100;

            if (sadl.coding == Coding.INT_IMA)
            {
                sadl.num_samples = (sadl.file_size - startOffset) / sadl.channel * 2;
            }
            else if (sadl.coding == Coding.NDS_PROCYON)
            {
                sadl.num_samples = (sadl.file_size - startOffset) / sadl.channel / 16 * 30;
            }

            sadl.interleave_block_size = 0x10;

            br.BaseStream.Position = 0x54;
            if (sadl.loopFlag != 0)
            {
                if (sadl.coding == Coding.INT_IMA)
                {
                    sadl.loopOffset = (br.ReadUInt32() - startOffset) / sadl.channel * 2;
                }
                else if (sadl.coding == Coding.NDS_PROCYON)
                {
                    sadl.loopOffset = (br.ReadUInt32() - startOffset) / sadl.channel / 16 * 30;
                }
            }

            // Set the data
            total_samples   = sadl.num_samples;
            sample_rate     = sadl.sample_rate;
            channels        = sadl.channel;
            block_size      = sadl.interleave_block_size;
            sample_bitdepth = 4;

            loop_enabled      = (sadl.loopFlag != 0 ? true : false);
            loop_begin_sample = sadl.loopOffset;
            loop_end_sample   = sadl.num_samples;

            br.BaseStream.Position = 0;
            byte[] buffer = br.ReadBytes((int)br.BaseStream.Length);

            br.Close();
            br = null;

            return(buffer);
        }
예제 #2
0
파일: SADL.cs 프로젝트: MetLob/tinke
        public override byte[] Read_File()
        {
            XElement xml = XElement.Load(Application.StartupPath + Path.DirectorySeparatorChar + "Plugins" +
                Path.DirectorySeparatorChar + "SoundLang.xml");
            xml = xml.Element(lang).Element("Messages");

            sadl = new sSADL();
            BinaryReader br = new BinaryReader(File.OpenRead(soundFile));

            sadl.id = br.ReadChars(4);

            br.BaseStream.Position = 0x31;
            sadl.loopFlag = br.ReadByte();
            sadl.channel = br.ReadByte();

            byte coding = br.ReadByte();
            sadl.coding = (Coding)(coding & 0xF0);
            Console.WriteLine(xml.Element("S03").Value + ' ' + sadl.coding.ToString());
            switch (coding & 0x06)
            {
                case 4:
                    sadl.sample_rate = 32728;
                    break;
                case 2:
                    sadl.sample_rate = 16364;
                    break;
            }

            br.BaseStream.Position = 0x40;
            sadl.file_size = br.ReadUInt32();

            uint startOffset = 0x100;
            if (sadl.coding == Coding.INT_IMA)
                sadl.num_samples = (sadl.file_size - startOffset) / sadl.channel * 2;
            else if (sadl.coding == Coding.NDS_PROCYON)
                sadl.num_samples = (sadl.file_size - startOffset) / sadl.channel / 16 * 30;

            sadl.interleave_block_size = 0x10;

            br.BaseStream.Position = 0x54;
            if (sadl.loopFlag != 0)
            {
                if (sadl.coding == Coding.INT_IMA)
                    sadl.loopOffset = (br.ReadUInt32() - startOffset) / sadl.channel * 2;
                else if (sadl.coding == Coding.NDS_PROCYON)
                    sadl.loopOffset = (br.ReadUInt32() - startOffset) / sadl.channel / 16 * 30;
            }

            // Set the data
            total_samples = sadl.num_samples;
            sample_rate = sadl.sample_rate;
            channels = sadl.channel;
            block_size = sadl.interleave_block_size;
            sample_bitdepth = 4;

            loop_enabled = (sadl.loopFlag != 0 ? true : false);
            loop_begin_sample = sadl.loopOffset;
            loop_end_sample = sadl.num_samples;

            br.BaseStream.Position = 0;
            byte[] buffer = br.ReadBytes((int)br.BaseStream.Length);

            br.Close();
            br = null;

            return buffer;
        }