/// <summary> /// Reads directly from the stream, ignoring the Converter, and providing /// </summary> /// <param name="count">The number of points to poll</param> /// <returns>The data packet with at most count data points added</returns> public override DataPacket ReadDirect(int count) { var toReturn = new DataPacket(); if (Sampler == null) { return(toReturn); } toReturn.AddChannel(); // Read the required number of points off of the stream count *= 4; var buffer = new float[count]; count = Sampler.Read(buffer, 0, count); if (count <= 0) { return(toReturn); } for (var k = 0; k < count; k++) { toReturn[0].Add((double)buffer[k]); } return(toReturn); }
/// <summary> /// Accepts incoming data from a previous connection. /// This is allowed to queue and store as needed. /// </summary> /// <param name="data">The data being pushed from the previous node</param> public override void AcceptIncomingData(StreamlineCore core, DataPacket data) { // Create the packet to return var toReturn = new DataPacket(); toReturn.AddChannel(); // Loop through until no data is available while ((BatchMode && data[0].Count > SmoothingFactor) || toReturn[0].Count == 0) { // Grab the required amount, but only pop off the earliest var fulldata = data.PeekRange(0, SmoothingFactor); data.Pop(0); // Calculate the average var currentData = 0.0; for (var j = 0; j < fulldata.Count; j++) { currentData += fulldata[j]; } toReturn[0].Add(currentData / fulldata.Count); } // Push the data core.PassDataToNextConnectable(this, toReturn); }
/// <summary> /// Accepts incoming data from a previous connection. /// This is allowed to queue and store as needed. /// </summary> /// <param name="data">The data being pushed from the previous node</param> /// <param name="core">The Streamline program this is a part of</param> public override void AcceptIncomingData(StreamlineCore core, DataPacket data) { // Create the packet to return var toReturn = new DataPacket(); toReturn.AddChannel(); // Quantize all points in each channel // Loop through until no data is available while ((BatchMode && data[0].Count > 0) || toReturn[0].Count == 0) { var currentData = data.Pop(0); if (currentData < Minimum) { toReturn[0].Add(Minimum); } else if (currentData > Maximum) { toReturn[0].Add(Maximum); } else { toReturn[0].Add(Math.Floor((currentData - Minimum) / StepSize) * StepSize + Minimum); } } // Push to the next node, and clear the saved data core.PassDataToNextConnectable(this, toReturn); }
/// <summary> /// Decodes an input byte stream into seperate values. /// If input is not emptied or set to null, it will be appended with future data /// </summary> /// <param name="input">The input byte array to convert</param> /// <returns>A series of doubles representing the decoded data</returns> public override DataPacket DecodeData(ref byte[] input) { // Only decode when possible if (input.Length < DataSize) { return(null); } // Take out everything possible from the input var pieceCount = input.Length / DataSize; var toReturn = new DataPacket(); toReturn.AddChannel(); for (var k = 0; k < pieceCount; k++) { toReturn[0].Add(ConversionUtil.BytesToDouble(input, k * DataSize, DataSize, Signed, LittleEndianMode)); } // Set the input to the correct sub-buffer var fullSize = pieceCount * DataSize; if (fullSize == input.Length) { input = null; } else { var temp = new byte[input.Length - fullSize]; Buffer.BlockCopy(input, fullSize, temp, 0, temp.Length); } return(toReturn); }
/// <summary> /// Reads directly from the stream, ignoring the Converter, and providing /// </summary> /// <param name="count">The number of points to poll</param> /// <returns>The data packet with at most count data points added</returns> public override DataPacket ReadDirect(int count) { lock (_bufferLock) { if (BufferedPacketA.ChannelCount <= 0) { BufferedPacketA.AddChannel(); } if (BufferedPacketB.ChannelCount <= 0) { BufferedPacketB.AddChannel(); } // Swap buffers whenever a read is requested if (CurrentDataPacket == BufferedPacketA) { CurrentDataPacket = BufferedPacketB; return(BufferedPacketA); } else { CurrentDataPacket = BufferedPacketA; return(BufferedPacketB); } } }
/// <summary> /// Reads directly from the stream, ignoring the Converter, and providing /// </summary> /// <param name="count">The number of points to poll</param> /// <returns>The data packet with at most count data points added</returns> public override DataPacket ReadDirect(int count) { var toReturn = new DataPacket(); toReturn.AddChannel(); while (count-- > 0) { toReturn[0].Add((RNG.NextDouble() * _off) + Minimum); } return(toReturn); }
/// <summary> /// Reads directly from the stream, ignoring the Converter, and providing /// </summary> /// <param name="count">The number of points to poll</param> /// <returns>The data packet with at most count data points added</returns> public override DataPacket ReadDirect(int count) { var toReturn = new DataPacket(); toReturn.AddChannel(); while (count-- > 0) { toReturn[0].Add(_value); } return(toReturn); }
/// <summary> /// Accepts incoming data from a previous connection. /// This is allowed to queue and store as needed. /// </summary> /// <param name="data">The data being pushed from the previous node</param> /// <param name="core">The Streamline program this is a part of</param> public override void AcceptIncomingData(StreamlineCore core, DataPacket data) { var toReturn = new DataPacket(); toReturn.AddChannel(); while ((BatchMode && data[0].Count > Delay) || toReturn[0].Count == 0) { toReturn[0].Add(data.Pop(0)); } core.PassDataToNextConnectable(this, toReturn); }
/// <summary> /// Creates a new AudioFileStream. /// A file must be specified before it can be used /// </summary> public MicrophoneStream() { Reader = new WaveIn(); Reader.DataAvailable += DataAvailableEvent; Reader.WaveFormat = new WaveFormat(); BufferedPacketA = new DataPacket(); BufferedPacketA.AddChannel(); BufferedPacketB = new DataPacket(); BufferedPacketB.AddChannel(); CurrentDataPacket = BufferedPacketA; }
/// <summary> /// Accepts incoming data from a previous connection. /// This is allowed to queue and store as needed. /// </summary> /// <param name="data">The data being pushed from the previous node</param> /// <param name="core">The Streamline program this is a part of</param> public override void AcceptIncomingData(StreamlineCore core, DataPacket data) { // Push the multiplied value to the next node var toReturn = new DataPacket(); toReturn.AddChannel(); while ((BatchMode && data[0].Count > 0) || toReturn[0].Count == 0) { toReturn[0].Add(data.Pop(0) * Gain); } core.PassDataToNextConnectable(this, toReturn); }
/// <summary> /// Method triggered whenever data is available from the microphone /// </summary> private void DataAvailableEvent(object sender, WaveInEventArgs e) { lock (_bufferLock) { if (CurrentDataPacket.ChannelCount <= 0) { CurrentDataPacket.AddChannel(); } // Convert from 16-bit samples for (var k = 0; k < e.BytesRecorded; k += 2) { CurrentDataPacket[0].Add(BitConverter.ToInt16(e.Buffer, k) / ((double)ushort.MaxValue)); } } }
/// <summary> /// Reads directly from the stream, ignoring the Converter, and providing /// </summary> /// <param name="count">The number of points to poll</param> /// <returns>The data packet with at most count data points added</returns> public override DataPacket ReadDirect(int count) { var toReturn = new DataPacket(); if (Reader == null) { return(toReturn); } toReturn.AddChannel(); // Read the required number of points off of the stream var str = new StringBuilder(); double realVal; string realStr; while (!Reader.EndOfStream && count > 0) { var symbol = (char)Reader.Read(); if (symbol == ',') { realStr = str.ToString(); if (double.TryParse(realStr.Trim(), out realVal)) { toReturn[0].Add(realVal); count--; } str.Clear(); } else { str.Append(symbol); } } // Push the last little bit if ran out of room if (str.Length > 0) { realStr = str.ToString(); if (double.TryParse(realStr.Trim(), out realVal)) { toReturn[0].Add(realVal); count--; } } EndOfStream = Reader.EndOfStream; return(toReturn); }
/// <summary> /// Accepts incoming data from a previous connection. /// This is allowed to queue and store as needed. /// </summary> /// <param name="data">The data being pushed from the previous node</param> /// <param name="core">The Streamline program this is a part of</param> public override void AcceptIncomingData(StreamlineCore core, DataPacket data) { var toReturn = new DataPacket(); toReturn.AddChannel(); while ((BatchMode && data[0].Count > InputLength) || toReturn[0].Count == 0) { var nd = _b1 * data[0][1] + _b0 * data[0][0] + _a0 * _y0; _y0 = nd; // Remove the oldest data point data.Pop(0); toReturn[0].Add(nd); } // Push to the next node core.PassDataToNextConnectable(this, toReturn); }
/// <summary> /// Accepts incoming data from a previous connection. /// This is allowed to queue and store as needed. /// </summary> /// <param name="data">The data being pushed from the previous node</param> /// <param name="core">The Streamline program this is a part of</param> public override void AcceptIncomingData(StreamlineCore core, DataPacket data) { var toReturn = new DataPacket(); toReturn.AddChannel(); // Sum every available channel while ((BatchMode && data.EnsureMinCountOnAllChannels(1, 0)) || (toReturn[0].Count == 0 && data.EnsureMinCountOnAllChannels(1, 0))) { var val = 0.0; for (var k = 0; k < data.ChannelCount; k++) { val += data.Pop(k); } toReturn[0].Add(val); } // Push to the next node core.PassDataToNextConnectable(this, toReturn); }
/// <summary> /// Accepts incoming data from a previous connection. /// This is allowed to queue and store as needed. /// </summary> /// <param name="data">The data being pushed from the previous node</param> /// <param name="core">The Streamline program this is a part of</param> public override void AcceptIncomingData(StreamlineCore core, DataPacket data) { // Return a new packet with the sum var toReturn = new DataPacket(); toReturn.AddChannel(); while ((BatchMode && data[0].Count >= InputCount) || toReturn[0].Count == 0) { // Calculate the new point var nd = _samplingPeriod * data[0][1] - _samplingPeriod * data[0][0] - LastOutput; LastOutput = nd; toReturn[0].Add(nd); // Remove the oldest data point data.Pop(0); } // Push to the next node core.PassDataToNextConnectable(this, toReturn); }
/// <summary> /// Accepts incoming data from a previous connection. /// This is allowed to queue and store as needed. /// </summary> /// <param name="data">The data being pushed from the previous node</param> /// <param name="core">The Streamline program this is a part of</param> public override void AcceptIncomingData(StreamlineCore core, DataPacket data) { // Return a new packet with the sum var toReturn = new DataPacket(); toReturn.AddChannel(); while ((BatchMode && data[0].Count >= 3) || toReturn[0].Count == 0) { var nd = _b2 * data[0][2] + _b1 * data[0][1] + _b0 * data[0][0] + _a1 * _y1 + _a0 * _y2; _y2 = _y1; _y1 = nd; toReturn[0].Add(nd); // Remove the oldest data point data.Pop(0); } // Push to the next node core.PassDataToNextConnectable(this, toReturn); }