public void AnalyzeSignal_KnownSignal_ReturnsExpectedValues()
        {
            var audioStream = new MemoryStream();

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

            fskAudioGenerator.GenerateAudio(_binaryFskAnalyzerSettings.BaudRate,
                                            _binaryFskAnalyzerSettings.SpaceFrequency, _binaryFskAnalyzerSettings.MarkFrequency,
                                            _bitManipulator.StringToBits(Resources.LoremIpsumTestString));

            var audioAnalyzer     = new AudioAnalyzer(audioStream, audioGenerator);
            var binaryFskAnalyzer = (IBinaryFskAnalyzer) new BinaryFskAnalyzer(audioAnalyzer, new ZeroCrossingsFrequencyDetector(), _binaryFskAnalyzerSettings);
            var results           = binaryFskAnalyzer.AnalyzeSignal();

            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);
                }
            }

            var ascii = BitManipulator.BitsToString(bits);

            Assert.AreEqual(Resources.LoremIpsumTestString, ascii);
        }
Esempio n. 2
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();
        }