コード例 #1
0
        private void AnalyzeRaw(ChunkArgs e)
        {
            // logger.Debug(string.Format("ANALYZE RAW Real: {0} Step: {1} Bits: {2} Sample rate: {3} Data length: {4} Fft Length: {5}", _real, _step, _converter.BitRate, e.SamplingRate, e.RawData.Length, _fftLength));

            if (_real)
            {
                // NetRadio.Devices.G3XDdc.Signal.G3XDdcIfProvider
                for (var n = 0; n < e.RawData.Length; n += _step)
                {
                    var f = _converter.Convert(e.RawData, n);
                    Add(f, 0);
                }
            }
            else
            {
                // NetRadio.Devices.G3XDdc.Signal.G3XDdcDdc1StreamProvider
                for (var n = 0; n < e.RawData.Length; n += _step * 2)
                {
                    var r = _converter.Convert(e.RawData, n);
                    var i = _converter.Convert(e.RawData, n + _step);
                    Add(r, i);
                }
            }

            if (ForceInstantFft)
            {
                CalculateFft();
            }
        }
コード例 #2
0
        public void ConvertToFloatBase_Success()
        {
            Assert.True(floatConverter.CanConvert(typeof(float)));

            var dict = floatConverter.Convert((object)123f, settings);

            Assert.Equal("123", dict);

            var result = floatConverter.ConvertBack(dict, typeof(float), settings);

            Assert.Equal(123f, result);
        }
コード例 #3
0
        public void FloatConverter_CorrectConversionTest()
        {
            Array[] data = new float[][]
            {
                new float[] { 0f, 1f },
                new float[] { 0.4f, 0.6f },
            };

            var converter = new FloatConverter();
            var sut       = converter.Convert(data, 2, 2);

            var expectation = new ushort[] { 0, ushort.MaxValue, 26214, 39321 };

            sut.Should().BeEquivalentTo(expectation);
        }
コード例 #4
0
        private void Ddc1_DataRecieved(object sender, Ddc1CallbackArgs e)
        {
            if (FloatChunkRecieved == null)
            {
                return;
            }

            var iqRate = e.SamplingRate;

            iqRate = SeperateIq ? iqRate : iqRate * 2;

            _floatBuffer.Initialize();

            DataLength = e.Data.Length;
            var j = 0;

            for (var i = 0; i < e.Data.Length; i += _step)
            {
                _floatBuffer[j] = _converter.Convert(e.Data, i);
                j++;
            }

            FloatChunkRecieved(this, new FloatArgs(_floatBuffer, iqRate, j));
        }
コード例 #5
0
        public void TestFloatConverter()
        {
            FloatConverter floatConverter = new FloatConverter();

            Assert.True(floatConverter.CanConvertTo(typeof(float)));
            Assert.True(floatConverter.CanConvertTo(typeof(double)));
            Assert.True(floatConverter.CanConvertTo(typeof(decimal)));

            Assert.False(floatConverter.CanConvertTo(typeof(string)));
            Assert.False(floatConverter.CanConvertTo(typeof(int)));
            Assert.False(floatConverter.CanConvertTo(typeof(Enum)));

            Assert.True(floatConverter.CanConvertFrom(" 10  "));
            Assert.True(floatConverter.CanConvertFrom("1.0"));
            Assert.True(floatConverter.CanConvertFrom(" .2"));
            Assert.True(floatConverter.CanConvertFrom(" 0      "));
            Assert.True(floatConverter.CanConvertFrom(" 1,000,000"));
            Assert.True(floatConverter.CanConvertFrom(" 123.456  "));
            Assert.True(floatConverter.CanConvertFrom(".123"));
            Assert.True(floatConverter.CanConvertFrom(" 1,234,567.89  "));
            Assert.True(floatConverter.CanConvertFrom("1e2"));
            Assert.True(floatConverter.CanConvertFrom("12E-3"));
            Assert.True(floatConverter.CanConvertFrom("1.2E4"));

            Assert.False(floatConverter.CanConvertFrom("abc"));
            Assert.False(floatConverter.CanConvertFrom(""));
            Assert.False(floatConverter.CanConvertFrom("   "));
            Assert.False(floatConverter.CanConvertFrom("."));
            Assert.False(floatConverter.CanConvertFrom("abc123"));
            Assert.False(floatConverter.CanConvertFrom("1 2 3"));
            Assert.False(floatConverter.CanConvertFrom("123e"));
            Assert.False(floatConverter.CanConvertFrom("e123"));

            Assert.Equal(1.0f, floatConverter.Convert(typeof(float), "1"));
            Assert.Equal(0.123d, floatConverter.Convert(typeof(double), " .123"));
            Assert.Equal(1234567m, floatConverter.Convert(typeof(decimal), "1,234,567  "));
            Assert.Equal(123.0m, floatConverter.Convert(typeof(object), "  123"));
            Assert.Equal(12.3f, floatConverter.Convert(typeof(float), "   1,2.3"));
            Assert.Equal(123.456d, floatConverter.Convert(typeof(double), "123.456  "));
            Assert.Equal(1.00001m, floatConverter.Convert(typeof(decimal), "00001.00001"));
            Assert.Equal(0.123m, floatConverter.Convert(typeof(object), ".123  "));
            Assert.Equal(1234567.89f, floatConverter.Convert(typeof(float), "1,234,567.89  "));
            Assert.Equal(123456789.0d, floatConverter.Convert(typeof(double), "  1,2,3,4,5,6,7,8,9"));
            Assert.Equal(0.0m, floatConverter.Convert(typeof(decimal), "  00000  "));
            Assert.Equal(1234.0m, floatConverter.Convert(typeof(object), "1,234"));
            Assert.Equal(12000.0f, floatConverter.Convert(typeof(float), "12e3"));
            Assert.Equal(0.01d, floatConverter.Convert(typeof(double), "10e-3"));
            Assert.Equal(10000000000000000.0m, floatConverter.Convert(typeof(decimal), "  10E+15  "));
            Assert.Equal(0.00035m, floatConverter.Convert(typeof(object), "3.5E-4"));

            Assert.Throws <InvalidOperationException>(() => floatConverter.Convert(typeof(float), "."));
            Assert.Throws <InvalidOperationException>(() => floatConverter.Convert(typeof(double), "122abc"));
            Assert.Throws <InvalidOperationException>(() => floatConverter.Convert(typeof(decimal), " 1 2 3 4 "));
            Assert.Throws <InvalidOperationException>(() => floatConverter.Convert(typeof(object), "123..123"));
            Assert.Throws <InvalidOperationException>(() => floatConverter.Convert(typeof(float), "e"));
            Assert.Throws <InvalidOperationException>(() => floatConverter.Convert(typeof(double), "1E"));
            Assert.Throws <InvalidOperationException>(() => floatConverter.Convert(typeof(decimal), " 3E"));
            Assert.Throws <InvalidOperationException>(() => floatConverter.Convert(typeof(object), "   3e4E-1   "));
        }