Exemplo n.º 1
0
        public override void PrepareProcessing()
        {
            if (_precTimer == null)
            {
                _precTimer                       = new PrecisionTimer();
                _precTimer.Elapsed              += precTimer_Elapsed;
                _precTimer.Milliseconds          = _attrPeriod.TypedGet();
                _precTimer.ToleranceMilliseconds = 10;
            }

            var sampleCount = _attrSamplerate.TypedGet() * _attrPeriod.TypedGet() / 1000;

            if (_buffer == null || _buffer.Length != sampleCount)
            {
                _buffer = new double[sampleCount];
            }

            _portOut.PrepareProcessing(
                DefaultParameters.DefaultQueueMilliseconds.ToSamples(_portOut.Samplerate),
                DefaultParameters.DefaultBufferMilliseconds.ToSamples(_portOut.Samplerate)
                );

            CalculatePhaseStep();
            _phaseAcc = 0;
        }
Exemplo n.º 2
0
        public MetricFFT(Graph graph) : base("FFT", graph)
        {
            _portOut = new NodeSystemLib2.FormatDataFFT.OutputPortDataFFT(this, "out");
            _portInp = new NodeSystemLib2.FormatData1D.InputPortData1D(this, "in");

            _portInp.SamplerateChanged += (s, e) => _portOut.Samplerate = _portInp.Samplerate;

            _attrFFTSize = new NodeSystemLib2.Generic.NodeAttributes.AttributeValueInt(this, "FFT Size", "Samples",
                                                                                       (x) => x < 2 ? 2 : (int)Math.Pow(2, Math.Round(Math.Log(x, 2)))
                                                                                       );
            _attrFFTSize.SetRuntimeReadonly();
            _attrFFTSize.Changed += (s, e) => _portOut.FFTSize = _attrFFTSize.TypedGet();
            _attrFFTSize.Set(512);
        }
Exemplo n.º 3
0
        public DeviceSimulatorPort(Graph g, int portId) : base("Simulator Port", g, UniquenessBy(portId))
        {
            Id = portId;

            _portOut = new OutputPortData1D(this, "Out");

            _attrFrequency  = new NodeSystemLib2.Generic.NodeAttributes.AttributeValueDouble(this, "Frequency", "Hz");
            _attrAmplitude  = new NodeSystemLib2.Generic.NodeAttributes.AttributeValueDouble(this, "Amplitude");
            _attrSamplerate = new NodeSystemLib2.Generic.NodeAttributes.AttributeValueInt(this, "Samplerate", "Hz");
            _attrSignalType = new NodeSystemLib2.Generic.NodeAttributes.AttributeValueEnum <SignalType>(this, "Type");
            _attrPeriod     = new NodeSystemLib2.Generic.NodeAttributes.AttributeValueInt(this, "Period", "ms");
            _attrPhase      = new NodeSystemLib2.Generic.NodeAttributes.AttributeValueDouble(this, "Phase", "°");

            _attrFrequency.Changed  += (s, e) => CalculatePhaseStep();
            _attrSamplerate.Changed += (s, e) => _portOut.Samplerate = _attrSamplerate.TypedGet();

            _attrSamplerate.SetRuntimeReadonly();
            _attrPeriod.SetRuntimeReadonly();

            _attrFrequency.Set(100000);
            _attrAmplitude.Set(1);
            _attrPeriod.Set(100);
            _attrSamplerate.Set(1000000);
        }