Ejemplo n.º 1
0
        /// <summary>
        /// Write a STRM structure to a file
        /// </summary>
        /// <param name="strm">STRM structure to write</param>
        /// <param name="path">File to write</param>
        public static void Write(sSTRM strm, string path)
        {
            System.IO.FileStream   fs = null;
            System.IO.BinaryWriter bw = null;

            try
            {
                fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
                bw = new System.IO.BinaryWriter(fs);

                // Common header
                bw.Write(Encoding.ASCII.GetBytes(strm.cabecera.id));
                bw.Write(strm.cabecera.constant);
                bw.Write(strm.cabecera.fileSize);
                bw.Write(strm.cabecera.headerSize);
                bw.Write(strm.cabecera.nBlocks);

                // HEAD section
                bw.Write(Encoding.ASCII.GetBytes(strm.head.id));
                bw.Write(strm.head.size);
                bw.Write(strm.head.waveType);
                bw.Write(strm.head.loop);
                bw.Write(strm.head.channels);
                bw.Write(strm.head.sampleRate);
                bw.Write(strm.head.time);
                bw.Write(strm.head.loopOffset);
                bw.Write(strm.head.nSamples);
                bw.Write(strm.head.dataOffset);
                bw.Write(strm.head.nBlocks);
                bw.Write(strm.head.blockLen);
                bw.Write(strm.head.blockSample);
                bw.Write(strm.head.lastBlocklen);
                bw.Write(strm.head.lastBlockSample);
                bw.Write(strm.head.reserved);

                // DATA section
                bw.Write(Encoding.ASCII.GetBytes(strm.data.id));
                bw.Write(strm.data.size);
                bw.Write(strm.data.data);

                bw.Flush();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }
            finally
            {
                if (bw != null)
                {
                    bw.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the information of the structure in an string array
        /// </summary>
        /// <param name="strm">Structure to show</param>
        /// <returns>Information</returns>
        public static Dictionary <String, String> Information(sSTRM strm, 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(strm.cabecera.id));
                info.Add(xml.Element("S03").Value, strm.cabecera.constant.ToString());
                info.Add(xml.Element("S04").Value, strm.cabecera.fileSize.ToString());

                info.Add(xml.Element("S05").Value, new String(strm.head.id));
                info.Add(xml.Element("S06").Value, strm.head.size.ToString());
                info.Add(xml.Element("S07").Value, strm.head.waveType.ToString());
                info.Add(xml.Element("S08").Value, strm.head.loop.ToString());
                info.Add(xml.Element("S09").Value, "0x" + strm.head.loopOffset.ToString("x"));
                info.Add(xml.Element("S0A").Value, strm.head.channels.ToString());
                info.Add(xml.Element("S0B").Value, strm.head.sampleRate.ToString());
                info.Add(xml.Element("S0C").Value, strm.head.time.ToString());
                info.Add(xml.Element("S0D").Value, strm.head.nSamples.ToString());
                info.Add(xml.Element("S0E").Value, "0x" + strm.head.dataOffset.ToString("x"));
                info.Add(xml.Element("S0F").Value, strm.head.nBlocks.ToString());
                info.Add(xml.Element("S10").Value, strm.head.blockLen.ToString());
                info.Add(xml.Element("S11").Value, strm.head.blockSample.ToString());
                info.Add(xml.Element("S12").Value, strm.head.lastBlocklen.ToString());
                info.Add(xml.Element("S13").Value, strm.head.lastBlockSample.ToString());

                info.Add(xml.Element("S14").Value, new string(strm.data.id));
                info.Add(xml.Element("S15").Value, strm.data.size.ToString());
            }
            catch { throw new Exception("There was an error reading the language file"); }

            return(info);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Read a STRM file and return the structure
        /// </summary>
        /// <param name="path">File to read</param>
        /// <returns>Structure from the file</returns>
        public static sSTRM Read(string path)
        {
            sSTRM        strm = new sSTRM();
            BinaryReader br   = new BinaryReader(File.OpenRead(path));

            // Common header
            strm.cabecera.id         = br.ReadChars(4);
            strm.cabecera.constant   = br.ReadUInt32();
            strm.cabecera.fileSize   = br.ReadUInt32();
            strm.cabecera.headerSize = br.ReadUInt16();
            strm.cabecera.nBlocks    = br.ReadUInt16();
            // HEAD section
            strm.head.id              = br.ReadChars(4);
            strm.head.size            = br.ReadUInt32();
            strm.head.waveType        = br.ReadByte();
            strm.head.loop            = br.ReadByte();
            strm.head.channels        = br.ReadUInt16();
            strm.head.sampleRate      = br.ReadUInt16();
            strm.head.time            = br.ReadUInt16();
            strm.head.loopOffset      = br.ReadUInt32();
            strm.head.nSamples        = br.ReadUInt32();
            strm.head.dataOffset      = br.ReadUInt32();
            strm.head.nBlocks         = br.ReadUInt32();
            strm.head.blockLen        = br.ReadUInt32();
            strm.head.blockSample     = br.ReadUInt32();
            strm.head.lastBlocklen    = br.ReadUInt32();
            strm.head.lastBlockSample = br.ReadUInt32();
            br.ReadBytes(32); // Reserved
            // DATA section
            strm.data.id   = br.ReadChars(4);
            strm.data.size = br.ReadUInt32();
            strm.data.data = br.ReadBytes((int)strm.data.size - 0x08);

            br.Close();

            return(strm);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Convert a WAV structure to a STRM structure
        /// </summary>
        /// <param name="wav">WAV structure to convert</param>
        /// <returns>STRM structure converted</returns>
        public static sSTRM ConvertToSTRM(sWAV wav, int waveType, int blockSize = 0x200)
        {
            if (blockSize <= 0)
            {
                blockSize = 0x200;
            }

            if (waveType == 2)
            {
                blockSize -= 4; // compression info
                blockSize *= 4; // 4-bit
            }
            else if (waveType == 0)
            {
                blockSize *= 2; // 8-bit
            }
            sSTRM strm = new sSTRM();

            strm.cabecera.id         = "STRM".ToArray();
            strm.cabecera.constant   = 0x0100FEFF;
            strm.cabecera.headerSize = 0x10;
            strm.cabecera.nBlocks    = 0x02;

            strm.head.id         = "HEAD".ToArray();
            strm.head.size       = 0x50;
            strm.head.waveType   = (byte)waveType;
            strm.head.loop       = 1;
            strm.head.channels   = wav.wave.fmt.numChannels;
            strm.head.sampleRate = (ushort)wav.wave.fmt.sampleRate;
            strm.head.time       = (ushort)(1.0 / strm.head.sampleRate * 1.6756991e+7 / 32);
            strm.head.loopOffset = 0x00;
            strm.head.dataOffset = 0x68;
            strm.head.reserved   = new Byte[32];

            strm.data.id = "DATA".ToArray();

            if (wav.wave.fmt.numChannels == 2)
            {
                strm.data.leftChannel  = DivideChannels(wav.wave.data.data, true);
                strm.data.rightChannel = DivideChannels(wav.wave.data.data, false);
                byte[][] leftBlock  = CreateBlocks(strm.data.leftChannel, blockSize, waveType);
                byte[][] rigthBlock = CreateBlocks(strm.data.rightChannel, blockSize, waveType);
                strm.data.data = MergeBlocks(leftBlock, rigthBlock);

                strm.head.blockLen     = (uint)leftBlock[0].Length;
                strm.head.lastBlocklen = (uint)leftBlock[leftBlock.Length - 1].Length;
                strm.head.nBlocks      = (uint)leftBlock.Length;
            }
            else
            {
                byte[][]    blocks = CreateBlocks(wav.wave.data.data, blockSize, waveType);
                List <byte> data   = new List <byte>();
                for (int i = 0; i < blocks.Length; i++)
                {
                    data.AddRange(blocks[i]);
                }
                strm.data.data = data.ToArray();

                strm.head.blockLen     = (uint)blocks[0].Length;
                strm.head.lastBlocklen = (uint)blocks[blocks.Length - 1].Length;
                strm.head.nBlocks      = (uint)blocks.Length;
            }

            if (waveType == 2)
            {
                strm.head.blockSample     = (strm.head.blockLen - 4) * 2;
                strm.head.lastBlockSample = (strm.head.lastBlocklen - 4) * 2;
            }
            else if (waveType == 1)
            {
                strm.head.blockSample     = strm.head.blockLen / 2;
                strm.head.lastBlockSample = strm.head.lastBlocklen / 2;
            }
            else if (waveType == 0)
            {
                strm.head.blockSample     = strm.head.blockLen;
                strm.head.lastBlockSample = strm.head.lastBlocklen;
            }
            strm.head.nSamples = (strm.head.nBlocks - 1) * strm.head.blockSample + strm.head.lastBlockSample;


            strm.data.size         = (uint)strm.data.data.Length + 0x08;
            strm.cabecera.fileSize = strm.data.size + strm.head.size + strm.cabecera.headerSize;

            return(strm);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Convert a STRM structure to a WAV structure
        /// </summary>
        /// <param name="strm">STRM structure to convert</param>
        /// <param name="loop">If true, the new WAV data will start in the loop offset</param>
        /// <returns>WAV structure converted</returns>
        public static sWAV ConvertToWAV(sSTRM strm, bool loop)
        {
            sWAV wav = new sWAV();

            // Get the audio data
            if (strm.head.channels == 2)
            {
                // Get both channels and convert it to PCM-16
                strm.data.leftChannel = DivideChannels(strm.data.data, strm.head.nBlocks, strm.head.blockLen,
                                                       strm.head.lastBlocklen, true, strm.head.waveType);
                strm.data.rightChannel = DivideChannels(strm.data.data, strm.head.nBlocks, strm.head.blockLen,
                                                        strm.head.lastBlocklen, false, strm.head.waveType);
                Array.Clear(strm.data.data, 0, strm.data.data.Length);

                if (loop && strm.head.waveType == 0) // 8 bits per sample
                {
                    strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel, (int)strm.head.loopOffset);
                }
                else if (loop && strm.head.waveType == 2) // 4 bits per sample
                {
                    strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel, (int)strm.head.loopOffset * 2);
                }
                else if (loop && strm.head.waveType == 1) // 16 bits per sample (NO TESTED)
                {
                    strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel, (int)strm.head.loopOffset);
                }
                else // No loop
                {
                    strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel);
                }
            }
            else if (strm.head.channels == 1)
            {
                // Get the channel and convert it to PCM-16
                strm.data.data = MonoChannel(strm.data.data, strm.head.nBlocks, strm.head.blockLen,
                                             strm.head.lastBlocklen, strm.head.waveType);

                if (strm.head.waveType == 0 && loop) // 8 bits per sample
                {
                    Byte[] data = new Byte[strm.data.data.Length - (int)strm.head.loopOffset];
                    Array.Copy(strm.data.data, strm.head.loopOffset, data, 0, data.Length);
                    strm.data.data = data;
                }
                else if (loop && strm.head.waveType == 2) // 4 bits per sample
                {
                    Byte[] data = new Byte[strm.data.data.Length - ((int)strm.head.loopOffset * 2)];
                    Array.Copy(strm.data.data, strm.head.loopOffset * 2, data, 0, data.Length);
                    strm.data.data = data;
                }
                else if (loop && strm.head.waveType == 1) // 16-bits per sample (NO TESTED)
                {
                    Byte[] data = new Byte[strm.data.data.Length - (int)strm.head.loopOffset];
                    Array.Copy(strm.data.data, strm.head.loopOffset, data, 0, data.Length);
                    strm.data.data = data;
                }
            }

            // Create the WAV structure from the STRM data
            wav = WAV.Create_WAV(strm.head.channels, strm.head.sampleRate, 16, strm.data.data);

            return(wav);
        }
