Exemple #1
0
        public int Peek(TimeLocatedBuffer buffer, int length = -1)
        {
            lock (this) {
                if (buffer.Samplerate != _rate)
                {
                    throw new InvalidOperationException();
                }

                if (length == -1)
                {
                    length = buffer.GetSamples().Length;
                }
                else if (length > buffer.Length)
                {
                    length = buffer.Length;
                }

                var begin  = BeginTime;
                var result = Peek(buffer.GetSamples(), 0, length);

                buffer.SetWritten(result);
                buffer.SetTime(begin.Add(result, _rate));
                return(result);
            }
        }
Exemple #2
0
        public int Enqueue(TimeLocatedBuffer buffer, int offset, int sampleCount)
        {
            lock (this) {
                if (buffer.Samplerate != _rate)
                {
                    throw new InvalidOperationException();
                }

                var samples = buffer.GetSamples();

                var written = Enqueue(samples, offset, sampleCount);
                _timeBufEnd = _timeBufEnd.Add(written, _rate);

                var newEndTime = buffer.FrontTime.Add(offset + written, _rate);

                if (!newEndTime.Equals(_timeBufEnd))
                {
                    if (!IgnoreOverflow)
                    {
                        // TODO: Commented out for the moment.
                        //       FFT and Data use different time counting mechanisms.
                        //       Enqueue uses the counting mechanism of time data.
                        //       So this gives false error reports.
                        //       Need to replace the node system with a good one.
                        //NodeSystemSettings.Instance.SystemHost.ReportError($"Ring Buffer: Missing samples. Buffer Timestamp: { newEndTime } \t Ring Timestamp: { _timeBufEnd }");
                    }
                    _timeBufEnd = new TimeStamp(newEndTime);
                }

                return(written);
            }
        }