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"); } }
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"); } }