Exemple #1
0
        public static void Main(string[] args)
        {
            var bitManipulator = new BitManipulator();
            var myBits         = bitManipulator.StringToBits(Resources.BigLebowskiQuote);

            Console.WriteLine($"Length of string in bits: {myBits.Count}");

            var audioStream = new MemoryStream();

            var binaryFskAnalyzerSettings = new Bell103BinaryFskAnalyzerSettings();

            var audioGenerator    = new AudioGenerator(audioStream);
            var fskAudioGenerator = new FskAudioGenerator(audioGenerator);

            fskAudioGenerator.GenerateAudio(binaryFskAnalyzerSettings.BaudRate,
                                            binaryFskAnalyzerSettings.SpaceFrequency, binaryFskAnalyzerSettings.MarkFrequency, myBits);

            var audioLengthInMicroseconds = (int)(myBits.Count * Math.Pow(10, 6) / binaryFskAnalyzerSettings.BaudRate);

            Console.WriteLine($"Length of audio in seconds: {audioLengthInMicroseconds / Math.Pow(10, 6):N1}");
            Console.WriteLine();

            Console.WriteLine(Resources.BigLebowskiQuote);
            Console.WriteLine();

            AudioAnalyzer.Play(audioStream, audioLengthInMicroseconds / 1000);

            audioGenerator    = new AudioGenerator(audioStream);
            fskAudioGenerator = new FskAudioGenerator(audioGenerator);
            fskAudioGenerator.GenerateAudio(binaryFskAnalyzerSettings.BaudRate,
                                            binaryFskAnalyzerSettings.SpaceFrequency, binaryFskAnalyzerSettings.MarkFrequency, myBits);

            var binaryFskAnalyzer = new BinaryFskAnalyzer(new AudioAnalyzer(audioStream, audioGenerator), new ZeroCrossingsFrequencyDetector(), binaryFskAnalyzerSettings);

            Console.WriteLine($"Window position start {binaryFskAnalyzerSettings.WindowPositionStartMicroseconds:N3} us, window position end {binaryFskAnalyzerSettings.WindowPositionEndMicroseconds:N3} us, window position increment {binaryFskAnalyzerSettings.WindowPositionIncrementMicroseconds:N3} us");
            Console.WriteLine($"Window length start {binaryFskAnalyzerSettings.WindowLengthStartMicroseconds:N3} us, window length end {binaryFskAnalyzerSettings.WindowLengthEndMicroseconds:N3} us, window length increment {binaryFskAnalyzerSettings.WindowLengthIncrementMicroseconds:N3} us");
            Console.WriteLine();

            var result = binaryFskAnalyzer.AnalyzeSignal();
            var bits   = new List <bool>();

            foreach (var frame in result.AnalysisFrames)
            {
                if (frame.Bit.HasValue == true)
                {
                    bits.Add(frame.Bit.Value);
                }
            }

            Console.WriteLine("Rendering bytes");
            Console.WriteLine();
            var renderer = (IRenderer) new RowRenderer();

            renderer.Render(BitManipulator.BitsToBytes(bits));
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Rendering ASCII");
            Console.WriteLine();
            renderer = new AsciiRenderer();
            renderer.Render(BitManipulator.BitsToBytes(bits));
            Console.WriteLine();

            Console.WriteLine("Done");
            Console.ReadLine();
        }
        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))));
                    }
                }
            }
        }