private void btnPlay_Click(object sender, EventArgs e) { var awFile = root.currentWGroup; var wavDesc = root.currentWave; Stream fStrm = null; try { fStrm = File.OpenRead(awFile.awFile); } catch { MessageBox.Show($"Failed to open '{awFile.awFile}'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } byte[] tf = new byte[wavDesc.wsys_size]; fStrm.Position = wavDesc.wsys_start; fStrm.Read(tf, 0, wavDesc.wsys_size); var ADP = ADPCM.ADPCMToPCM16(tf, ADPCM.ADPCMFormat.FOUR_BIT); var w = JAIDSP.SetupSoundBuffer(ADP, 1, (int)wavDesc.sampleRate, 0); var b = new JAIDSPVoice(ref w); b.play(); fStrm.Close(); }
private void Menu_ReplaceSoundWav() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "WAV|*.wav"; ofd.FileName = Data.ID.ToString(); if (ofd.ShowDialog() == DialogResult.OK) { using (FileStream file = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read)) using (BinaryReader reader = new BinaryReader(file)) { file.Position = 0x16; UInt16 channels = reader.ReadUInt16(); UInt32 frequency = reader.ReadUInt32(); file.Position = 0x28; int len = reader.ReadInt32(); Byte[] PCM = reader.ReadBytes(len); if (channels == 1) { Data.Freq = (ushort)frequency; Byte[] newData = ADPCM.FromPCMMono(PCM); UInt32 newSize = (uint)newData.Length; InjectData(Data.SoundOffset, Data.SoundSize, newData); Data.SoundSize = newSize; } else { throw new ArgumentException("ATM only mono, sorry fam"); } LoadSoundData(); GenText(); } } }
private void FMV_Load(object sender, EventArgs e) { /*double ticks = 10000000.0 / (Video.Header.FrameRate / 256.0); * float exp = (float)(ticks - Math.Floor(ticks)); * if (exp != 0) * { * int i = 0; * float result; * do * { * i++; * result = exp * i; * } * while((float)(result - Math.Floor(result)) != 0); * }*/ //TODO: Calculate timing based on fps if ((Video.Header.Flags & 4) == 4) { AudioConverter = new ADPCM(); AudioBuffer = new NAudio.Wave.BufferedWaveProvider(new NAudio.Wave.WaveFormat((int)Video.Header.AudioRate, 16, 1)); AudioBuffer.DiscardOnBufferOverflow = true; AudioBuffer.BufferLength = 8192 * 16; Player = new NAudio.Wave.WaveOut(); Player.DesiredLatency = 150; Player.Init(AudioBuffer); Player.Play(); } new System.Threading.Thread(new System.Threading.ThreadStart(delegate { int state = 0; while (!stop) { if (Frames.Count != 0) { pictureBox1.Image = Frames.Dequeue(); switch (state) { case 0: System.Threading.Thread.Sleep(TimeSpan.FromTicks(666666)); break; case 1: System.Threading.Thread.Sleep(TimeSpan.FromTicks(666667)); break; case 2: System.Threading.Thread.Sleep(TimeSpan.FromTicks(666667)); break; } state = (state + 1) % 3; } } System.Threading.Thread.CurrentThread.Abort(); })).Start(); backgroundWorker1.RunWorkerAsync(); }
private void button1_Click(object sender, EventArgs e) { Track selTrack = tracks[listBox1.SelectedIndex]; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "WAV|*.wav"; sfd.FileName = selTrack.Type != 0 ? $"{listBox1.SelectedIndex}" : $"{listBox1.SelectedIndex} - {selTrack.Name}"; if (sfd.ShowDialog() == DialogResult.OK) { BinaryWriter writer = new BinaryWriter(new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write)); BinaryReader mb = new BinaryReader(new FileStream(mb_name, FileMode.Open)); mb.BaseStream.Position = curTrack.Offset + (curTrack.Type == 0 ? 0x30 : 0); byte[] rawData = mb.ReadBytes(curTrack.Type == 0 ? curTrack.Size - 0x30 : curTrack.Size); mb.Close(); writer.Write(curTrack.Type == 1 ? RIFF.SaveRiff(ADPCM.ToPCMStereo(rawData, rawData.Length, interleave), 2, curTrack.SampleRate) : RIFF.SaveRiff(ADPCM.ToPCMMono(rawData, rawData.Length), 1, curTrack.SampleRate)); writer.Close(); } }
static void Main(string[] args) { string fullfilename = args[0]; string dir = Path.GetDirectoryName(fullfilename); string filename = Path.GetFileNameWithoutExtension(fullfilename); Console.WriteLine($"{fullfilename} = {dir} + {Path.DirectorySeparatorChar} + {filename}"); FileStream fs = new FileStream(fullfilename, FileMode.Open); FileStream fsout = new FileStream(dir + Path.DirectorySeparatorChar + filename + "_out.bin", FileMode.Create); byte[] pcmhead = { 0x00, 0x00 }; //TODO fs.Seek(0x82, SeekOrigin.Begin); //fs.Seek(0x12,SeekOrigin.Begin); int b; while (true) { int sample0 = fs.ReadByte() + (fs.ReadByte() << 8); int index0 = fs.ReadByte(); fs.ReadByte(); ADPCM adpcm = new ADPCM(sample0, index0); for (int i = 0; i < 0x3FC; i++) //while(true) { b = fs.ReadByte(); if (b == -1) { goto exit; } int sample; sample = adpcm.next(b & 0x0F); fsout.WriteByte((byte)(sample & 0xFF)); fsout.WriteByte((byte)(sample >> 8)); sample = adpcm.next(b >> 4); fsout.WriteByte((byte)(sample & 0xFF)); fsout.WriteByte((byte)(sample >> 8)); } } exit: fs.Close(); fsout.Close(); }
private void button3_Click(object sender, EventArgs e) { if (tracks[listBox1.SelectedIndex].Type == 2) { return; } player.Stop(); player.Stream = null; button3.Enabled = trackBar1.Enabled = false; curTrack = tracks[listBox1.SelectedIndex]; BinaryReader mb = new BinaryReader(new FileStream(mb_name, FileMode.Open)); mb.BaseStream.Position = curTrack.Offset + (curTrack.Type == 0 ? 0x30 : 0); byte[] rawData = mb.ReadBytes(curTrack.Type == 0 ? curTrack.Size - 0x30 : curTrack.Size); mb.Close(); sndData = curTrack.Type == 1 ? RIFF.SaveRiff(ADPCM.ToPCMStereo(rawData, rawData.Length, interleave), 2, curTrack.SampleRate) : RIFF.SaveRiff(ADPCM.ToPCMMono(rawData, rawData.Length), 1, curTrack.SampleRate); player.Stream = new MemoryStream(sndData); player.Play(); seekWatch = Stopwatch.StartNew(); curName = (string)listBox1.SelectedItem; button3.Enabled = button4.Enabled = trackBar1.Enabled = seekTimer.Enabled = true; }
private void addTrackToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "WAV files|*.wav"; if (ofd.ShowDialog() == DialogResult.OK) { BinaryReader reader = new BinaryReader(new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read)); if (new string(reader.ReadChars(4)) != "RIFF" || reader.ReadInt32() != reader.BaseStream.Length - 8 || new string(reader.ReadChars(4)) != "WAVE" || new string(reader.ReadChars(4)) != "fmt " || reader.ReadInt32() != 16 || reader.ReadInt16() != 1) { return; } ushort channels = reader.ReadUInt16(); int samplerate = reader.ReadInt32(); if (channels > 2 || reader.ReadInt32() != samplerate * channels * 2 || reader.ReadInt16() != channels * 2 || reader.ReadInt16() != 16 || new string(reader.ReadChars(4)) != "data") { return; } BinaryWriter mb = new BinaryWriter(new FileStream(mb_name, FileMode.Append, FileAccess.Write)); long mb_start_seek = mb.BaseStream.Position; if (mb_start_seek > uint.MaxValue) { return; } int readsize = reader.ReadInt32(); byte[] vag_data; if (channels == 1) { vag_data = ADPCM.FromPCMMono(reader.ReadBytes(readsize)); mb.Write("MSVp".ToCharArray()); mb.Write(0x20000000); mb.Write(0); mb.Write(BitConv.FlipBytes(vag_data.Length)); mb.Write(BitConv.FlipBytes(samplerate)); mb.Write(0); mb.Write(0); mb.Write(0); string fname_no_ext = ofd.SafeFileName.Substring(0, ofd.SafeFileName.LastIndexOf('.')); for (int i = 0; i < 16; ++i) { if (i < fname_no_ext.Length) { mb.Write(fname_no_ext[i]); } else { mb.Write(0); } } mb.Write(vag_data); } else if (channels == 2) { vag_data = ADPCM.FromPCMStereo(reader.ReadBytes(readsize), interleave); mb.Write(vag_data); } } }
public void LoadSoundData() { RawData = new byte[Data.SoundSize]; Array.Copy(Data.Parent.ExtraData, Data.SoundOffset, RawData, 0, Data.SoundSize); SoundData = RIFF.SaveRiff(ADPCM.ToPCMMono(RawData, (int)Data.SoundSize), 1, Data.Freq); }
public Int16[] GetChannelData(int Channel) { if (Channel >= Info.StreamInfo.NrChannels) { return(null); } if (Info.StreamInfo.Format == 2) { ADPCM worker = new ADPCM(Info.CodecInfos[Channel].Table); List <short> Data = new List <short>(); for (int i = 0; i < this.Data.Data.Length; i += (int)Info.StreamInfo.BlockSize * Info.StreamInfo.NrChannels) { if (i != 0) { Data[Data.Count - 2] = Seek.Samples[(i / Info.StreamInfo.BlockSize) * 2 + Channel * 2 + 1]; Data[Data.Count - 1] = Seek.Samples[(i / Info.StreamInfo.BlockSize) * 2 + Channel * 2]; } worker.UpdateLastSamples(Seek.Samples[(i / Info.StreamInfo.BlockSize) * 2 + Channel * 2], Seek.Samples[(i / Info.StreamInfo.BlockSize) * 2 + Channel * 2 + 1]); if (i + Info.StreamInfo.BlockSize * Info.StreamInfo.NrChannels < this.Data.Data.Length) { Data.AddRange(worker.GetWaveData(this.Data.Data, i + Channel * (int)Info.StreamInfo.BlockSize, (int)Info.StreamInfo.BlockSize)); } else if (Info.StreamInfo.BlockSize != Info.StreamInfo.LastBlockPaddedSize) { Data.AddRange(worker.GetWaveData(this.Data.Data, i + Channel * (int)Info.StreamInfo.LastBlockPaddedSize, (int)Info.StreamInfo.LastBlockPaddedSize)); } else { break; } } return(Data.ToArray()); } else if (Info.StreamInfo.Format == 1) { List <short> Data = new List <short>(); for (int i = 0; i < this.Data.Data.Length; i += (int)Info.StreamInfo.BlockSize * Info.StreamInfo.NrChannels) { if (i + Info.StreamInfo.BlockSize * Info.StreamInfo.NrChannels < this.Data.Data.Length) { for (int q = 0; q < Info.StreamInfo.BlockSize; q += 2) { Data.Add(IOUtil.ReadS16LE(this.Data.Data, (int)(i + Channel * Info.StreamInfo.BlockSize + q))); } } else if (Info.StreamInfo.BlockSize != Info.StreamInfo.LastBlockSize) { for (int q = 0; q < Info.StreamInfo.LastBlockSize; q += 2) { Data.Add(IOUtil.ReadS16LE(this.Data.Data, (int)(i + Channel * Info.StreamInfo.LastBlockPaddedSize + q))); } } else { break; } } return(Data.ToArray()); } else { return(new short[0]); } }