Ejemplo n.º 6
0
Archivo: STRM.cs Proyecto: MetLob/tinke
        /// <summary>
        /// Write a STRM structure to a file
        /// </summary>
        /// <param name="strm">STRM structure to write</param>
        /// <param name="path">File to write</param>
        public static void Write(sSTRM strm, string path)
        {
            System.IO.FileStream fs = null;
            System.IO.BinaryWriter bw = null;

            try
            {
                fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
                bw = new System.IO.BinaryWriter(fs);

                // Common header
                bw.Write(Encoding.ASCII.GetBytes(strm.cabecera.id));
                bw.Write(strm.cabecera.constant);
                bw.Write(strm.cabecera.fileSize);
                bw.Write(strm.cabecera.headerSize);
                bw.Write(strm.cabecera.nBlocks);

                // HEAD section
                bw.Write(Encoding.ASCII.GetBytes(strm.head.id));
                bw.Write(strm.head.size);
                bw.Write(strm.head.waveType);
                bw.Write(strm.head.loop);
                bw.Write(strm.head.channels);
                bw.Write(strm.head.sampleRate);
                bw.Write(strm.head.time);
                bw.Write(strm.head.loopOffset);
                bw.Write(strm.head.nSamples);
                bw.Write(strm.head.dataOffset);
                bw.Write(strm.head.nBlocks);
                bw.Write(strm.head.blockLen);
                bw.Write(strm.head.blockSample);
                bw.Write(strm.head.lastBlocklen);
                bw.Write(strm.head.lastBlockSample);
                bw.Write(strm.head.reserved);

                // DATA section
                bw.Write(Encoding.ASCII.GetBytes(strm.data.id));
                bw.Write(strm.data.size);
                bw.Write(strm.data.data);

                bw.Flush();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }
            finally
            {
                if (bw != null) bw.Close();
                if (fs != null) fs.Close();
            }
        }
