public static void StartSession(DataDisplayModes mode) { consoleSB = new StringBuilder(); //Console.SetOut(File.AppendText($"{workingDirectory}{SessionId}.log")); Console.WriteLine($"Session '{SessionId}' starts at {DateTime.Now.ToString("yyyy-MM-dd HH\\:mm\\:sszzz")} ({DateTime.UtcNow.ToString("yyyy-MM-dd HH\\:mm\\:ss")} UTC)"); try { Console.Write($"Checking if Mercury-16 is connected as PHDC USB device... "); BBDMercury16Input bbdMercury16Input = new BBDMercury16Input(); waveSourceDevice = bbdMercury16Input; waveSource = bbdMercury16Input; Console.WriteLine("OK"); } catch (System.IO.IOException) { Console.WriteLine("not connected"); } if (waveSource == null) { try { Console.Write($"Checking if Arduino is connected on port '{arduinoPort}', expecting The 8x8 Matrix as data-source... "); waveSource = new BBD8x8MatrixInput(arduinoPort, 64); Console.WriteLine("OK"); } catch (System.IO.IOException) { Console.WriteLine("not connected"); } } if (waveSource == null) { Console.Write($"No hardware source was detected, so creating an 8kHz 16ch sine signal generator as data-source... "); waveSource = new SineInput(8000, 16); Console.WriteLine("OK"); } int fftSize = 1024 * 16; frequencyStep = (float)waveSource.SamplesPerSecond / fftSize; MultiChannelInput <IDataChannel> normalizedSource = FilterManager.ApplyFilters(waveSource, new NormalizeFilter() { Settings = new NormalizeFilterSettings() { Enabled = true, SampleCount = waveSource.SamplesPerSecond * 3, Gain = 10.0f } }); //MultiChannelInput<IDataChannel> filteredSource = FilterManager.ApplyFilters(waveSource, new ByPassFilter() { Settings = new ByPassFilterSettings() { Enabled = true } }); //MultiChannelInput<IDataChannel> filteredSource = FilterManager.ApplyFilters(waveSource, new FillFilter() { Settings = new FillFilterSettings() { Enabled = true, ValueToFillWith = 0.75f } }); //MultiChannelInput<IDataChannel> averagedSource = FilterManager.ApplyFilters(normalizedSource, new MovingAverageFilter() { Settings = new MovingAverageFilterSettings() { Enabled = true, InputDataDimensions = 2, MovingAverageLength = 10 } }); wfo = new WaveFileOutput(normalizedSource, $"{workingDirectory}{SessionId}.wav"); wfo.DataWritten += Wfo_DataWritten; //vtkfo = new VTKFileOutput(filteredSource, $"{workingDirectory}{SessionId}.vts"); //vtkfo.DataWritten += Wfo_DataWritten; //vtsfo = new SimpleVTSFileOutput(filteredSource, $"{workingDirectory}{SessionId}.vts", true); //vtsfo.DataWritten += Vtsfo_DataWritten; MultiChannelInput <IDataChannel> filteredSource = null; switch (mode) { case DataDisplayModes.NormalizedWaveform: peakToPeakValues = null; vo = new VisualOutput(normalizedSource, 25, VisualOutputMode.Waveform); break; case DataDisplayModes.FilteredSpectogram: filteredSource = FilterManager.ApplyFilters(normalizedSource, new FFTWFilter() { Settings = new FFTWFilterSettings() { Enabled = true, FFTSampleCount = fftSize, IsBackward = false, PlanningRigor = FFTPlanningRigor.Estimate, IsRealTime = true, Timeout = 300, OutputFormat = FFTOutputFormat.Magnitude, BufferSize = fftSize * 16 } }); vo = new VisualOutput(filteredSource, 25, VisualOutputMode.Spectrum); break; case DataDisplayModes.DominanceMatrix: filteredSource = FilterManager.ApplyFilters(normalizedSource, new FFTWFilter() { Settings = new FFTWFilterSettings() { Enabled = true, FFTSampleCount = fftSize, IsBackward = false, PlanningRigor = FFTPlanningRigor.Estimate, IsRealTime = true, Timeout = 300, OutputFormat = FFTOutputFormat.FrequencyMagnitudePair } }); MultiChannelInput <IDataChannel> thresholdedSource = FilterManager.ApplyFilters(filteredSource, new ThresholdFilter() { Settings = new ThresholdFilterSettings() { Enabled = true, MinValue = 0.002f, MaxValue = Single.MaxValue } }); vo = new VisualOutput(thresholdedSource, 25, VisualOutputMode.DominanceMatrix); break; case DataDisplayModes.GoertzelValues: vo = new VisualOutput(waveSource, 25, VisualOutputMode.GoertzelTable); break; } if (vo != null) { vo.RefreshVisualOutput += Vo_RefreshVisualOutput; } firstActivity = DateTime.UtcNow; Console.OutputEncoding = System.Text.Encoding.Unicode; Console.SetBufferSize(200, 500); Console.SetWindowSize(200, 63); consoleRefreshAtY = Console.CursorTop; }