Exemple #1
0
        /// <summary>
        /// Decompress the SWAR file in SWAV files.
        /// </summary>
        /// <param name="swar">SWAR structure to decompress</param>
        /// <returns>All the SWAV that are in it</returns>
        public static sSWAV[] ConvertToSWAV(sSWAR swar)
        {
            sSWAV[] swav = new sSWAV[swar.data.samples.Length];

            for (int i = 0; i < swav.Length; i++)
            {
                swav[i] = new sSWAV();

                swav[i].data.data  = swar.data.samples[i].data;
                swav[i].data.info  = swar.data.samples[i].info;
                swav[i].data.type  = new char[] { 'D', 'A', 'T', 'A' };
                swav[i].data.nSize = (uint)swav[i].data.data.Length + 1 * sizeof(uint) + 4 * sizeof(byte) + (2 * sizeof(byte) + 3 * sizeof(ushort) + sizeof(uint));

                swav[i].header.type      = new char[] { 'S', 'W', 'A', 'V' };
                swav[i].header.magic     = 0x0100feff;
                swav[i].header.nSize     = 16;
                swav[i].header.nBlock    = 1;
                swav[i].header.nFileSize = 16 + ((uint)swav[i].data.data.Length + 1 * sizeof(uint) + 4 * sizeof(byte) + (2 * sizeof(byte) + 3 * sizeof(ushort) + sizeof(uint)));
            }

            return(swav);
        }
Exemple #2
0
        public static Dictionary <String, String> Information(sSWAR swar, string lang)
        {
            Dictionary <String, String> info = new Dictionary <string, string>();

            try
            {
                System.Xml.Linq.XElement xml = System.Xml.Linq.XElement.Load(System.Windows.Forms.Application.StartupPath +
                                                                             Path.DirectorySeparatorChar + "Plugins" + Path.DirectorySeparatorChar + "SDATLang.xml");
                xml = xml.Element(lang).Element("Information");

                info.Add(xml.Element("S00").Value, xml.Element("S01").Value);
                info.Add(xml.Element("S02").Value, new String(swar.header.type));
                info.Add(xml.Element("S03").Value, "0x" + swar.header.magic.ToString("x"));
                info.Add(xml.Element("S04").Value, swar.header.nFileSize.ToString());

                info.Add(xml.Element("S05").Value, new String(swar.data.type));
                info.Add(xml.Element("S06").Value, swar.data.nSize.ToString());
                info.Add(xml.Element("S16").Value, swar.data.nSample.ToString());
            }
            catch { throw new Exception("There was an error reading the language file"); }

            return(info);
        }
