コード例 #1
0
        public static Dictionary <String, String> Information(sSWAV swav, 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(swav.header.type));
                info.Add(xml.Element("S03").Value, "0x" + swav.header.magic.ToString("x"));
                info.Add(xml.Element("S04").Value, swav.header.nFileSize.ToString());

                info.Add(xml.Element("S05").Value, xml.Element("S17").Value);
                info.Add(xml.Element("S07").Value, swav.data.info.nWaveType.ToString());
                info.Add(xml.Element("S08").Value, swav.data.info.bLoop.ToString());
                info.Add(xml.Element("S09").Value, "0x" + swav.data.info.nLoopOffset.ToString("x"));
                info.Add(xml.Element("S18").Value, "0x" + swav.data.info.nNonLoopLen.ToString("x"));
                info.Add(xml.Element("S0B").Value, swav.data.info.nSampleRate.ToString());
                info.Add(xml.Element("S0C").Value, swav.data.info.nTime.ToString());

                info.Add(xml.Element("S14").Value, new String(swav.data.type));
                info.Add(xml.Element("S15").Value, swav.data.nSize.ToString());
            }
            catch { throw new Exception("There was an error reading the language file"); }

            return(info);
        }
コード例 #2
0
        public static sSWAV Read(string path)
        {
            /***Lectura del archivo SWAV***/
            System.IO.FileStream   fs = null;
            System.IO.BinaryReader br = null;

            sSWAV swav = new sSWAV();

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

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

                //Leer Data
                swav.data.type  = Encoding.ASCII.GetChars(br.ReadBytes(4));
                swav.data.nSize = br.ReadUInt32();
                {//Leer Info
                    swav.data.info.nWaveType   = br.ReadByte();
                    swav.data.info.bLoop       = br.ReadByte();
                    swav.data.info.nSampleRate = br.ReadUInt16();
                    swav.data.info.nTime       = br.ReadUInt16();
                    swav.data.info.nLoopOffset = br.ReadUInt16();
                    swav.data.info.nNonLoopLen = br.ReadUInt32();
                }
                //Leer resto de Data
                uint tamañoDatos = (uint)(br.BaseStream.Length - br.BaseStream.Position);
                swav.data.data = br.ReadBytes((int)tamañoDatos);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
                if (br != null)
                {
                    br.Close();
                }
            }

            return(swav);
        }
コード例 #3
0
        public static void Write(sSWAV swav, 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);

                //Escribir Header
                bw.Write(Encoding.ASCII.GetBytes(swav.header.type));
                bw.Write(swav.header.magic);
                bw.Write(swav.header.nFileSize);
                bw.Write(swav.header.nSize);
                bw.Write(swav.header.nBlock);

                //Escribir Data
                bw.Write(Encoding.ASCII.GetBytes(swav.data.type));
                bw.Write(swav.data.nSize);

                //Escribir Info
                bw.Write(swav.data.info.nWaveType);
                bw.Write(swav.data.info.bLoop);
                bw.Write(swav.data.info.nSampleRate);
                bw.Write(swav.data.info.nTime);
                bw.Write(swav.data.info.nLoopOffset);
                bw.Write(swav.data.info.nNonLoopLen);

                //Escribir data
                bw.Write(swav.data.data);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
                if (bw != null)
                {
                    bw.Close();
                }
            }
        }
