コード例 #1
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));
                    }
                }
            }
        }
コード例 #2
0
        public override void Process()
        {
            var bufIn = _input.Read();
            var cnt   = bufIn.Available;

            cnt -= _resample.PutData(bufIn.Data, 0, cnt);
            if (cnt > 0)
            {
                throw new InvalidOperationException("Resampler could not consume all input samples");
            }
            _resample.Resample();

            if (_resample.OutputAvailable > 0)
            {
                var samplesToRead = Math.Min(_output.Buffer.Free, _resample.OutputAvailable);
                var actuallyRead  = _resample.GetData(_bufOutput.Data, 0, samplesToRead);
                _bufOutput.SetWritten(actuallyRead);

                var written = _output.Buffer.Write(_bufOutput);
                if (written != _bufOutput.Available)
                {
                    throw new InvalidOperationException("Not all samples could be written to output buffer");
                }
            }
        }
コード例 #3
0
 public override void Process()
 {
     if (_portInp.Available >= _samplesToKeep)
     {
         var buffer = _portInp.Read(_portOut.Buffer.Free);
         _portOut.Buffer.Write(buffer, 0, buffer.Available);
     }
 }
コード例 #4
0
        public override void Process()
        {
            var buf = _portInp.Read(_outputBuffer.Capacity);

            for (var i = 0; i < buf.Available; i++)
            {
                _outputBuffer.Data[i] = _bpf.Process(buf.Data[i]);
            }

            _outputBuffer.SetWritten(buf.Available);
            _portOut.Buffer.Write(_outputBuffer);
        }
コード例 #5
0
ファイル: MultiplyValue.cs プロジェクト: muba24/flumin-master
        public override void Process()
        {
            var bufIn = _portInp.Read(_bufOut.Capacity);

            var count  = 0;
            var output = _bufOut.Data;

            foreach (var sample in bufIn.ZipWithValueInput(_portInpVal))
            {
                output[count++] = sample.Sample * sample.Scalar;
            }

            _bufOut.SetWritten(count);
            _portOut.Buffer.Write(_bufOut.Data, 0, _bufOut.Available);
        }
コード例 #6
0
ファイル: MetricRMS.cs プロジェクト: muba24/flumin-master
        public override void Process()
        {
            var buffer  = _portIn.Read();
            var samples = buffer.Data;

            for (int i = 0; i < buffer.Available; i++)
            {
                _sum += samples[i] * samples[i];
                if (++_inputSampleCounter >= _samplesPerRms)
                {
                    _bufOut.Data[_outputSampleCounter++] = Math.Sqrt(_sum / _samplesPerRms);
                    _inputSampleCounter = 0;
                    _sum = 0;

                    if (_outputSampleCounter == _bufOut.Capacity)
                    {
                        _bufOut.SetWritten(_outputSampleCounter);
                        _portOut.Buffer.Write(_bufOut);
                        _outputSampleCounter = 0;
                    }
                }
            }
        }
コード例 #7
0
        public override void Process()
        {
            foreach (var tuple in _portIn.Read().ZipWithValueInput(_portThreshLow, _portThreshHigh))
            {
                switch (_active)
                {
                case TristateActive.Active:
                    if (tuple.Sample < tuple.Scalar && tuple.Scalar < tuple.Scalar2)
                    {
                        _active = TristateActive.Inactive;
                        _portOut.BufferForTransfer(new TimeLocatedValue <double>(0, tuple.Stamp));
                    }
                    break;

                case TristateActive.Inactive:
                    if (tuple.Sample > tuple.Scalar2 && tuple.Scalar < tuple.Scalar2)
                    {
                        _active = TristateActive.Active;
                        _portOut.BufferForTransfer(new TimeLocatedValue <double>(1, tuple.Stamp));
                    }
                    break;
                }
            }
        }
コード例 #8
0
        public override void Process()
        {
            var samplesAvailable = Math.Min(PortIn1.Available, PortIn2.Available);
            var samplesWritable  = PortOut.Buffer.Free;
            var samplesToRead    = Math.Min(samplesWritable, samplesAvailable);

            var buf1   = PortIn1.Read(samplesToRead);
            var buf2   = PortIn2.Read(samplesToRead);
            var output = OutputBuffer.Data;

            if (buf1.Available != buf2.Available)
            {
                throw new InvalidOperationException("Expected both reads to have the same sample count");
            }

            // TODO: Very vectorizable
            for (int i = 0; i < samplesAvailable; i++)
            {
                output[i] = buf1.Data[i] + buf2.Data[i];
            }

            OutputBuffer.SetWritten(samplesAvailable);
            PortOut.Buffer.Write(OutputBuffer, OutputBuffer.Available);
        }