Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
        public void PostData(OutputPort port, TimeLocatedBuffer buffer)
        {
            var output = _outputs[port];

            if (!output.IsDone)
            {
                throw new InvalidOperationException("can't change buffer before sent");
            }
            output.SetBuffer(buffer);
        }
Exemplo n.º 4
0
        public TimeLocatedBuffer(TimeLocatedBuffer cp)
        {
            _buffer         = new double[cp._buffer.Length];
            _writtenSamples = cp._writtenSamples;
            CurrentTime     = cp.CurrentTime;
            Samplerate      = cp.Samplerate;

            Array.Copy(
                destinationArray:   _buffer,
                sourceArray:        cp._buffer,
                length:             cp._buffer.Length
                );
        }
Exemplo n.º 5
0
 public void SendData(TimeLocatedBuffer data)
 {
     //foreach (var input in Connections) {
     //    var port = (DataInputPort)input;
     //    if (port.Queue.Capacity - port.Queue.Length < data.WrittenSamples) {
     //        while (port.Queue.Capacity - port.Queue.Length < data.WrittenSamples) {
     //            //System.Diagnostics.Debug.WriteLine("Waiting for the next port...");
     //            System.Threading.Thread.Sleep(1);
     //        }
     //    }
     //    port.RecieveData(data);
     //}
     Graph.PostData(this, data);
 }
Exemplo n.º 6
0
 public void SetBuffer(TimeLocatedBuffer buf)
 {
     lock (_dataLock) {
         if (buf == null)
         {
             throw new InvalidOperationException("Can't be null");
         }
         Data = buf;
         for (int i = 0; i < TargetWrittenTo.Length; i++)
         {
             TargetWrittenTo[i] = 0;
         }
         _dataDone = false;
     }
 }
Exemplo n.º 7
0
        public int Dequeue(TimeLocatedBuffer buffer, int length = -1)
        {
            lock (this) {
                var result = Peek(buffer, length);
                Skip(result);
                return(result);

                //if (length == -1) length = buffer.GetSamples().Length;
                //if (buffer.Samplerate != _rate) throw new InvalidOperationException();

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

                //buffer.SetWritten(result);
                //buffer.SetTime(begin.Add(result, _rate));
                //return result;
            }
        }
Exemplo n.º 8
0
        public int RecieveData(TimeLocatedBuffer buf, int offset, int sampleCount)
        {
            if (buf.Length % (_fftSize / 2) != 0)
            {
                throw new FFTDataLengthException();
            }

            if (Queue.Length == Queue.Capacity)
            {
                NodeSystemSettings.Instance.SystemHost.ReportError(Parent, "Data Input: Buffer full. Data loss. Stopping");
                NodeSystemSettings.Instance.SystemHost.StopProcessing();
                return(-1);
            }
            else
            {
                var written = Queue.Enqueue(buf, offset, sampleCount);
                DataAvailable?.Invoke(this, Queue.Length);
                return(written);
            }
        }
Exemplo n.º 9
0
 public int RecieveData(TimeLocatedBuffer buf, int offset, int sampleCount)
 {
     if (Queue == null)
     {
         NodeSystemSettings.Instance.SystemHost.ReportError(Parent, "Data Input: Buffer not initialized");
         NodeSystemSettings.Instance.SystemHost.StopProcessing();
         return(-1);
     }
     else if (Queue.Length == Queue.Capacity)
     {
         NodeSystemSettings.Instance.SystemHost.ReportError(Parent, "Data Input: Buffer full. Data loss. Stopping");
         NodeSystemSettings.Instance.SystemHost.StopProcessing();
         return(-1);
     }
     else
     {
         var written = Queue.Enqueue(buf, offset, sampleCount);
         DataAvailable?.Invoke(this, Queue.Length);
         return(written);
     }
 }
Exemplo n.º 10
0
        public bool InitBuffer(int queueSamples = -1, int bufferSamples = -1)
        {
            try {
                if (Queue == null || Queue.Samplerate != Samplerate || (queueSamples >= 0 && Queue.Capacity < queueSamples))
                {
                    Queue = new SignalRingBuffer(queueSamples < 0 ? NodeSystemSettings.Instance.SystemHost.GetDefaultRingBufferSize(Samplerate) : queueSamples, Samplerate);
                }

                if (Buffer == null || Buffer.Samplerate != Samplerate || (bufferSamples >= 0 && Buffer.Length < bufferSamples))
                {
                    Buffer = TimeLocatedBuffer.Default(Samplerate);
                }

                Queue.Clear();
                Buffer.SetTime(TimeStamp.Zero());

                return(true);
            } catch (Exception e) {
                NodeSystemSettings.Instance.SystemHost.ReportError(Parent, $"InitBuffer of {Parent.Name}: {e}");
                return(false);
            }
        }
Exemplo n.º 11
0
 public void SendData(TimeLocatedBuffer data)
 {
     Graph.PostData(this, data);
 }
Exemplo n.º 12
0
 public void PostData(OutputPort port, TimeLocatedBuffer buffer)
 {
     _processor.PostData(port, buffer);
 }
Exemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="buf"></param>
 /// <returns>Returns number of samples taken from buffer</returns>
 public int RecieveData(TimeLocatedBuffer buf)
 {
     return(RecieveData(buf, 0, buf.WrittenSamples));
 }
Exemplo n.º 14
0
 public int Enqueue(TimeLocatedBuffer buffer)
 {
     return(Enqueue(buffer, 0, buffer.WrittenSamples));
 }