Ejemplo n.º 7
0
Archivo: STRM.cs Proyecto: MetLob/tinke
        /// <summary>
        /// Read a STRM file and return the structure
        /// </summary>
        /// <param name="path">File to read</param>
        /// <returns>Structure from the file</returns>
        public static sSTRM Read(string path)
        {
            sSTRM strm = new sSTRM();
            BinaryReader br = new BinaryReader(File.OpenRead(path));

            // Common header
            strm.cabecera.id = br.ReadChars(4);
            strm.cabecera.constant = br.ReadUInt32();
            strm.cabecera.fileSize = br.ReadUInt32();
            strm.cabecera.headerSize = br.ReadUInt16();
            strm.cabecera.nBlocks = br.ReadUInt16();
            // HEAD section
            strm.head.id = br.ReadChars(4);
            strm.head.size = br.ReadUInt32();
            strm.head.waveType = br.ReadByte();
            strm.head.loop = br.ReadByte();
            strm.head.channels = br.ReadUInt16();
            strm.head.sampleRate = br.ReadUInt16();
            strm.head.time = br.ReadUInt16();
            strm.head.loopOffset = br.ReadUInt32();
            strm.head.nSamples = br.ReadUInt32();
            strm.head.dataOffset = br.ReadUInt32();
            strm.head.nBlocks = br.ReadUInt32();
            strm.head.blockLen = br.ReadUInt32();
            strm.head.blockSample = br.ReadUInt32();
            strm.head.lastBlocklen = br.ReadUInt32();
            strm.head.lastBlockSample = br.ReadUInt32();
            br.ReadBytes(32); // Reserved
            // DATA section
            strm.data.id = br.ReadChars(4);
            strm.data.size = br.ReadUInt32();
            strm.data.data = br.ReadBytes((int)strm.data.size - 0x08);

            br.Close();

            return strm;
        }
