public void GetFilterRange(double x, double y) { double lowFreq = 20000; double highFreq = 20; double centreFreq = x; if (Dsp.GetScriptVal("SCALE").GetType().Name == "Func`2") { Func <double, double> scale = (Func <double, double>)Dsp.GetScriptVal("SCALE"); centreFreq = scale((int)x); } if (y > 0.7) { highFreq = 20 + (centreFreq - 2.8 * (centreFreq / 100) - 20) * Math.Pow(y, 6); lowFreq = centreFreq + centreFreq - highFreq; } SetFilter((float)lowFreq, (float)highFreq, (float)centreFreq, (float)(16 * y), (float)(40 * y)); string note = Dsp.Analyser.GetMusic().GetNote(centreFreq); ui.SetFilterText(note, centreFreq); }
/* * Master method for performing analysis */ public async void RunAnalysis() { if (ui.Output.PlaybackState == PlaybackState.Playing || Mode == 1) { if (SpectrogramOpened) // Display spectrogram analysis in real-time { Dsp.ReadSpectrogramFrame(); DisplayAnalysisUI(); DisplayChords(); if (AudioSource.AudioStream != null) { ui.specViewer.OnTimestampUpdate(AudioSource.AudioStream.CurrentTime.TotalMilliseconds); } ui.RenderSpectrum(); } else // Perform real-time analysis pipeline { ui.EnableTimer(false); var watch = System.Diagnostics.Stopwatch.StartNew(); Dsp.RunFrequencyAnalysis(); Dsp.FrequencyAnalysisToSpectrum(Dsp.GetScriptVal("SCALE")); Dsp.RunPitchDetection(); Dsp.Analyser.GetNotes(Dsp.FreqPeaks, (double[])Dsp.GetScriptVal("POSITIONS"), analysisUpdates); Task asyncAnalysis = RunAnalysisAsync(); DisplayAnalysisUI(); ui.RenderSpectrum(); if (Dsp.Analyser.GetAvgError().Count == Prefs.ERROR_DURATION) // Calculate average note error { int error = (int)Dsp.Analyser.GetAvgError().Average(); if (error >= 0) { ui.SetErrorText("+ " + Math.Abs(error) + " Cents"); } else { ui.SetErrorText("- " + Math.Abs(error) + " Cents"); } Dsp.Analyser.ResetError(); } await asyncAnalysis; if (Prefs.STORE_SPEC_DATA) { Dsp.WriteToSpectrogram(); } watch.Stop(); if (Prefs.UPDATE_MODE == 0) // Dynamic update mode { executionTime.Add((int)watch.ElapsedMilliseconds); if (executionTime.Count == Prefs.AVG_EXECUTIONS) // Calculate average execution time { int executionTime = AverageExecutionTime(); if (executionTime >= Prefs.MIN_UPDATE_TIME) { ui.SetTimerInterval(executionTime); } ui.SetExecTimeText(executionTime); } } else if (Prefs.UPDATE_MODE == 1) // Manual update mode { ui.SetTimerInterval(Prefs.MIN_UPDATE_TIME); ui.SetExecTimeText((int)watch.ElapsedMilliseconds); } if (Mode != 1) { ui.EnableTimer(true); } analysisUpdates++; } } }