/// <summary>Calls the stop recording dll function.</summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void stRec_Click(object sender, EventArgs e) { if (!dialogOpen) { OpenDialog(); } RecordData rd = StopRec(); byte[] data = new byte[rd.len]; //gets recorded data (samples) Marshal.Copy(rd.ip, data, 0, (int)rd.len); //gets wave fmt/riff data byte[] formatTag = new byte[4]; wf = (WaveForm)Marshal.PtrToStructure(GetWaveform(), typeof(WaveForm)); waveFile = new RWWaveFile(Encoding.ASCII.GetBytes("RIFF"), (uint)(rd.len / wf.nBlockAlign) + 36, Encoding.ASCII.GetBytes("WAVE"), Encoding.ASCII.GetBytes("fmt "), 16, (ushort)1, wf.nChannels, wf.nSamplesPerSec, wf.nAvgBytesPerSec, wf.nBlockAlign, wf.wBitsPerSample, Encoding.ASCII.GetBytes("data"), rd.len); //sets up samples if (waveFile.FmtChunk1.BitsPerSample == 16) { double[] temp = new double[rd.len / (int)waveFile.FmtChunk1.BlockAlign]; for (int i = 0; i < temp.Length - 1; i++) { temp[i] = BitConverter.ToInt16(data, i * (int)waveFile.FmtChunk1.BlockAlign); } rawSamples = new double[temp.Length]; rawSamples = temp.Select(x => (x)).ToArray(); } else if (waveFile.FmtChunk1.BitsPerSample == 32) { double[] temp = new double[rd.len / (int)waveFile.FmtChunk1.BlockAlign]; for (int i = 0; i < temp.Length; i++) { temp[i] = BitConverter.ToInt32(data, i * (int)waveFile.FmtChunk1.BlockAlign); } rawSamples = temp.Select(x => (x)).ToArray(); waveFile.FmtChunk1.FmtTag = 3; } waveFile.DataChunk1.Data = rawSamples; if (waveFile.DataChunk1.Data != null) { sel = (int)waveFile.DataChunk1.DataSize; selEnd = (int)waveFile.DataChunk1.DataSize; newChart(); } this.Text = "new untitled recording (" + waveFile.FmtChunk1.BitsPerSample + "bits, " + waveFile.FmtChunk1.SamplesPerSec + "Hz)"; }
/// <summary>Handles the Click event of the openFileToolStripMenuItem control.</summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void openFileToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog fileDlg = new OpenFileDialog(); if (fileDlg.ShowDialog() == DialogResult.OK) { filename = fileDlg.FileName; waveFile = new RWWaveFile(filename); sel = (int)waveFile.DataChunk1.DataSize; selEnd = (int)waveFile.DataChunk1.DataSize; newChart(); newRecording = false; this.Text = fileDlg.FileName + " (" + waveFile.FmtChunk1.BitsPerSample + "bits, " + waveFile.FmtChunk1.SamplesPerSec + "Hz)"; refreshChart(); } }