Ejemplo n.º 8
0
Archivo: STRM.cs Proyecto: MetLob/tinke
        /// <summary>
        /// Get the information of the structure in an string array
        /// </summary>
        /// <param name="strm">Structure to show</param>
        /// <returns>Information</returns>
        public static Dictionary<String, String> Information(sSTRM strm, 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(strm.cabecera.id));
                info.Add(xml.Element("S03").Value, strm.cabecera.constant.ToString());
                info.Add(xml.Element("S04").Value, strm.cabecera.fileSize.ToString());

                info.Add(xml.Element("S05").Value, new String(strm.head.id));
                info.Add(xml.Element("S06").Value, strm.head.size.ToString());
                info.Add(xml.Element("S07").Value, strm.head.waveType.ToString());
                info.Add(xml.Element("S08").Value, strm.head.loop.ToString());
                info.Add(xml.Element("S09").Value, "0x" + strm.head.loopOffset.ToString("x"));
                info.Add(xml.Element("S0A").Value, strm.head.channels.ToString());
                info.Add(xml.Element("S0B").Value, strm.head.sampleRate.ToString());
                info.Add(xml.Element("S0C").Value, strm.head.time.ToString());
                info.Add(xml.Element("S0D").Value, strm.head.nSamples.ToString());
                info.Add(xml.Element("S0E").Value, "0x" + strm.head.dataOffset.ToString("x"));
                info.Add(xml.Element("S0F").Value, strm.head.nBlocks.ToString());
                info.Add(xml.Element("S10").Value, strm.head.blockLen.ToString());
                info.Add(xml.Element("S11").Value, strm.head.blockSample.ToString());
                info.Add(xml.Element("S12").Value, strm.head.lastBlocklen.ToString());
                info.Add(xml.Element("S13").Value, strm.head.lastBlockSample.ToString());

                info.Add(xml.Element("S14").Value, new string(strm.data.id));
                info.Add(xml.Element("S15").Value, strm.data.size.ToString());
            }
            catch { throw new Exception("There was an error reading the language file"); }

            return info;
        }
