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)); } } } }
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(); }
public override void PrepareProcessing() { _reader?.Dispose(); try { _reader = new System.IO.BinaryReader(System.IO.File.OpenRead(_attrFilePath.TypedGet())); } catch (Exception ex) { Parent.Context.Notify(new GraphNotification(GraphNotification.NotificationType.Error, ex.ToString())); throw; } if (_reader != null) { _reader.BaseStream.Seek(0, System.IO.SeekOrigin.Begin); _portOut.PrepareProcessing(); _portTrigger.PrepareProcessing(); _buffer = new TimeLocatedBuffer1D <double>(_portOut.Buffer.Capacity, _portOut.Samplerate); _endOfStream = false; if (_portTrigger.Connection == null) { _startTime = new TimeStamp(0); } } else { throw new Exception("File node: did not specify input"); } _lastStatePosition = 0; _sampleSize = _dataTypeSizes[_attrDataType.TypedGet()]; _sampleGetterFunc = () => { throw new System.IO.EndOfStreamException(); }; switch (_attrDataType.TypedGet()) { case DataType.Float32: _sampleGetterFunc = () => _reader.ReadSingle(); break; case DataType.Float64: _sampleGetterFunc = () => _reader.ReadDouble(); break; case DataType.Int16: _sampleGetterFunc = () => _reader.ReadInt16(); break; case DataType.Int32: _sampleGetterFunc = () => _reader.ReadInt32(); break; case DataType.Int64: _sampleGetterFunc = () => _reader.ReadInt64(); break; default: throw new NotImplementedException(); } }