/// <summary> /// Filters the selected points. /// </summary> public static void filter(Chart chart1, List <DataPoint> selectedPoints, List <DataPoint> selectedPoints2, float[] dataArray) { int maxLength = selectedPoints.Count; int maxLength2 = selectedPoints2.Count; double[] filterFrequencyD = new double[maxLength]; double[] filterTimeD; double[] filteredData; for (int i = 0; i < maxLength; i++) { if (i < maxLength2 || (maxLength - maxLength2) < i) { filterFrequencyD[i] = 1; } else { filterFrequencyD[i] = 0; } } filterTimeD = IDFT(filterFrequencyD); filteredData = convolution(filterTimeD, dataArray); for (int i = 0; i < filteredData.Length; i++) { dataArray[i] = (float)filteredData[i]; } WaveReader.FillChart(dataArray, chart1); }
/// <summary> /// Paste copied graph. /// </summary> public static void copyPaste(Chart chart1, List <DataPoint> selectedPoints, ref List <DataPoint> copiedPoints, float[] dataArray) { float[] newArray = new float[dataArray.Length + copiedPoints.Count + 1]; double[] copyData = convertPoints(copiedPoints); int startPoint = (int)selectedPoints[0].XValue; int endPoint = (int)selectedPoints[selectedPoints.Count - 1].XValue; for (int i = 0; i < startPoint; i++) { newArray[i] = dataArray[i]; } for (int i = startPoint, j = 0; j < copyData.Length; i++, j++) { newArray[i] = (float)copyData[j]; } for (int i = copyData.Length + startPoint, j = startPoint; j < dataArray.Length; i++, j++) { newArray[i] = dataArray[j]; } byte[] updatedArray = new byte[newArray.Length]; for (int i = 0; i < newArray.Length; i++) { updatedArray[i] = (byte)(newArray[i] + (byte)128); } updateAudio(updatedArray); dataArray = newArray; WaveReader.FillChart(newArray, chart1); }
/// <summary> /// Copies the selected graphs onto copiedPoints variable and deletes from graph. /// </summary> public static void deletePoints(Chart chart1, List <DataPoint> selectedPoints, ref List <DataPoint> copiedPoints, ref float[] dataArray) { if (selectedPoints == null) { return; } float[] newArray = new float[dataArray.Length - selectedPoints.Count + 1]; double[] deleteData = convertPoints(selectedPoints); copiedPoints = selectedPoints; int startPoint = (int)selectedPoints[0].XValue; int endPoint = (int)selectedPoints[selectedPoints.Count - 1].XValue; for (int i = 0; i < startPoint; i++) { newArray[i] = dataArray[i]; } for (int i = endPoint; i < dataArray.Length; i++) { newArray[startPoint] = dataArray[i]; startPoint++; } byte[] updatedArray = new byte[newArray.Length]; for (int i = 0; i < newArray.Length; i++) { updatedArray[i] = (byte)(newArray[i] + (byte)128); } updateAudio(updatedArray); dataArray = newArray; WaveReader.FillChart(newArray, chart1); }
private void graphToolStripMenuItem_Click(object sender, EventArgs e) { IntPtr winData = Recorder.getRecorded(); uint size = Recorder.getSize(); byte[] convData = new byte[size]; Marshal.Copy(winData, convData, 0, (int)size); float[] convData2 = new float[size]; for (uint i = 0; i < size; i++) { convData2[i] = convData[i] - (byte)128; } dataArray = new float[convData2.Length]; for (int i = 0; i < dataArray.Length; i++) { dataArray[i] = convData2[i]; } WaveReader.FillChart(convData2, chart1); }
/// <summary> /// Paste for when cut is called. /// </summary> public static void cutPaste(Chart chart1, List <DataPoint> selectedPoints, ref List <DataPoint> copiedPoints, float[] dataArray) { if (selectedPoints == null) { return; } float[] newArray = new float[dataArray.Length + copiedPoints.Count - selectedPoints.Count + 1]; int startPoint = (int)selectedPoints[0].XValue; int endPoint = (int)selectedPoints[selectedPoints.Count - 1].XValue; for (int i = 0; i < startPoint; i++) { newArray[i] = dataArray[i]; } for (int i = startPoint, j = 0; j < copiedPoints.Count; j++, i++) { newArray[i] = (float)copiedPoints.ElementAt(j).YValues[0]; } for (int i = endPoint, j = copiedPoints.Count + startPoint; i < dataArray.Length; i++, j++) { newArray[j] = dataArray[i]; } byte[] updatedArray = new byte[newArray.Length]; for (int i = 0; i < newArray.Length; i++) { updatedArray[i] = (byte)(newArray[i] + (byte)128); } Form1.paste = 2; updateAudio(updatedArray); dataArray = newArray; WaveReader.FillChart(newArray, chart1); }
/// <summary> /// Opens the selected audio file and graphs it on the the main graph. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openToolStripMenuItem_Click(object sender, EventArgs e) { float[] leftArray; float[] rightArray; string file = "NULL"; int size = -1; DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result. { file = openFileDialog1.FileName; try { string text = File.ReadAllText(file); size = text.Length; } catch (IOException) { } } Console.WriteLine(file); if (String.ReferenceEquals(file, "NULL")) { Console.WriteLine("...Failed to load note"); } else if (WaveReader.readWav(file, out leftArray, out rightArray)) { dataArray = new float[leftArray.Length]; for (int i = 0; i < leftArray.Length; i++) { dataArray[i] = leftArray[i]; } WaveReader.FillChart(leftArray, chart1); } }
private void windowingToolStripMenuItem_Click(object sender, EventArgs e) { double[] windowingPoints; windowingPoints = Fourier.Windowing(selectedPoints); WaveReader.FillChartDouble(Fourier.DFT(windowingPoints), chart3); }
private void inverseFourierToolStripMenuItem_Click(object sender, EventArgs e) { WaveReader.FillChartDouble(Fourier.IDFT(EditChart.convertPoints(selectedPoints)), chart3); }