Exemple #3
0
        /// <summary>
        /// Read a SWAR file and return a SWAR structure
        /// </summary>
        /// <param name="path">File to read</param>
        /// <returns>Structure of the file</returns>
        public static sSWAR Read(string path)
        {
            System.IO.FileStream   fs = null;
            System.IO.BinaryReader br = null;

            sSWAR swar = new sSWAR();

            try
            {
                fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
                br = new System.IO.BinaryReader(fs);

                // Common header
                swar.header.type      = Encoding.ASCII.GetChars(br.ReadBytes(4));
                swar.header.magic     = br.ReadUInt32();
                swar.header.nFileSize = br.ReadUInt32();
                swar.header.nSize     = br.ReadUInt16();
                swar.header.nBlock    = br.ReadUInt16();

                // DATA section
                swar.data.type     = Encoding.ASCII.GetChars(br.ReadBytes(4));
                swar.data.nSize    = br.ReadUInt32();
                swar.data.reserved = new uint[8];
                for (int i = 0; i < 8; i++)
                {
                    swar.data.reserved[i] = br.ReadUInt32();
                }
                swar.data.nSample = br.ReadUInt32();

                swar.data.nOffset = new uint[swar.data.nSample];
                for (int i = 0; i < swar.data.nSample; i++)
                {
                    swar.data.nOffset[i] = br.ReadUInt32();
                }

                swar.data.samples = new sSWAR.Data.Sample[swar.data.nSample];

                for (uint i = 0; i < swar.data.nSample; i++)
                {
                    // INFO structure
                    swar.data.samples[i].info.nWaveType   = br.ReadByte();
                    swar.data.samples[i].info.bLoop       = br.ReadByte();
                    swar.data.samples[i].info.nSampleRate = br.ReadUInt16();
                    swar.data.samples[i].info.nTime       = br.ReadUInt16();
                    swar.data.samples[i].info.nLoopOffset = br.ReadUInt16();
                    swar.data.samples[i].info.nNonLoopLen = br.ReadUInt32();

                    // Calculation of data size
                    if (i < swar.data.nOffset.Length - 1)
                    {
                        swar.data.samples[i].data = new byte[swar.data.nOffset[i + 1] - swar.data.nOffset[i] - /*SWAVInfo size ->*/ 12];
                    }
                    else
                    {
                        swar.data.samples[i].data = new byte[br.BaseStream.Length - swar.data.nOffset[i] - /*SWAVInfo size ->*/ 12];
                    }

                    // Read DATA
                    for (uint j = 0; j < swar.data.samples[i].data.Length; j++)
                    {
                        swar.data.samples[i].data[j] = br.ReadByte();
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
                if (br != null)
                {
                    br.Close();
                }
            }

            return(swar);
        }
Exemple #4
0
        /// <summary>
        /// Read a SWAR file and return a SWAR structure
        /// </summary>
        /// <param name="path">File to read</param>
        /// <returns>Structure of the file</returns>
        public static sSWAR Read(string path)
        {
            System.IO.FileStream fs = null;
            System.IO.BinaryReader br = null;

            sSWAR swar = new sSWAR();

            try
            {
                fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
                br = new System.IO.BinaryReader(fs);

                // Common header
                swar.header.type = Encoding.ASCII.GetChars(br.ReadBytes(4));
                swar.header.magic = br.ReadUInt32();
                swar.header.nFileSize = br.ReadUInt32();
                swar.header.nSize = br.ReadUInt16();
                swar.header.nBlock = br.ReadUInt16();

                // DATA section
                swar.data.type = Encoding.ASCII.GetChars(br.ReadBytes(4));
                swar.data.nSize = br.ReadUInt32();
                swar.data.reserved = new uint[8];
                for (int i = 0; i < 8; i++) { swar.data.reserved[i] = br.ReadUInt32(); }
                swar.data.nSample = br.ReadUInt32();

                swar.data.nOffset = new uint[swar.data.nSample];
                for (int i = 0; i < swar.data.nSample; i++) { swar.data.nOffset[i] = br.ReadUInt32(); }

                swar.data.samples = new sSWAR.Data.Sample[swar.data.nSample];

                for (uint i = 0; i < swar.data.nSample; i++)
                {
                    // INFO structure
                    swar.data.samples[i].info.nWaveType = br.ReadByte();
                    swar.data.samples[i].info.bLoop = br.ReadByte();
                    swar.data.samples[i].info.nSampleRate = br.ReadUInt16();
                    swar.data.samples[i].info.nTime = br.ReadUInt16();
                    swar.data.samples[i].info.nLoopOffset = br.ReadUInt16();
                    swar.data.samples[i].info.nNonLoopLen = br.ReadUInt32();

                    // Calculation of data size
                    if (i < swar.data.nOffset.Length - 1)
                    {
                        swar.data.samples[i].data = new byte[swar.data.nOffset[i + 1] - swar.data.nOffset[i] - /*SWAVInfo size ->*/12];
                    }
                    else
                    {
                        swar.data.samples[i].data = new byte[br.BaseStream.Length - swar.data.nOffset[i] - /*SWAVInfo size ->*/12];
                    }

                    // Read DATA
                    for (uint j = 0; j < swar.data.samples[i].data.Length; j++)
                    {
                        swar.data.samples[i].data[j] = br.ReadByte();
                    }

                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }
            finally
            {
                if (fs != null) fs.Close();
                if (br != null) br.Close();
            }

            return swar;
        }
Exemple #5
0
        public static Dictionary<String, String> Information(sSWAR swar, string lang)
        {
            Dictionary<String, String> info = new Dictionary<string, string>();

            try
            {
                System.Xml.Linq.XElement xml = System.Xml.Linq.XElement.Load(System.Windows.Forms.Application.StartupPath +
                    Path.DirectorySeparatorChar + "Plugins" + Path.DirectorySeparatorChar + "SDATLang.xml");
                xml = xml.Element(lang).Element("Information");

                info.Add(xml.Element("S00").Value, xml.Element("S01").Value);
                info.Add(xml.Element("S02").Value, new String(swar.header.type));
                info.Add(xml.Element("S03").Value, "0x" + swar.header.magic.ToString("x"));
                info.Add(xml.Element("S04").Value, swar.header.nFileSize.ToString());

                info.Add(xml.Element("S05").Value, new String(swar.data.type));
                info.Add(xml.Element("S06").Value, swar.data.nSize.ToString());
                info.Add(xml.Element("S16").Value, swar.data.nSample.ToString());
            }
            catch { throw new Exception("There was an error reading the language file"); }

            return info;
        }
Exemple #6
0
        /// <summary>
        /// Decompress the SWAR file in SWAV files.
        /// </summary>
        /// <param name="swar">SWAR structure to decompress</param>
        /// <returns>All the SWAV that are in it</returns>
        public static sSWAV[] ConvertToSWAV(sSWAR swar)
        {
            sSWAV[] swav = new sSWAV[swar.data.samples.Length];

            for (int i = 0; i < swav.Length; i++)
            {
                swav[i] = new sSWAV();

                swav[i].data.data = swar.data.samples[i].data;
                swav[i].data.info = swar.data.samples[i].info;
                swav[i].data.type = new char[] { 'D', 'A', 'T', 'A' };
                swav[i].data.nSize = (uint)swav[i].data.data.Length + 1 * sizeof(uint) + 4 * sizeof(byte) + (2 * sizeof(byte) + 3 * sizeof(ushort) + sizeof(uint));

                swav[i].header.type = new char[] { 'S', 'W', 'A', 'V' };
                swav[i].header.magic = 0x0100feff;
                swav[i].header.nSize = 16;
                swav[i].header.nBlock = 1;
                swav[i].header.nFileSize = 16 + ((uint)swav[i].data.data.Length + 1 * sizeof(uint) + 4 * sizeof(byte) + (2 * sizeof(byte) + 3 * sizeof(ushort) + sizeof(uint)));
            }

            return swav;
        }