private void openToolStripMenuItem_Click(object sender, EventArgs e) { string outputFileName = ""; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Wave File (*.wav) | *.wav|MP3 Files (*.mp3) | *.mp3|All Files (*.*) | *.*"; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { outputFileName = openFileDialog.FileName; } else { return; } if (openFileDialog.FileName.Contains(".mp3")) { outputFileName = outputFileName.Substring(0, outputFileName.Length - 3) + "wav"; Mp3ToWav(openFileDialog.FileName, outputFileName); } //OpenFileDialog open = new OpenFileDialog(); //open.Filter = "Wave File (*.wav) | *.wav"; //if (open.ShowDialog() != DialogResult.OK) return; waveViewer1.WaveStream = new NAudio.Wave.WaveFileReader(outputFileName); waveViewer1.GetTotal = true; waveViewer1.Refresh(); var datalow = waveViewer1.Datax; var datahigh = waveViewer1.Datay; //take the data and look for patterns in the frame of 8 secs var peaks = detectpeak(200, datahigh, true); var trough = detectpeak(200, datahigh, false); peaks = filterpeak(20, peaks); trough = filterpeak(20, trough); waveViewer1.peaks = peaks; waveViewer1.trough = trough; double[][] highamp = new double[peaks.Count][]; for (int a = 0; a < peaks.Count - 1; a++) { highamp[a] = new double[2]; highamp[a][0] = peaks[a + 1] - peaks[a]; highamp[a][1] = datahigh[peaks[a]]; } highamp[peaks.Count - 1] = new double[2]; highamp[peaks.Count - 1][0] = 0; highamp[peaks.Count - 1][1] = 0; double[][] lowamp = new double[trough.Count][]; for (int a = 0; a < trough.Count - 1; a++) { lowamp[a] = new double[2]; lowamp[a][0] = trough[a + 1] - trough[a]; lowamp[a][1] = datahigh[trough[a]]; } lowamp[trough.Count - 1] = new double[2]; lowamp[trough.Count - 1][0] = 0; lowamp[trough.Count - 1][1] = 0; //cluster both Accord.MachineLearning.KMeans gm = new Accord.MachineLearning.KMeans(5); Accord.MachineLearning.KMeans gml = new Accord.MachineLearning.KMeans(5); var ans = gm.Compute(highamp); var lans = gml.Compute(lowamp); var fclus = filtercluster(ans, peaks); cluspos = MixerControls.ToDict(fclus); var flans = filtercluster(lans, trough);//ignore bot waveViewer1.peakclus = ans; waveViewer1.troughclus = lans; IWavePlayer play; play = new NAudio.Wave.WaveOut(); audio = new AudioFileReader(outputFileName); play.Init(audio); play.Play(); Application.Idle += Application_Idle; timer1.Interval = 20; timer1.Enabled = true; timer1.Start(); Rectangle workingArea = Screen.GetWorkingArea(this); this.Location = new Point(workingArea.Right - Size.Width - 20, workingArea.Bottom - Size.Height - 20); //this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.TopMost = true; this.Opacity = .8; openToolStripMenuItem.Visible = false; menuStrip1.Visible = false; this.pictureBox1.Image = Image.FromFile("D:\\AllVSProject232015\\AudioMix\\AudioMix\\Hypnoctivity-Logo.png"); }
void Application_Idle(object sender, EventArgs e) { audio.Position = MixerControls.Jump(cluspos, audio.Position, waveViewer1.peaks, waveViewer1.peakclus, ref nextvalue, ref currentposs); }