Exemplo n.º 1
0
 private void Convert(uint index)
 {
     if (!(Sounds[index].Type == 2))
     {
         SaveWAV.FileName = Sounds[index].Name;
         if (SaveWAV.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             System.IO.MemoryStream SoundStream  = new System.IO.MemoryStream();
             System.IO.BinaryWriter StreamWriter = new System.IO.BinaryWriter(SoundStream);
             Twinsanity.ADPCM       ADPCM_Device = new Twinsanity.ADPCM();
             SoundStream.Position = 44;
             if (Sounds[index].Type == 0)
             {
                 System.IO.MemoryStream ADPCM       = new System.IO.MemoryStream();
                 System.IO.MemoryStream PCM         = new System.IO.MemoryStream();
                 System.IO.BinaryWriter ADPCMWriter = new System.IO.BinaryWriter(ADPCM);
                 MB.Position = Sounds[index].Offset + 48;
                 ADPCMWriter.Write(MBReader.ReadBytes((int)Sounds[index].Size));
                 ADPCM.Position = 0;
                 ADPCM_Device.ADPCM2PCM(ADPCM, ref PCM);
                 SoundStream.Position = 0;
                 WriteHeader(ref SoundStream, Sounds[index].SampleRate, 1, (uint)PCM.Length);
                 StreamWriter.Write(PCM.ToArray());
             }
             else
             {
                 System.IO.MemoryStream ADPCM       = new System.IO.MemoryStream();
                 System.IO.MemoryStream ADPCM_R     = new System.IO.MemoryStream();
                 System.IO.MemoryStream ADPCM_L     = new System.IO.MemoryStream();
                 System.IO.MemoryStream PCM         = new System.IO.MemoryStream();
                 System.IO.MemoryStream PCM_R       = new System.IO.MemoryStream();
                 System.IO.MemoryStream PCM_L       = new System.IO.MemoryStream();
                 System.IO.BinaryWriter ADPCMWriter = new System.IO.BinaryWriter(ADPCM);
                 System.IO.BinaryWriter PCMWriter   = new System.IO.BinaryWriter(PCM);
                 MB.Position = Sounds[index].Offset;
                 ADPCMWriter.Write(MBReader.ReadBytes((int)Sounds[index].Size));
                 ADPCM.Position = 0;
                 ADPCM_Device.ADPCM_Demux(ADPCM, ref ADPCM_R, ref ADPCM_L, Interleave);
                 ADPCM_R.Position = 0;
                 PCM_R.Position   = 0;
                 ADPCM_L.Position = 0;
                 PCM_L.Position   = 0;
                 ADPCM_Device.ADPCM2PCM(ADPCM_R, ref PCM_R);
                 ADPCM_Device.ADPCM2PCM(ADPCM_L, ref PCM_L);
                 ADPCM_Device.PCM_Mux(ref PCM, PCM_R, PCM_L);
                 SoundStream.Position = 0;
                 WriteHeader(ref SoundStream, Sounds[index].SampleRate, 2, (uint)PCM.Length);
                 StreamWriter.Write(PCM.ToArray());
             }
             SoundStream.Position = 0;
             System.IO.FileStream   File       = new System.IO.FileStream(SaveWAV.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
             System.IO.BinaryWriter FileWriter = new System.IO.BinaryWriter(File);
             FileWriter.Write(SoundStream.ToArray());
             FileWriter.Close();
             File.Close();
         }
     }
     else
     {
         Interaction.MsgBox("No data to play");
     }
 }
Exemplo n.º 2
0
        private void Button6_Click(object sender, EventArgs e)
        {
            int index = TreeView1.SelectedNode.Index;

            if (OpenWAV.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                System.IO.FileStream   WAVFile   = new System.IO.FileStream(OpenWAV.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                System.IO.BinaryReader WAVReader = new System.IO.BinaryReader(WAVFile);
                char[] Header;
                int    FileSize;
                char[] WAVHeader;
                char[] fmtHeader;
                int    SubChunk1Size;
                Int16  Format;
                Int16  Chanells;
                uint   SampleRate;
                uint   BitRate;
                UInt16 Align;
                UInt16 BPS;
                char[] SubChunk2Id;
                int    SubChunk2Size;
                Header        = WAVReader.ReadChars(4);
                FileSize      = WAVReader.ReadInt32();
                WAVHeader     = WAVReader.ReadChars(4);
                fmtHeader     = WAVReader.ReadChars(4);
                SubChunk1Size = WAVReader.ReadInt32();
                Format        = WAVReader.ReadInt16();
                Chanells      = WAVReader.ReadInt16();
                SampleRate    = WAVReader.ReadUInt32();
                BitRate       = WAVReader.ReadUInt32();
                Align         = WAVReader.ReadUInt16();
                BPS           = WAVReader.ReadUInt16();
                SubChunk2Id   = WAVReader.ReadChars(4);
                SubChunk2Size = WAVReader.ReadInt32();
                System.IO.MemoryStream ADPCM     = new System.IO.MemoryStream();
                System.IO.MemoryStream PCM       = new System.IO.MemoryStream();
                System.IO.BinaryWriter PCMWriter = new System.IO.BinaryWriter(PCM);
                PCMWriter.Write(WAVReader.ReadBytes(SubChunk2Size));
                Twinsanity.ADPCM ADPCM_Device = new Twinsanity.ADPCM();
                if (Chanells == 2)
                {
                    System.IO.MemoryStream PCML   = new System.IO.MemoryStream();
                    System.IO.MemoryStream PCMR   = new System.IO.MemoryStream();
                    System.IO.MemoryStream ADPCML = new System.IO.MemoryStream();
                    System.IO.MemoryStream ADPCMR = new System.IO.MemoryStream();
                    ADPCM_Device.PCM_Demux(PCM, ref PCMR, ref PCML);
                    PCMR.Position = 0;
                    PCML.Position = 0;
                    ADPCM_Device.PCM2ADPCM(ref ADPCMR, PCMR);
                    ADPCM_Device.PCM2ADPCM(ref ADPCML, PCML);
                    ADPCM_Device.ADPCM_Mux(ref ADPCM, ADPCMR, ADPCML, Interleave);
                    Sounds[index].Type = 1;
                }
                else if (Chanells == 1)
                {
                    PCM.Position = 0;
                    ADPCM_Device.PCM2ADPCM(ref ADPCM, PCM);
                    Sounds[index].Type = 0;
                }
                Sounds[index].Size       = (uint)ADPCM.Length;
                Sounds[index].Offset     = 0;
                Sounds[index].SampleRate = SampleRate;
                Sounds[index].Skip       = 0;
                Sounds[index].External   = true;
                Sounds[index].Name       = "External";
                Sounds[index].Stream     = new System.IO.MemoryStream();
                Sounds[index].Stream.Write(ADPCM.ToArray(), 0, (int)ADPCM.Length);
                BuildTree();
            }
        }
Exemplo n.º 3
0
        private void LoadBuffer(uint index)
        {
            if (!(Sounds[index].Type == 2))
            {
                System.IO.MemoryStream SoundStream  = new System.IO.MemoryStream();
                System.IO.BinaryWriter StreamWriter = new System.IO.BinaryWriter(SoundStream);
                Twinsanity.ADPCM       ADPCM_Device = new Twinsanity.ADPCM();
                SoundStream.Position = 44;
                if (Sounds[index].Type == 0)
                {
                    System.IO.MemoryStream ADPCM       = new System.IO.MemoryStream();
                    System.IO.MemoryStream PCM         = new System.IO.MemoryStream();
                    System.IO.BinaryWriter ADPCMWriter = new System.IO.BinaryWriter(ADPCM);
                    if (!Sounds[index].External)
                    {
                        MB.Position = Sounds[index].Offset + 48;
                        ADPCMWriter.Write(MBReader.ReadBytes((int)Sounds[index].Size));
                    }
                    else
                    {
                        ADPCMWriter.Write(Sounds[index].Stream.ToArray());
                    }
                    ADPCM.Position = 0;
                    ADPCM_Device.ADPCM2PCM(ADPCM, ref PCM);
                    SoundStream.Position = 0;
                    WriteHeader(ref SoundStream, Sounds[index].SampleRate, 1, (uint)PCM.Length);
                    StreamWriter.Write(PCM.ToArray());
                }
                else
                {
                    System.IO.MemoryStream ADPCM       = new System.IO.MemoryStream();
                    System.IO.MemoryStream ADPCM_R     = new System.IO.MemoryStream();
                    System.IO.MemoryStream ADPCM_L     = new System.IO.MemoryStream();
                    System.IO.MemoryStream PCM         = new System.IO.MemoryStream();
                    System.IO.MemoryStream PCM_R       = new System.IO.MemoryStream();
                    System.IO.MemoryStream PCM_L       = new System.IO.MemoryStream();
                    System.IO.BinaryWriter ADPCMWriter = new System.IO.BinaryWriter(ADPCM);
                    System.IO.BinaryWriter PCMWriter   = new System.IO.BinaryWriter(PCM);
                    if (!Sounds[index].External)
                    {
                        MB.Position = Sounds[index].Offset;
                        ADPCMWriter.Write(MBReader.ReadBytes((int)Sounds[index].Size));
                    }
                    else
                    {
                        ADPCMWriter.Write(Sounds[index].Stream.ToArray());
                    }
                    ADPCM.Position = 0;
                    ADPCM_Device.ADPCM_Demux(ADPCM, ref ADPCM_R, ref ADPCM_L, Interleave);
                    ADPCM_R.Position = 0;
                    PCM_R.Position   = 0;
                    ADPCM_L.Position = 0;
                    PCM_L.Position   = 0;
                    ADPCM_Device.ADPCM2PCM(ADPCM_R, ref PCM_R);
                    ADPCM_Device.ADPCM2PCM(ADPCM_L, ref PCM_L);
                    ADPCM_Device.PCM_Mux(ref PCM, PCM_R, PCM_L);
                    SoundStream.Position = 0;
                    WriteHeader(ref SoundStream, Sounds[index].SampleRate, 2, (uint)PCM.Length);
                    StreamWriter.Write(PCM.ToArray());
                }
                SoundStream.Position = 0;

                AL.BindBufferToSource(SoundSource, SoundBuffer);
                AL.BufferData(SoundBuffer, ALFormat.Stereo16, SoundStream.GetBuffer(), SoundStream.GetBuffer().Length, 44100);


                TrackBar1.Maximum = SoundStream.GetBuffer().Length - 1;
                Label10.Text      = "Loaded: yes";
            }
            else
            {
                Interaction.MsgBox("No data to play");
            }
        }