コード例 #4
0
        public static sWAV ConvertToWAV(sSWAV swav, bool loop)
        {
            sWAV wav = new sWAV();

            if (swav.data.info.nWaveType == 0) // 8 Bits per sample, PCM-8
            {
                swav.data.data = PCM.PCM8SignedToPCM16(swav.data.data);
                if (loop)
                {
                    Byte[] data = new Byte[(int)swav.data.info.nNonLoopLen];
                    Array.Copy(swav.data.data, swav.data.info.nLoopOffset, data, 0, data.Length);
                    swav.data.data = data;
                }

                wav = WAV.Create_WAV(1, swav.data.info.nSampleRate, 16, swav.data.data);
            }
            else if (swav.data.info.nWaveType == 1) // 16 Bits per sample, PCM-16
            {
                if (loop)                           // NO TESTED
                {
                    Byte[] data = new Byte[(int)swav.data.info.nNonLoopLen];
                    Array.Copy(swav.data.data, swav.data.info.nLoopOffset, data, 0, data.Length);
                    swav.data.data = data;
                }

                wav = WAV.Create_WAV(1, swav.data.info.nSampleRate, 16, swav.data.data);
            }
            else if (swav.data.info.nWaveType >= 2) // 4 Bits per sample, IMA-ADPCM
            {
                swav.data.data = Compression_ADPCM.Decompress(
                    swav.data.data,
                    BitConverter.ToUInt16(swav.data.data, 0),
                    BitConverter.ToUInt16(swav.data.data, 2));

                if (loop)
                {
                    Byte[] data = new Byte[swav.data.data.Length - ((int)swav.data.info.nLoopOffset * 2)];
                    Array.Copy(swav.data.data, swav.data.info.nLoopOffset * 2, data, 0, data.Length);
                    swav.data.data = data;
                }

                wav = WAV.Create_WAV(1, swav.data.info.nSampleRate, 16, swav.data.data);
            }
            return(wav);
        }
コード例 #5
0
        public static sSWAV ConvertToSWAV(sWAV wav, int waveType, int volume = 150)
        {
            sSWAV swav = new sSWAV();

            swav.header.type   = "SWAV".ToCharArray();
            swav.header.magic  = 0x0100FEFF;
            swav.header.nSize  = 0x10;
            swav.header.nBlock = 0x01;

            swav.data.type             = "DATA".ToCharArray();
            swav.data.info.nWaveType   = (byte)waveType;
            swav.data.info.bLoop       = 1;
            swav.data.info.nSampleRate = (ushort)wav.wave.fmt.sampleRate;
            swav.data.info.nTime       = (ushort)(1.6756991e+7 / wav.wave.fmt.sampleRate);
            swav.data.info.nLoopOffset = 0x01;

            if (wav.wave.fmt.numChannels > 1)
            {
                wav.wave.data.data = WAV.ConvertToMono(wav.wave.data.data, wav.wave.fmt.numChannels, wav.wave.fmt.bitsPerSample);
            }

            //wav.wave.data.data = ChangeVolume(wav.wave.data.data, volume, wav.wave.fmt.bitsPerSample);
            if (waveType == 0)
            {
                swav.data.data = PCM.PCM16ToPCM8(wav.wave.data.data);
            }
            else if (waveType == 2)
            {
                List <byte> temp = new List <byte>();
                temp.AddRange(new Byte[] { 0x00, 0x00, 0x00, 0x00 });
                temp.AddRange(Compression_ADPCM.Compress(wav.wave.data.data));
                swav.data.data = temp.ToArray();
            }
            else
            {
                swav.data.data = wav.wave.data.data;
            }

            swav.data.nSize            = (uint)swav.data.data.Length + 0x0A;
            swav.data.info.nNonLoopLen = (uint)swav.data.data.Length;
            swav.header.nFileSize      = swav.data.nSize + swav.header.nSize;

            return(swav);
        }
コード例 #6
0
ファイル: SWAR.cs プロジェクト: calvarado194/layton-rando
        /// <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);
        }
