private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { TestRunnerArguments testRunnerArguments = null; try { testRunnerArguments = ArgumentProcessor.ProcessArguments( new FormInput { SpaceFrequency = spaceFrequency.Text, MarkFrequency = markFrequency.Text, Tolerance = tolerance.Text, BaudStart = baudStart.Text, BaudIncrement = baudIncrement.Text, BaudEnd = baudEnd.Text, BoostStart = boostStart.Text, BoostIncrement = boostIncrement.Text, BoostEnd = boostEnd.Text, WriteWavFiles = writeWavFiles.Checked, PlayAudio = playAudio.Checked, TestString = testString.Text } ); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Input validation"); return; } var testRunner = new TestRunner(); testRunner.FskAnalyzer.AnalysisCompleted += AnalysisCompletedHandler; testRunner.SignalGenerationCompleted += SignalGenerationCompletedHandler; testRunner.Run(testRunnerArguments); }
public void Run(TestRunnerArguments arguments) { var fileTimestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss"); var bitManipulator = new BitManipulator(); var bits = bitManipulator.StringToBits(arguments.TestString); for (var baudRate = arguments.BaudStart; baudRate <= arguments.BaudEnd; baudRate += arguments.BaudIncrement) { for (var loopBoostFrequency = arguments.BoostStart; loopBoostFrequency <= arguments.BoostEnd; loopBoostFrequency += arguments.BoostIncrement) { _binaryFskAnalyzerSettings = new Bell103BinaryFskAnalyzerSettings { SpaceFrequency = arguments.SpaceFrequency, MarkFrequency = arguments.MarkFrequency, BaudRate = baudRate, FrequencyDeviationTolerance = arguments.Tolerance }; _audioStream = new MemoryStream(); _audioGenerator = new AudioGenerator(_audioStream); _fskAudioGenerator = new FskAudioGenerator(_audioGenerator); _fskAudioGenerator.GenerateAudio(_binaryFskAnalyzerSettings.BaudRate, _binaryFskAnalyzerSettings.SpaceFrequency, _binaryFskAnalyzerSettings.MarkFrequency, bits); var audioLengthInMicroseconds = (int)(bits.Count * Math.Pow(10, 6) / _binaryFskAnalyzerSettings.BaudRate); _audioStream = new MemoryStream(); _audioGenerator = new AudioGenerator(_audioStream); _fskAudioGenerator = new FskAudioGenerator(_audioGenerator); var samples = _fskAudioGenerator.GenerateAudio(_binaryFskAnalyzerSettings.BaudRate, _binaryFskAnalyzerSettings.SpaceFrequency, _binaryFskAnalyzerSettings.MarkFrequency, bits); SignalGenerationComplete(bits.Count, audioLengthInMicroseconds, samples, _audioAnalyzer.SampleRate); if (arguments.WriteFaveFiles == true) { using (var file = File.Create($"{fileTimestamp}_{baudRate}_baud.wav")) { var previousPosition = _audioStream.Position; _audioStream.Position = 0; _audioStream.CopyTo(file); _audioStream.Position = previousPosition; } } _binaryFskAnalyzerSettings = new Bell103BinaryFskAnalyzerSettings { SpaceFrequency = (int)(arguments.SpaceFrequency + loopBoostFrequency), MarkFrequency = (int)(arguments.MarkFrequency + loopBoostFrequency), BaudRate = baudRate, FrequencyDeviationTolerance = arguments.Tolerance }; _audioAnalyzer = new AudioAnalyzer(_audioStream, _audioGenerator, (int)loopBoostFrequency); FskAnalyzer.Initialize(_audioAnalyzer, new ZeroCrossingsFrequencyDetector(), _binaryFskAnalyzerSettings); FskAnalyzer.AnalyzeSignal(arguments.TestString); if (arguments.PlayAudio == true) { AudioAnalyzer.Play(_audioStream, (int)Math.Ceiling((audioLengthInMicroseconds / Math.Pow(10, 3)))); } } } }