private void SendCaptureAudio(object sender, WaveInEventArgs e) { try { foreach (byte _byte in e.Buffer) { _waveWriter.WriteByte(_byte); } } catch (Exception ex) { } }
//========== EXTRACTING ========== #region Extracting /** <summary> Called by the timer to extract the images. </summary> */ private void Extracting(object sender, EventArgs e) { if (this.extractFileIndex == 1) { for (int i = 0; i < 5 && this.css1Index < this.css1NumSounds; i++, this.css1Index++) { reader.BaseStream.Position = (long)this.css1Offsets[this.css1Index]; WaveFormat format = new WaveFormat(22050, 16, 1); string soundName = (this.nameFormat ? GetSoundName(this.extractFileIndex, this.css1Index) : this.extractFileIndex.ToString() + "-" + this.css1Index.ToString()); if (this.css1Index == 28 || this.css1Index == 44) // A stereo sound { format = new WaveFormat(22050, 16, 2); } using (WaveFileWriter writer = new WaveFileWriter(Path.Combine(this.outputDirectory, soundName + ".wav"), format)) { uint length = reader.ReadUInt32(); reader.ReadBytes(20); for (int j = 0; j < length; j++) { writer.WriteByte(reader.ReadByte()); } writer.Close(); } } if (this.css1Index == this.css1NumSounds) { reader.Close(); this.extractFileIndex++; } } else { if (IsSong(this.extractFileIndex)) { SongInfo info = GetSongInfo(this.extractFileIndex); if (this.extractMusicAsMp3) { WriteSong( Path.Combine(this.dataDirectory, "css" + this.extractFileIndex.ToString() + ".dat"), Path.Combine(this.outputDirectory, "Music", info.RCT2Title + ".mp3"), info ); } else { File.Copy( Path.Combine(this.dataDirectory, "css" + this.extractFileIndex.ToString() + ".dat"), Path.Combine(this.outputDirectory, "Music", info.RCT2Title + ".wav"), true ); } } else if (this.extractFileIndex != 10 && this.extractFileIndex != 16) { string soundName = (this.nameFormat ? GetSoundName(this.extractFileIndex, 0) : this.extractFileIndex.ToString()); File.Copy( Path.Combine(this.dataDirectory, "css" + this.extractFileIndex.ToString() + ".dat"), Path.Combine(this.outputDirectory, soundName + ".wav"), true ); } this.extractFileIndex++; } this.loadingBar.Width = 274 * (this.css1Index + this.extractFileIndex - 1) / ((int)this.css1NumSounds + 46); if ((this.css1Index + this.extractFileIndex - 1) == ((int)this.css1NumSounds + 46)) { reader.Close(); this.labelComplete.Visible = true; this.labelComplete.Text = "Finished - Took " + Math.Round((DateTime.Now - this.extractStart).TotalSeconds) + " seconds"; this.timerExtract.Stop(); } }
private void ButtonSave_Click(object sender, EventArgs e) { this.buttonPause.Enabled = false; this.buttonStart.Enabled = false; this.buttonStop.Enabled = false; this.buttonNewEvent.Enabled = false; this.buttonClear.Enabled = false; this.buttonSave.Enabled = false; WaveFileWriter writer = new WaveFileWriter(this.testName + ".wav", this.waveFormat); foreach (DataRow row in dataSet.WaveTable.Rows) { writer.WriteByte((byte)row["Amplitude"]); } writer.Close(); var result = new StringBuilder(); for (int i = 0; i < dataSet.WaveTable.Columns.Count; i++) { result.Append(dataSet.WaveTable.Columns[i].ColumnName); result.Append(i == dataSet.WaveTable.Columns.Count - 1 ? "\n" : ","); } foreach (DataRow row in dataSet.WaveTable.Rows) { for (int i = 0; i < dataSet.WaveTable.Columns.Count; i++) { result.Append(row[i].ToString()); result.Append(i == dataSet.WaveTable.Columns.Count - 1 ? "\n" : ","); } } StreamWriter waveData = System.IO.File.CreateText(this.testName + "-wave.csv"); waveData.Write(result.ToString()); waveData.Close(); result = new StringBuilder(); for (int i = 0; i < dataSet.EventTable.Columns.Count; i++) { result.Append(dataSet.EventTable.Columns[i].ColumnName); result.Append(i == dataSet.EventTable.Columns.Count - 1 ? "\n" : ","); } foreach (DataRow row in dataSet.EventTable.Rows) { for (int i = 0; i < dataSet.EventTable.Columns.Count; i++) { result.Append(row[i].ToString()); result.Append(i == dataSet.EventTable.Columns.Count - 1 ? "\n" : ","); } } StreamWriter eventData = System.IO.File.CreateText(this.testName + "-event.csv"); eventData.Write(result.ToString()); eventData.Close(); this.buttonPause.Enabled = false; this.buttonStart.Enabled = true; this.buttonStop.Enabled = false; this.buttonNewEvent.Enabled = false; this.buttonClear.Enabled = true; this.buttonSave.Enabled = false; }