Beispiel #1
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();
                    }
                }
            }
        }
Beispiel #2
0
        public Resampler(Graph g) : base("Resampler", g)
        {
            _input  = new InputPortData1D(this, "In");
            _output = new OutputPortData1D(this, "Out");

            _attrSamplerateOut          = new AttributeValueInt(this, "Output Samplerate", "Hz");
            _attrSamplerateOut.Changed += (s, e) => _output.Samplerate = _attrSamplerateOut.TypedGet();
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public MetricFile(Graph g) : base("File Node", g)
        {
            _portOut     = new OutputPortData1D(this, "Out");
            _portTrigger = new InputPortValueDouble(this, "Trig");

            _attrFilePath   = new AttributeValueFile(this, "Path", true);
            _attrSamplerate = new AttributeValueInt(this, "Samplerate", 1000);
            _attrDataType   = new AttributeValueEnum <DataType>(this, "DataType");

            _attrSamplerate.Changed += (o, e) => _portOut.Samplerate = _attrSamplerate.TypedGet();

            _attrSamplerate.SetRuntimeReadonly();
            _attrDataType.SetRuntimeReadonly();
            _attrFilePath.SetRuntimeReadonly();
        }
Beispiel #5
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;
                }
            }
        }
Beispiel #6
0
        private void _numOfLines1D_Changed(object sender, AttributeChangedEventArgs e)
        {
            var countShouldBe = _attrNumOfLines1D.TypedGet();
            var countIs       = _lines.Count(line => line.Port.DataType == PortDataTypes.TypeIdSignal1D);

            if (countIs < countShouldBe)
            {
                for (int i = countIs; i < countShouldBe; i++)
                {
                    CreateLine(PortDataTypes.TypeIdSignal1D);
                }
            }
            else if (countIs > countShouldBe)
            {
                for (int i = countShouldBe; i < countIs; i++)
                {
                    RemoveLine(_lines.Last(line => line.Port.DataType == PortDataTypes.TypeIdSignal1D));
                }
            }

            BuildDataLineView();
        }
Beispiel #7
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();
                }
            };
        }
Beispiel #8
0
        private void FillBuffer(object arg)
        {
            if (_endOfStream)
            {
                return;
            }

            var currentTime = Parent.GetCurrentClockTime();
            var bufferTime  = _portOut.Buffer.Time;

            var timeDiff = currentTime.AsSeconds() - bufferTime.AsSeconds();

            if (timeDiff > 0)
            {
                var samplesToWrite = timeDiff * _portOut.Samplerate;
                var free           = (int)Math.Min(_portOut.Buffer.Free, samplesToWrite);
                if (free > 0)
                {
                    var written = 0;

                    if (!_startTime.HasValue)
                    {
                        for (; written < free; written++)
                        {
                            _buffer.Data[written] = 0;
                        }
                    }
                    else
                    {
                        var timeLeftTillStart    = _startTime.Value - bufferTime;
                        var samplesLeftTillStart = Math.Min(free, timeLeftTillStart.ToRate(_portOut.Samplerate));

                        for (; written < samplesLeftTillStart; written++)
                        {
                            _buffer.Data[written] = 0;
                        }

                        try {
                            for (; written < free; written++)
                            {
                                _buffer.Data[written] = _sampleGetterFunc();
                            }
                        } catch (System.IO.EndOfStreamException) {
                            _endOfStream = true;
                        }
                    }

                    _buffer.SetWritten(written);
                    _portOut.Buffer.Write(_buffer);

                    if ((_reader.BaseStream.Position - _lastStatePosition) / _sampleSize >= 10 * _attrSamplerate.TypedGet())
                    {
                        _lastStatePosition = _reader.BaseStream.Position;
                        Parent.Pause();
                        Parent.Flush();

                        Parent.Resume();
                    }

                    if (_endOfStream)
                    {
                        Parent.Context.Notify(new GraphNotification(GraphNotification.NotificationType.Info, "End of file"));
                        Parent.Stop();
                    }
                }
            }
        }
 public override void EditStart()
 {
     _box.UserControl.Text = _attr.TypedGet().ToString();
 }