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); }
void GenerateClick(object sender, RoutedEventArgs e) { do { tree = DevelopManager.CreateInitialTree(); individual = new Individual(tree, true); } while (!individual.IsValidWaveform()); individual.Play(); }
public static Unit.Renderer DevelopTopology(Tree.RootNode tree) { var man = new DevelopManager(); man.tree = tree; tree.Target = man.firstPoint; foreach (var item in tree.ToBreadthFirstList()) { item.Process(); } man.render.InitAll(); return(man.render); }
public AutoGA(string targetFile, int poolSize) { fileName = targetFile; this.PoolSize = poolSize; Elite = 1; target = new Analyzer(targetFile); Settings.Instance.SamplingFreq = target.SampleRate; target.Normalize(); target.CalcSpectrogram(true); target.CalcPitch(); target.CalcPower(); DevelopManager.SetNonNormalizedSource(target.Pitch, target.PowerTime); items = new Individual[poolSize]; Scores = new double[poolSize]; prob = new double[poolSize]; }
private void Button_Click(object sender, RoutedEventArgs e) { var fn = "test.wav"; var file = new FileUtil(fn); var render = new DevelopManager().CreateEmbryo(); file.Write(Enumerable.Range(0, 44100).Select(x => (float)render.RequireValue())); file.Dispose(); //var src = new Unit.WaveSource(); //var render = new Unit.Renderer(); //Unit.UnitBase.Connect(src, 0, render, 0); //file.Write(Enumerable.Range(0, 44100).Select(x => // { // src.Update(); // return (float)render.In[0].Value; // })); //file.Dispose(); new System.Media.SoundPlayer(fn).Play(); }
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); }
public void Init() { var trees = Enumerable.Range(0, Initial == null ? PoolSize : PoolSize - 1).Select(x => DevelopManager.CreateInitialTree()).ToArray(); if (Initial != null) { items[PoolSize - 1] = new Individual(Initial, false); } Parallel.For(0, Initial == null ? PoolSize : PoolSize - 1, i => items[i] = new Individual(new ParameterOptimizer(trees[i], target).Run(), false)); Generation = 0; FailCount = 0; continueCount = 0; BestScore = double.PositiveInfinity; }