Example #1
0
        public TimeDisplayWaterfall(Graph g) : base("Waterfall", g)
        {
            _port = new InputPortDataFFT(this, "In");

            _attrDbMax      = new AttributeValueDouble(this, "dB max", "dB");
            _attrDbMin      = new AttributeValueDouble(this, "dB min", "dB");
            _attrTimeWindow = new AttributeValueInt(this, "Window Length", "ms");

            _attrDbMin.Changed += (s, e) => {
                if (_attrDbMin.TypedGet() >= _attrDbMax.TypedGet())
                {
                    _attrDbMin.Set(_attrDbMax.TypedGet() - 0.0001);
                }
                if (_wnd != null)
                {
                    _wnd.DbMin = (float)_attrDbMin.TypedGet();
                }
            };

            _attrDbMax.Changed += (s, e) => {
                if (_attrDbMax.TypedGet() <= _attrDbMin.TypedGet())
                {
                    _attrDbMax.Set(_attrDbMin.TypedGet() + 0.0001);
                }
                if (_wnd != null)
                {
                    _wnd.DbMax = (float)_attrDbMax.TypedGet();
                }
            };

            _attrTimeWindow.Changed += (s, e) => {
                UpdateWindowSettings();
            };
            _attrTimeWindow.SetRuntimeReadonly();
        }
Example #2
0
        public override void PrepareProcessing()
        {
            if (_attrLookAheadFactor.TypedGet() <= 0)
            {
                throw new ArgumentOutOfRangeException(_attrLookAheadFactor.Name, "Lookahead Factor must be > 0");
            }

            if (_attrWindowLength.TypedGet() <= 0)
            {
                throw new ArgumentOutOfRangeException(_attrWindowLength.Name, "Window length must be > 0 ms");
            }

            CreateChannels();

            lock (_wndLock) {
                lock (_processingLock) {
                    if (_wnd == null || _wnd.IsDisposed)
                    {
                        try {
                            CreateWindow();
                        } catch (Exception e) {
                            throw new InvalidOperationException("Error while creating window: " + e);
                        }
                    }

                    _wnd.Run = true;
                    if (_wnd.IsLoaded)
                    {
                        _wnd.PrepareProcessing();
                    }
                }
            }
        }
Example #3
0
        public override void Process()
        {
            if (_attrStartAt.TypedGet() == SustainMode.StartAtFallingEdge)
            {
                foreach (var tuple in _portIn.Read().ZipWithValueInput(_portThresh))
                {
                    if (tuple.Sample >= tuple.Scalar)
                    {
                        _timeBecomeInactive = tuple.Stamp.Increment(_attrActiveDurationMillis.TypedGet() / 1000.0);
                        if (_active == TristateActive.Inactive)
                        {
                            _active = TristateActive.Active;
                            _portOut.BufferForTransfer(new TimeLocatedValue <double>(1, tuple.Stamp));
                        }
                    }
                    else
                    {
                        if (_active == TristateActive.Active && _timeBecomeInactive <= tuple.Stamp)
                        {
                            _active = TristateActive.Inactive;
                            _portOut.BufferForTransfer(new TimeLocatedValue <double>(0, tuple.Stamp));
                        }
                    }
                }
            }
            else if (_attrStartAt.TypedGet() == SustainMode.StartAtRisingEdge)
            {
                foreach (var tuple in _portIn.Read().ZipWithValueInput(_portThresh))
                {
                    if (tuple.Sample >= tuple.Scalar)
                    {
                        if (_active == TristateActive.Inactive)
                        {
                            _timeBecomeInactive = tuple.Stamp.Increment(_attrActiveDurationMillis.TypedGet() / 1000.0);
                            _active             = TristateActive.Active;
                            _portOut.BufferForTransfer(new TimeLocatedValue <double>(1, tuple.Stamp));
                        }
                    }
                    else
                    {
                        if (_active == TristateActive.BecomingInactive)
                        {
                            _active = TristateActive.Inactive;
                        }
                    }

                    if (_active == TristateActive.Active && _timeBecomeInactive <= tuple.Stamp)
                    {
                        _active = TristateActive.BecomingInactive;
                        _portOut.BufferForTransfer(new TimeLocatedValue <double>(0, tuple.Stamp));
                    }
                }
            }
        }
Example #4
0
        private void attrValue_Changed(object sender, AttributeChangedEventArgs e)
        {
            var time = Parent?.GetCurrentClockTime();

            if (time != null)
            {
                System.Diagnostics.Debug.WriteLine("Value time: " + time.Value);
            }
            TimeValue = new TimeLocatedValue <double>(_attrValue.TypedGet(), time ?? TimeStamp.Zero);
        }
Example #5
0
        public void OnLoad(NodeGraphNode node)
        {
            _slider               = new NodeGraphControl.Controls.NodeControlSlider(node);
            _slider.Position      = new Point(30, 10);
            _slider.Size          = new Size(70, 20);
            _slider.ValueChanged += Slider_ValueChanged;
            _slider.Max           = _attrMax.TypedGet();
            _slider.Min           = _attrMin.TypedGet();
            _slider.Value         = _attrValue.TypedGet();
            _slider.Steps         = _attrSteps.TypedGet();

            node.Controls.Add(_slider);
        }