Ejemplo n.º 9
0
Archivo: STRM.cs Proyecto: MetLob/tinke
        /// <summary>
        /// Convert a STRM structure to a WAV structure
        /// </summary>
        /// <param name="strm">STRM structure to convert</param>
        /// <param name="loop">If true, the new WAV data will start in the loop offset</param>
        /// <returns>WAV structure converted</returns>
        public static sWAV ConvertToWAV(sSTRM strm, bool loop)
        {
            sWAV wav = new sWAV();

            // Get the audio data
            if (strm.head.channels == 2)
            {
                // Get both channels and convert it to PCM-16
                strm.data.leftChannel = DivideChannels(strm.data.data, strm.head.nBlocks, strm.head.blockLen,
                    strm.head.lastBlocklen, true, strm.head.waveType);
                strm.data.rightChannel = DivideChannels(strm.data.data, strm.head.nBlocks, strm.head.blockLen,
                    strm.head.lastBlocklen, false, strm.head.waveType);
                Array.Clear(strm.data.data, 0, strm.data.data.Length);

                if (loop && strm.head.waveType == 0) // 8 bits per sample
                    strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel, (int)strm.head.loopOffset);
                else if (loop && strm.head.waveType == 2) // 4 bits per sample
                    strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel, (int)strm.head.loopOffset * 2);
                else if (loop && strm.head.waveType == 1) // 16 bits per sample (NO TESTED)
                    strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel, (int)strm.head.loopOffset);
                else // No loop
                    strm.data.data = MergeChannels(strm.data.leftChannel, strm.data.rightChannel);
            }
            else if (strm.head.channels == 1)
            {
                // Get the channel and convert it to PCM-16
                strm.data.data = MonoChannel(strm.data.data, strm.head.nBlocks, strm.head.blockLen,
                    strm.head.lastBlocklen, strm.head.waveType);

                if (strm.head.waveType == 0 && loop) // 8 bits per sample
                {
                    Byte[] data = new Byte[strm.data.data.Length - (int)strm.head.loopOffset];
                    Array.Copy(strm.data.data, strm.head.loopOffset, data, 0, data.Length);
                    strm.data.data = data;
                }
                else if (loop && strm.head.waveType == 2) // 4 bits per sample
                {
                    Byte[] data = new Byte[strm.data.data.Length - ((int)strm.head.loopOffset * 2)];
                    Array.Copy(strm.data.data, strm.head.loopOffset * 2, data, 0, data.Length);
                    strm.data.data = data;
                }
                else if (loop && strm.head.waveType == 1) // 16-bits per sample (NO TESTED)
                {
                    Byte[] data = new Byte[strm.data.data.Length - (int)strm.head.loopOffset];
                    Array.Copy(strm.data.data, strm.head.loopOffset, data, 0, data.Length);
                    strm.data.data = data;
                }
            }

            // Create the WAV structure from the STRM data
            wav = WAV.Create_WAV(strm.head.channels, strm.head.sampleRate, 16, strm.data.data);

            return wav;
        }