コード例 #7
0
ファイル: iSDAT.cs プロジェクト: calvarado194/layton-rando
        private void btnUncompress_Click(object sender, EventArgs e)
        {
            System.Xml.Linq.XElement xml = System.Xml.Linq.XElement.Load(Application.StartupPath + Path.DirectorySeparatorChar +
                                                                         "Plugins" + Path.DirectorySeparatorChar + "SDATLang.xml");
            xml = xml.Element(pluginHost.Get_Language());
            xml = xml.Element("iSDAT");

            if (btnUncompress.Text == xml.Element("S07").Value)
            {
                #region Unpack SWAR file
                string swar = SaveFile();

                sSWAV[]  archivos = SWAR.ConvertToSWAV(SWAR.Read(swar));
                string[] swav     = new string[archivos.Length];

                Folder carpeta = new Folder();
                carpeta.name  = SearchFile().name;
                carpeta.files = new List <Sound>();

                for (int i = 0; i < archivos.Length; i++)
                {
                    swav[i] = pluginHost.Get_TempFolder() + '\\' + Path.GetRandomFileName();
                    SWAV.Write(archivos[i], swav[i]);

                    Sound newSound = new Sound();
                    newSound.id = lastFileID;
                    lastFileID++;
                    newSound.internalID = newSound.id;
                    newSound.name       = "SWAV_" + i.ToString() + ".swav";
                    newSound.offset     = 0x00;
                    newSound.type       = FormatSound.SWAV;
                    newSound.path       = swav[i];
                    newSound.size       = (uint)new FileInfo(swav[i]).Length;

                    carpeta.files.Add(newSound);
                }

                // Lo añadimos al nodo
                Add_Files(ref carpeta, (int)SearchFile().id);

                TreeNode selected = treeFiles.SelectedNode;
                selected = CarpetaToNodo(carpeta);

                // Agregamos los nodos al árbol
                TreeNode[] nodos = new TreeNode[selected.Nodes.Count];
                selected.Nodes.CopyTo(nodos, 0);
                treeFiles.SelectedNode.Tag = selected.Tag;
                selected.Nodes.Clear();

                treeFiles.SelectedNode.Nodes.AddRange((TreeNode[])nodos);
                treeFiles.SelectedNode.Expand();
                #endregion
                btnUncompress.Text = xml.Element("S12").Value;
            }
            else
            {
                #region Pack SWAR file
                Folder       swar   = SearchFolder(Convert.ToInt32(treeFiles.SelectedNode.Tag), sdat.files.root);
                List <sSWAV> sounds = new List <sSWAV>();

                for (int i = 0; i < swar.files.Count; i++)
                {
                    String tempFile = SaveFile((int)swar.files[i].id);
                    sSWAV  swav     = SWAV.Read(tempFile);
                    sounds.Add(swav);
                    File.Delete(tempFile);
                }

                String fileout = Path.GetTempFileName();
                SWAR.Write(sounds.ToArray(), fileout);
                ChangeFile(Convert.ToInt32(treeFiles.SelectedNode.Tag), fileout);
                #endregion
            }
        }
コード例 #8
0
ファイル: iSDAT.cs プロジェクト: calvarado194/layton-rando
        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);
        }
コード例 #9
0
ファイル: SWAR.cs プロジェクト: MetLob/tinke
        /// <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;
        }
コード例 #10
0
ファイル: SWAR.cs プロジェクト: MetLob/tinke
        public static void Write(sSWAV[] sounds, string fileout)
        {
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileout));
            uint file_size = (uint)(0x10 + 0x10 + 0x04 * sounds.Length);
            for (int i = 0; i < sounds.Length; i++)
                file_size += (uint)sounds[i].data.data.Length + 0x0A;

            bw.Write(new char[] { 'S', 'W', 'A', 'R' });
            bw.Write((uint)0x0100FEFF);
            bw.Write(file_size);
            bw.Write((ushort)0x10);
            bw.Write((ushort)0x01);

            bw.Write(new char[] { 'D', 'A', 'T', 'A' });
            bw.Write((uint)(file_size - 0x10));
            for (int i = 0; i < 8; i++)
                bw.Write((uint)0x00);
            bw.Write((uint)sounds.Length);

            // Write offset
            uint currOffset = (uint)(0x3C + 0x04 * sounds.Length);
            for (int i = 0; i < sounds.Length; i++)
            {
                bw.Write(currOffset);
                currOffset += (uint)sounds[i].data.data.Length + 0x0A;
            }

            // Write data
            for (int i = 0; i < sounds.Length; i++)
            {
                bw.Write(sounds[i].data.info.nWaveType);
                bw.Write(sounds[i].data.info.bLoop);
                bw.Write(sounds[i].data.info.nSampleRate);
                bw.Write(sounds[i].data.info.nTime);
                bw.Write(sounds[i].data.info.nLoopOffset);
                bw.Write(sounds[i].data.info.nNonLoopLen);
                bw.Write(sounds[i].data.data);
            }

            bw.Flush();
            bw.Close();
        }