Example #6
0
 public override void Process()
 {
     foreach (var line in _lines)
     {
         if (line.Port.Connection != null)
         {
             if (line is RecorderLine1D)
             {
                 var l     = (RecorderLine1D)line;
                 var count = l.Port.Available * 1000 / (double)l.Port.Samplerate - _attrPrebufferLengthMs.TypedGet();
                 if (count > 0)
                 {
                     ProcessSignal1D(l, (int)(count / 1000.0 * l.Port.Samplerate));
                 }
             }
             else if (line is RecorderLineValue)
             {
                 var l = (RecorderLineValue)line;
                 ProcessValues(l);
             }
         }
     }
 }
Example #7
0
 private void UpdateSamplerate()
 {
     if (_portIn.Samplerate > 0)
     {
         _samplesPerRms = (int)(_attrMilliseconds.TypedGet() * _portIn.Samplerate / 1000);
         if (_samplesPerRms > 2)
         {
             _portOut.Samplerate = _portIn.Samplerate / _samplesPerRms;
         }
         else
         {
             _portOut.Samplerate = 0;
         }
     }
 }
Example #8
0
        private void UpdateWindowSettings()
        {
            var frameDuration = _port.FFTSize * 1000 / (double)Samplerate;
            var frameCount    = _attrTimeWindow.TypedGet() / frameDuration;

            lock (_wndLock) {
                if (_wnd != null && !_wnd.IsDisposed)
                {
                    _wnd.PrepareProcessing((int)frameCount);
                    _wnd.DbMin = (float)_attrDbMin.TypedGet();
                    _wnd.DbMax = (float)_attrDbMax.TypedGet();
                    _wnd.Run   = true;
                }
            }
        }
Example #9
0
        public MetricFilter(Graph graph) : base("Filter", graph)
        {
            _portInp = new InputPortData1D(this, "In");
            _portOut = new OutputPortData1D(this, "Out");

            _portInp.SamplerateChanged += portInp_SamplerateChanged;

            _attrCenterFrequency = new AttributeValueDouble(this, "Center", "Hz");
            _attrPeakGainDb      = new AttributeValueDouble(this, "Gain", "dB");
            _attrQFactor         = new AttributeValueDouble(this, "Q");
            _attrType            = new AttributeValueEnum <Biquad.BiquadType>(this, "Type");

            _attrCenterFrequency.Changed += (s, e) => _bpf.Fc = _portOut.Samplerate > 0 ? _attrCenterFrequency.TypedGet() / _portOut.Samplerate : 0;
            _attrPeakGainDb.Changed      += (s, e) => _bpf.PeakGainDb = _attrPeakGainDb.TypedGet();
            _attrQFactor.Changed         += (s, e) => _bpf.Q = _attrQFactor.TypedGet();
            _attrType.Changed            += (s, e) => _bpf.Type = _attrType.TypedGet();
        }
Example #10
0
        public MetricValueRange(Graph graph) : base("Range", graph)
        {
            _portOut = new OutputPortValueDouble(this, "Out");

            _attrValue = new AttributeValueDouble(this, "Value", IsRunning);
            _attrMax   = new AttributeValueDouble(this, "Max", IsRunning);
            _attrMin   = new AttributeValueDouble(this, "Min", IsRunning);
            _attrSteps = new AttributeValueInt(this, "Steps", IsRunning);

            _attrValue.Changed += (s, e) => {
                if (State == Graph.State.Running)
                {
                    SendValue(_attrValue.TypedGet());
                }
            };

            _attrMax.Changed += (s, e) => {
                if (_slider != null)
                {
                    _slider.Max = _attrMax.TypedGet();
                }
            };

            _attrMin.Changed += (s, e) => {
                if (_slider != null)
                {
                    _slider.Min = _attrMin.TypedGet();
                }
            };

            _attrSteps.Changed += (s, e) => {
                if (_slider != null)
                {
                    _slider.Steps = _attrSteps.TypedGet();
                }
            };
        }
 public override void EditStart()
 {
     _box.UserControl.Text = _attr.TypedGet().ToString(System.Globalization.CultureInfo.InvariantCulture);
 }
Example #12
0
        public override void Process()
        {
            var count = _portIn.Count;

            for (int i = 0; i < count; i++)
            {
                TimeLocatedValue <double> value;
                if (_portIn.TryDequeue(out value))
                {
                    _portOut.BufferForTransfer(new TimeLocatedValue <double>(value.Value, value.Stamp.Increment(_attrMillisDelay.TypedGet() / 1000.0)));
                }
                else
                {
                    break;
                }
            }
        }
Example #13
0
 public override void StartProcessing()
 {
     SendValue(_attrValue.TypedGet());
 }
Example #14
0
 private void portInp_SamplerateChanged(object sender, SamplerateChangedEventArgs e)
 {
     _portOut.Samplerate = _portInp.Samplerate;
     _bpf.Fc             = _attrCenterFrequency.TypedGet() / _portInp.Samplerate;
 }
Example #15
0
        // ----------------------------------------------------------------------------------------------------
        // HELPERS

        private void InitBuffer()
        {
            _samplesToKeep = (int)(_portInp.Samplerate * _attrMillis.TypedGet() / 1000);
            _portInp.PrepareProcessing(2 * _samplesToKeep, 2 * _samplesToKeep);
            _portOut.PrepareProcessing(2 * _samplesToKeep, 2 * _samplesToKeep);
        }