Ejemplo n.º 10
0
Archivo: STRM.cs Proyecto: MetLob/tinke
        /// <summary>
        /// Convert a WAV structure to a STRM structure
        /// </summary>
        /// <param name="wav">WAV structure to convert</param>
        /// <returns>STRM structure converted</returns>
        public static sSTRM ConvertToSTRM(sWAV wav, int waveType, int blockSize = 0x200)
        {
            if (blockSize <= 0)
                blockSize = 0x200;

            if (waveType == 2)
            {
                blockSize -= 4; // compression info
                blockSize *= 4;  // 4-bit
            }
            else if (waveType == 0)
                blockSize *= 2; // 8-bit

            sSTRM strm = new sSTRM();
            strm.cabecera.id = "STRM".ToArray();
            strm.cabecera.constant = 0x0100FEFF;
            strm.cabecera.headerSize = 0x10;
            strm.cabecera.nBlocks = 0x02;

            strm.head.id = "HEAD".ToArray();
            strm.head.size = 0x50;
            strm.head.waveType = (byte)waveType;
            strm.head.loop = 1;
            strm.head.channels = wav.wave.fmt.numChannels;
            strm.head.sampleRate = (ushort)wav.wave.fmt.sampleRate;
            strm.head.time = (ushort)(1.0 / strm.head.sampleRate * 1.6756991e+7 / 32);
            strm.head.loopOffset = 0x00;
            strm.head.dataOffset = 0x68;
            strm.head.reserved = new Byte[32];

            strm.data.id = "DATA".ToArray();

            if (wav.wave.fmt.numChannels == 2)
            {
                strm.data.leftChannel = DivideChannels(wav.wave.data.data, true);
                strm.data.rightChannel = DivideChannels(wav.wave.data.data, false);
                byte[][] leftBlock = CreateBlocks(strm.data.leftChannel, blockSize, waveType);
                byte[][] rigthBlock = CreateBlocks(strm.data.rightChannel, blockSize, waveType);
                strm.data.data = MergeBlocks(leftBlock, rigthBlock);

                strm.head.blockLen = (uint)leftBlock[0].Length;
                strm.head.lastBlocklen = (uint)leftBlock[leftBlock.Length - 1].Length;
                strm.head.nBlocks = (uint)leftBlock.Length;
            }
            else
            {
                byte[][] blocks = CreateBlocks(wav.wave.data.data, blockSize, waveType);
                List<byte> data = new List<byte>();
                for (int i = 0; i < blocks.Length; i++)
                    data.AddRange(blocks[i]);
                strm.data.data = data.ToArray();

                strm.head.blockLen = (uint)blocks[0].Length;
                strm.head.lastBlocklen = (uint)blocks[blocks.Length - 1].Length;
                strm.head.nBlocks = (uint)blocks.Length;
            }

            if (waveType == 2)
            {
                strm.head.blockSample = (strm.head.blockLen - 4) * 2;
                strm.head.lastBlockSample = (strm.head.lastBlocklen - 4) * 2;
            }
            else if (waveType == 1)
            {
                strm.head.blockSample = strm.head.blockLen / 2;
                strm.head.lastBlockSample = strm.head.lastBlocklen / 2;
            }
            else if (waveType == 0)
            {
                strm.head.blockSample = strm.head.blockLen;
                strm.head.lastBlockSample = strm.head.lastBlocklen;
            }
            strm.head.nSamples = (strm.head.nBlocks - 1) * strm.head.blockSample + strm.head.lastBlockSample;

            strm.data.size = (uint)strm.data.data.Length + 0x08;
            strm.cabecera.fileSize = strm.data.size + strm.head.size + strm.cabecera.headerSize;

            return strm;
        }
