private void oscFreq_Click(object sender, RoutedEventArgs e) { Pause(); PeriodicSourceBase source; if (sender == osc1Freq) { source = oscPanel.Osc1.Source; } else { source = oscPanel.Osc2.Source; } MainMixer.ClearSources(); MainMixer.AddSource(source); FrequencyFilter output = FrequencyFilter.Source; var window = new FrequencyDialog(); window.ExportClicked += Window_ExportClicked; window.ShowDialog(); void Window_ExportClicked(object sender, FreqEventArgs e) { window.ExportClicked -= Window_ExportClicked; ExportFreqCharacteristics(e, source, output); } }
public IActionResult SingQuestion() { int Id = int.Parse(this.RouteData.Values["id"].ToString()); int? userId = HttpContext.Session.GetInt32("UserId"); var user = _dbContext.Users.First(a => a.Id == userId); PropertyInfo info = user.GetType().GetProperty($"Answer{Id}"); var waveResampler = new Resampler(null); Sound freqencyDetector = new Sound(); List <float> result = freqencyDetector.DetectFrequency(waveResampler); float mainFrequency = FrequencyFilter.CalculateMainFreq(result); if (Id == 19) { FrequencyClassificator FreqClass = new FrequencyClassificator(330); UserAnswers.AddAnswer(FreqClass.Validate(mainFrequency)); info.SetValue(user, FreqClass.Validate(mainFrequency)); _dbContext.SaveChanges(); return(RedirectToAction("Question", new { Id = Id + 1 })); } else if (Id == 20) { FrequencyClassificator FreqClass = new FrequencyClassificator(440); UserAnswers.AddAnswer(FreqClass.Validate(mainFrequency)); info.SetValue(user, FreqClass.Validate(mainFrequency)); _dbContext.SaveChanges(); return(RedirectToAction("YourResult")); } else { return(null); } }
public MainWindow() { InitializeComponent(); AForge.Point p = new AForge.Point(); AForge.Imaging.ComplexFilters.FrequencyFilter f = new FrequencyFilter(); }
public static IObservable <TSource> SetMaxFrequency <TSource>(this IObservable <TSource> source, double maxFrequency) { var filter = new FrequencyFilter(maxFrequency); return(ChainNext <TSource, TSource>(source, obs => o => { if (filter.CheckLap()) { obs.OnNext(o); } })); }
public void ctor_2() { var filter = new FrequencyFilter(25); Observable2.Interval(TimeSpan.FromMilliseconds(20)) .Do(_ => filter.CheckLap()) .Select(_ => filter.ArrangedFrequency) .Subscribe(Console.WriteLine); Thread.Sleep(3000); }
public bool ProcessRecording(byte[] audioArray, int baseFreq) { var waveResampler = new Resampler(audioArray); Sound freqencyDetector = new Sound(); List <float> result = freqencyDetector.DetectFrequency(waveResampler); float mainFrequency = FrequencyFilter.CalculateMainFreq(result); FrequencyClassificator FreqClass = new FrequencyClassificator(baseFreq); bool answer = FreqClass.Validate(mainFrequency); return(answer); }
protected void AddFilterToChannel(FrequencyFilter filter, ChannelHandle channel) { if (channel.isRightChannel) { m_filtersRight.Add(filter); m_channelIndicesRight.Add(channel.channelIndex); } else { m_filtersLeft.Add(filter); m_channelIndicesLeft.Add(channel.channelIndex); } }
public void TestOnWideSequence() { var seq = new List <Point>(); seq.Add(new Point(0, 0)); seq.Add(new Point(1, 1)); seq.Add(new Point(2, 2)); seq.Add(new Point(3, 3)); FrequencyFilter filter = new FrequencyFilter(); var filtered = filter.Filter(seq).ToArray(); Assert.IsTrue(filtered.Length == 4); }
public void TestOnNarrowSequence() { var seq = new List <Point>(); seq.Add(new Point(0, 0)); seq.Add(new Point(0.3, 0.3)); seq.Add(new Point(0.4, 0.5)); seq.Add(new Point(2, 2)); FrequencyFilter filter = new FrequencyFilter(); var filtered = filter.Filter(seq).ToArray(); Assert.IsTrue(filtered.Length == 2); }
public void ctor_1() { var filter = new FrequencyFilter(25); var meter = new FrequencyMeter(); Observable2.Interval(TimeSpan.FromMilliseconds(20)) .Where(_ => filter.CheckLap()) .Do(_ => meter.RecordLap()) .Subscribe(Console.WriteLine); Thread.Sleep(3000); Assert.IsTrue(meter.Frequency > 24); Assert.IsTrue(meter.Frequency <= 25); }
public Synthesizer(int sampleRate, int maximumInputs = 100) { inputs = new SynthesizerInput[maximumInputs]; SynthesizerInput input; for (int i = 0; i < maximumInputs; i++) { input = new SynthesizerInput(); inputs[i] = input; mixer.AddSource(input.Envelope); } Format = new AudioFormat(sampleRate, 1, 32); FrequencyFilter = new FrequencyFilter(mixer); FrequencyFilter.Disable(); }
public void TestFilteringLastPoint() { List <Point> unfiltered = new List <Point>(); unfiltered.Add(new Point(0, 0)); unfiltered.Add(new Point(1, 0.1)); unfiltered.Add(new Point(-1, 0.2)); unfiltered.Add(new Point(0.5, 0.22)); unfiltered.Add(new Point(0.4, 0.23)); unfiltered.Add(new Point(2, 0)); FrequencyFilter filter = new FrequencyFilter(); filter.SetScreenRect(new Rect(0, 0, 2, 10)); var filtered = filter.Filter(unfiltered); Assert.IsTrue(filtered[filtered.Count - 1] == new Point(2, 0)); }
private async void ExportFreqCharacteristics(FreqEventArgs e, PeriodicSourceBase source, FrequencyFilter output) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "CSV File|*.csv"; var now = DateTime.Now; sfd.FileName = $"{now.Month}-{now.Day} {now.Hour}-{now.Minute}-{now.Second}.csv"; if (sfd.ShowDialog() ?? false) { List <(double, double)> exportingData = new List <(double, double)>(); progressOverlay.Visibility = Visibility.Visible; await Task.Run(() => { TimeSpan currentTime = TimeSpan.Zero; int size = (int)(source.Format.SampleRate * 1); for (double current = e.From; e.To >= current; current += e.Step) { source.SetFrequency((float)current); var sourceData = source.Next(size); var outputData = output.Next(size); var sourceAv = sourceData.Average(f => Math.Abs(f)); var outputAv = outputData.Average(f => Math.Abs(f)); var gain = 20 * Math.Log10(outputAv / sourceAv); exportingData.Add((current, gain)); currentTime += TimeSpan.FromSeconds(0.1); } }); using (var sw = new StreamWriter(sfd.FileName)) { foreach (var pair in exportingData) { sw.WriteLine($"{pair.Item1}, {pair.Item2}"); } } progressOverlay.Visibility = Visibility.Hidden; } }
public FFTWindow(string file) { InitializeComponent(); if (string.IsNullOrEmpty(file)) { MessageBox.Show("Did not specify file, nerd"); this.Close(); } else { try { Bitmap myBmp = new Bitmap(file); if (myBmp.Width < 1000) { imgFFT.Height = myBmp.Height; imgFFT.Width = myBmp.Width; imgFFT2.Height = myBmp.Height; imgFFT2.Width = myBmp.Width; this.Width = 2 * myBmp.Width; } else { imgFFT.Height = myBmp.Height / 2; imgFFT.Width = myBmp.Width / 2; imgFFT2.Height = myBmp.Height / 2; imgFFT2.Width = myBmp.Width / 2; this.Width = myBmp.Width; } Bitmap tmp = ResizeImage(myBmp, 1024, 1024); //rozmiar do potegi 2 Bitmap grayScaleBP = ToGrayscale(tmp); // do skali szarosci oraz 8bpp ComplexImage complexImage = ComplexImage.FromBitmap(grayScaleBP); //obraz zespolony complexImage.ForwardFourierTransform(); //przeprowadzenie forward fourier transform Bitmap fourierImage1 = complexImage.ToBitmap(); //obraz modulu fourierImage1 = ResizeImage(fourierImage1, myBmp.Width, myBmp.Height); imgFFT.Source = BitmapToImageSource(fourierImage1); FrequencyFilter filter = new FrequencyFilter(new IntRange(20, 128)); //filtr częstotl filter.Apply(complexImage); complexImage.BackwardFourierTransform(); //wsteczna transformacja Bitmap fourierImage2 = complexImage.ToBitmap(); //konwersja obrazu zesp do bitmapy fourierImage2 = ResizeImage(fourierImage2, myBmp.Width, myBmp.Height); imgFFT2.Source = BitmapToImageSource(fourierImage2); grayScaleBP.Dispose(); //clone.Dispose(); myBmp.Dispose(); fourierImage1.Dispose(); fourierImage2.Dispose(); } catch { MessageBox.Show("Wrong file, nerd"); this.Close(); } } }
// Frequency filter private void frequencyFilterFourierItem_Click( object sender, System.EventArgs e ) { FrequencyFilterForm form = new FrequencyFilterForm( ); form.InputRange = new IntRange( 0, width >> 1 ); form.OutputRange = new IntRange( 0, width >> 1 ); if ( form.ShowDialog( ) == DialogResult.OK ) { backup = (ComplexImage) image.Clone( ); // create and apply filter FrequencyFilter filter = new FrequencyFilter( form.OutputRange ); filter.Apply( image ); UpdateNewImage( ); } }