コード例 #11
0
ファイル: SWAV.cs プロジェクト: MetLob/tinke
        public static void Write(sSWAV swav, 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);

                //Escribir Header
                bw.Write(Encoding.ASCII.GetBytes(swav.header.type));
                bw.Write(swav.header.magic);
                bw.Write(swav.header.nFileSize);
                bw.Write(swav.header.nSize);
                bw.Write(swav.header.nBlock);

                //Escribir Data
                bw.Write(Encoding.ASCII.GetBytes(swav.data.type));
                bw.Write(swav.data.nSize);

                //Escribir Info
                bw.Write(swav.data.info.nWaveType);
                bw.Write(swav.data.info.bLoop);
                bw.Write(swav.data.info.nSampleRate);
                bw.Write(swav.data.info.nTime);
                bw.Write(swav.data.info.nLoopOffset);
                bw.Write(swav.data.info.nNonLoopLen);

                //Escribir data
                bw.Write(swav.data.data);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }
            finally
            {
                if (fs != null) fs.Close();
                if (bw != null) bw.Close();
            }
        }
コード例 #12
0
ファイル: SWAV.cs プロジェクト: MetLob/tinke
        public static sSWAV Read(string path)
        {
            /***Lectura del archivo SWAV***/
            System.IO.FileStream fs = null;
            System.IO.BinaryReader br = null;

            sSWAV swav = new sSWAV();

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

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

                //Leer Data
                swav.data.type = Encoding.ASCII.GetChars(br.ReadBytes(4));
                swav.data.nSize = br.ReadUInt32();
                {//Leer Info
                    swav.data.info.nWaveType = br.ReadByte();
                    swav.data.info.bLoop = br.ReadByte();
                    swav.data.info.nSampleRate = br.ReadUInt16();
                    swav.data.info.nTime = br.ReadUInt16();
                    swav.data.info.nLoopOffset = br.ReadUInt16();
                    swav.data.info.nNonLoopLen = br.ReadUInt32();
                }
                //Leer resto de Data
                uint tamañoDatos = (uint)(br.BaseStream.Length - br.BaseStream.Position);
                swav.data.data = br.ReadBytes((int)tamañoDatos);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }
            finally
            {
                if (fs != null) fs.Close();
                if (br != null) br.Close();
            }

            return swav;
        }
コード例 #13
0
ファイル: SWAV.cs プロジェクト: MetLob/tinke
        public static Dictionary<String, String> Information(sSWAV swav, 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(swav.header.type));
                info.Add(xml.Element("S03").Value, "0x" + swav.header.magic.ToString("x"));
                info.Add(xml.Element("S04").Value, swav.header.nFileSize.ToString());

                info.Add(xml.Element("S05").Value, xml.Element("S17").Value);
                info.Add(xml.Element("S07").Value, swav.data.info.nWaveType.ToString());
                info.Add(xml.Element("S08").Value, swav.data.info.bLoop.ToString());
                info.Add(xml.Element("S09").Value, "0x" + swav.data.info.nLoopOffset.ToString("x"));
                info.Add(xml.Element("S18").Value, "0x" + swav.data.info.nNonLoopLen.ToString("x"));
                info.Add(xml.Element("S0B").Value, swav.data.info.nSampleRate.ToString());
                info.Add(xml.Element("S0C").Value, swav.data.info.nTime.ToString());

                info.Add(xml.Element("S14").Value, new String(swav.data.type));
                info.Add(xml.Element("S15").Value, swav.data.nSize.ToString());
            }
            catch { throw new Exception("There was an error reading the language file"); }

            return info;
        }