Ejemplo n.º 11
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            Sound  selectedFile = SearchFile();
            String fileout      = pluginHost.Get_TempFolder() + Path.DirectorySeparatorChar + Path.GetRandomFileName();

            OpenFileDialog o = new OpenFileDialog();

            o.CheckFileExists = true;
            o.AddExtension    = true;
            o.DefaultExt      = "wav";
            o.Filter          = "WAVE audio format (*.wav)|*.wav";
            if (o.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            String filein = o.FileName;

            sWAV wav = new sWAV();

            try { wav = WAV.Read(filein); }
            catch (Exception ex) { MessageBox.Show(ex.Message); return; }

            NewAudioOptions dialog = new NewAudioOptions(pluginHost, (selectedFile.type == FormatSound.SWAV ? true : false));

            switch (selectedFile.type)
            {
            case FormatSound.STRM:
                sSTRM oldStrm = STRM.Read(SaveFile());
                dialog.Compression = oldStrm.head.waveType;
                dialog.BlockSize   = (int)oldStrm.head.blockLen;
                dialog.Loop        = (oldStrm.head.loop != 0 ? true : false);
                dialog.LoopOffset  = (int)oldStrm.head.loopOffset;
                dialog.SampleRate  = (int)wav.wave.fmt.sampleRate;
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                sSTRM strm = STRM.ConvertToSTRM(wav, dialog.Compression);
                strm.head.loop       = (byte)(dialog.Loop ? 0x01 : 0x00);
                strm.head.loopOffset = (uint)dialog.LoopOffset;

                STRM.Write(strm, fileout);
                break;

            case FormatSound.SWAV:
                sSWAV oldSwav = SWAV.Read(SaveFile());
                dialog.Compression = oldSwav.data.info.nWaveType;
                dialog.Loop        = (oldSwav.data.info.bLoop != 0 ? true : false);
                dialog.LoopLength  = (int)oldSwav.data.info.nNonLoopLen;
                dialog.LoopOffset  = (int)oldSwav.data.info.nLoopOffset;
                dialog.SampleRate  = (int)wav.wave.fmt.sampleRate;
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                sSWAV swav = SWAV.ConvertToSWAV(wav, dialog.Compression, dialog.Volume);

                swav.data.info.bLoop       = (byte)(dialog.Loop ? 0x01 : 0x00);
                swav.data.info.nLoopOffset = (ushort)dialog.LoopOffset;
                swav.data.info.nNonLoopLen = (uint)dialog.LoopLength;

                SWAV.Write(swav, fileout);
                break;

            case FormatSound.SSEQ:
            case FormatSound.SSAR:
            case FormatSound.SBNK:
            case FormatSound.SWAR:
            default:
                break;
            }

            if (!File.Exists(fileout))
            {
                return;
            }
            ChangeFile((int)selectedFile.id, fileout);
        }