public Individual(Tree.RootNode tree, bool useMask) { Tree = tree; Topology = DevelopManager.DevelopTopology(tree); Data = Enumerable.Range(0, DevelopManager.TableLength).Select(x => (float)Topology.RequireValue(x)).ToArray(); Normalize(); Analyzer = new AudioLib.Analyzer(Data, (int)FileUtil.SampleRate); Analyzer.CalcSpectrogram(useMask); }
double CompareSpectrogram(AudioLib.Analyzer another) { double s = 0; for (int i = 0; i < Analyzer.Spectrogram.GetLength(0); i++) { for (int j = 0; j < Analyzer.Spectrogram.GetLength(1); j++) { s += Math.Pow(Analyzer.Spectrogram[i, j] - another.Spectrogram[i, j], 2); } } s /= Analyzer.Spectrogram.GetLength(0); //frame length return(s); }
public ParameterOptimizer(Tree.RootNode original, AudioLib.Analyzer target) { rand = RandomProvider.GetThreadRandom(); Original = original; items = GetActiveConstants(original).ToArray(); Dimension = items.Length; Target = target; pool = new double[PoolSize][]; pool[0] = items.Select(x => x.Value).ToArray(); for (int i = 1; i < PoolSize; i++) { pool[i] = CreateVector(); } history = new Dictionary <double[], Individual>(); probTable = new double[PoolSize]; scores = new double[PoolSize]; }
public async void OpenFile(string fn) { this.Cursor = Cursors.Wait; Analyzer = new AudioLib.Analyzer(fn); Settings.Instance.SamplingFreq = Analyzer.SampleRate; //analyzer.Dft(); //analyzer.CalcSpectrogram(); await Task.Run(() => Analyzer.CalcPower()); await Task.Run(() => Analyzer.CalcPitch()); this.Cursor = null; //SetSpector(analyzer.Freq.Select((x, i) => new OxyPlot.DataPoint(analyzer.FreqPerIndex * i, x))); plot.Model = SetSpectrogram(Analyzer.Pitch.Select((x, i) => new OxyPlot.DataPoint(i / (double)Settings.Instance.SamplingFreq, x))); plot2.Model = SetPowergram(Analyzer.PowerTime.Select((x, i) => new OxyPlot.DataPoint(i / (double)Settings.Instance.SamplingFreq, x))); plot2.InvalidatePlot(); plot.InvalidatePlot(); DevelopManager.SetSource(Analyzer.Pitch.Select(x => x / (FileUtil.SampleRate / 2)).ToArray(), Analyzer.PowerTime); }
double CompareThresholdMasking(AudioLib.Analyzer target) { double s = 0; for (int i = 0; i < Analyzer.Spectrogram.GetLength(0); i++) { for (int j = 0; j < Analyzer.Spectrogram.GetLength(1); j++) { var m = target.ThresholdMask[i][j]; var o = Analyzer.Spectrogram[i, j]; var t = target.Spectrogram[i, j]; if (t >= m) { s += (o - t) * (o - t); } if (o >= t) { s += (o - m) * (o - m); } } } s /= Analyzer.Spectrogram.GetLength(0); return(s); }
public double CompareTo(AudioLib.Analyzer another) { return(CompareThresholdMasking(another)); //return CompareSpectrogram(another); }