コード例 #14
0
ファイル: SWAV.cs プロジェクト: MetLob/tinke
        public static sWAV ConvertToWAV(sSWAV swav, bool loop)
        {
            sWAV wav = new sWAV();

            if (swav.data.info.nWaveType == 0) // 8 Bits per sample, PCM-8
            {
                swav.data.data = PCM.PCM8SignedToPCM16(swav.data.data);
                if (loop)
                {
                    Byte[] data = new Byte[(int)swav.data.info.nNonLoopLen];
                    Array.Copy(swav.data.data, swav.data.info.nLoopOffset, data, 0, data.Length);
                    swav.data.data = data;
                }

                wav = WAV.Create_WAV(1, swav.data.info.nSampleRate, 16, swav.data.data);
            }
            else if (swav.data.info.nWaveType == 1) // 16 Bits per sample, PCM-16
            {
                if (loop) // NO TESTED
                {
                    Byte[] data = new Byte[(int)swav.data.info.nNonLoopLen];
                    Array.Copy(swav.data.data, swav.data.info.nLoopOffset, data, 0, data.Length);
                    swav.data.data = data;
                }

                wav = WAV.Create_WAV(1, swav.data.info.nSampleRate, 16, swav.data.data);
            }
            else if (swav.data.info.nWaveType >= 2) // 4 Bits per sample, IMA-ADPCM
            {
                swav.data.data = Compression_ADPCM.Decompress(
                    swav.data.data,
                    BitConverter.ToUInt16(swav.data.data, 0),
                    BitConverter.ToUInt16(swav.data.data, 2));

                if (loop)
                {
                    Byte[] data = new Byte[swav.data.data.Length - ((int)swav.data.info.nLoopOffset * 2)];
                    Array.Copy(swav.data.data, swav.data.info.nLoopOffset * 2, data, 0, data.Length);
                    swav.data.data = data;
                }

                wav = WAV.Create_WAV(1, swav.data.info.nSampleRate, 16, swav.data.data);
            }
            return wav;
        }
コード例 #15
0
ファイル: SWAV.cs プロジェクト: MetLob/tinke
        public static sSWAV ConvertToSWAV(sWAV wav, int waveType, int volume = 150)
        {
            sSWAV swav = new sSWAV();
            swav.header.type = "SWAV".ToCharArray();
            swav.header.magic = 0x0100FEFF;
            swav.header.nSize = 0x10;
            swav.header.nBlock = 0x01;

            swav.data.type = "DATA".ToCharArray();
            swav.data.info.nWaveType = (byte)waveType;
            swav.data.info.bLoop = 1;
            swav.data.info.nSampleRate = (ushort)wav.wave.fmt.sampleRate;
            swav.data.info.nTime = (ushort)(1.6756991e+7 / wav.wave.fmt.sampleRate);
            swav.data.info.nLoopOffset = 0x01;

            if (wav.wave.fmt.numChannels > 1)
                wav.wave.data.data = WAV.ConvertToMono(wav.wave.data.data, wav.wave.fmt.numChannels, wav.wave.fmt.bitsPerSample);

            //wav.wave.data.data = ChangeVolume(wav.wave.data.data, volume, wav.wave.fmt.bitsPerSample);
            if (waveType == 0)
                swav.data.data = PCM.PCM16ToPCM8(wav.wave.data.data);
            else if (waveType == 2)
            {
                List<byte> temp = new List<byte>();
                temp.AddRange(new Byte[] { 0x00, 0x00, 0x00, 0x00 });
                temp.AddRange(Compression_ADPCM.Compress(wav.wave.data.data));
                swav.data.data = temp.ToArray();
            }
            else
                swav.data.data = wav.wave.data.data;

            swav.data.nSize = (uint)swav.data.data.Length + 0x0A;
            swav.data.info.nNonLoopLen = (uint)swav.data.data.Length;
            swav.header.nFileSize = swav.data.nSize + swav.header.nSize;

            return swav;
        }