// Only double[] and float[] chunks can support appending secondary timestamp. public void PushChunkLSL(float[,] data, double[] timestamps, double[] timestamps2 = null) { LatestTimestamp = timestamps[timestamps.Length - 1]; if (timestamps2 != null) // Append timestamp data to final column. { float[,] dataRevised = new float[data.GetLength(0), data.GetLength(1) + 2]; // Add extra 2 columns for timestamp. int lastColIndex = data.GetLength(1) + 1; for (int rowIndex = 0; rowIndex < data.GetLength(0); rowIndex++) { for (int colIndex = 0; colIndex < data.GetLength(1); colIndex++) { dataRevised[rowIndex, colIndex] = data[rowIndex, colIndex]; } float timestampBase = (float)timestamps2[rowIndex]; float remainder = (float)(timestamps2[rowIndex] - timestampBase); dataRevised[rowIndex, lastColIndex - 1] = timestampBase; dataRevised[rowIndex, lastColIndex] = remainder; } lslStream.push_chunk(dataRevised, timestamps); } else { lslStream.push_chunk(data, timestamps); } }
static void Main(string[] args) { Random rnd = new Random(); // create stream info and outlet liblsl.StreamInfo info = new liblsl.StreamInfo("BioSemi", "EEG", 8, 100, liblsl.channel_format_t.cf_float32, "sddsfsdf"); liblsl.StreamOutlet outlet = new liblsl.StreamOutlet(info); // send data in chunks of 10 samples and 8 channels float[,] data = new float[10, 8]; while (true) { for (int s = 0; s < 10; s++) { for (int c = 0; c < 8; c++) { data[s, c] = rnd.Next(-100, 100); } } outlet.push_chunk(data); System.Threading.Thread.Sleep(100); } }
private void StreamData(Bitalino dev, liblsl.StreamOutlet lslout, bool ecg, bool eda, bool resp, bool emg, bool egg) { // Simpler this way. By Default lets just open all channels we assume will be open. dev.start(sampling_rate, new int[] { 0, 1, 2, 3, 4 }); // Data Structure used for Streaming Data short[,] sample = new short[100, lslChannelCount]; // Initialize Sample to the number of available Channels and chunked samples we want to send. Bitalino.Frame[] frames = new Bitalino.Frame[100]; for (int i = 0; i < frames.Length; i++) { frames[i] = new Bitalino.Frame(); // must initialize all elements in the array } while (MainWindow.IS_STREAMING) { double start_clock = liblsl.local_clock(); // Record local clock before chunk processing dev.read(frames); string s = ""; for (int i = 0; i < frames.Length; i++) { int auxSampleIndexer = 0; // This variable helps manage the sample array for the various channels that are currently being used. // Manage the ECG Values if (ecg) { //s += frames[i].analog[0]; //s += " "; sample[i, auxSampleIndexer] = frames[i].analog[0]; auxSampleIndexer += 1; } // Manage the EDA Values if (eda) { //s += frames[i].analog[1]; //s += " "; sample[i, auxSampleIndexer] = frames[i].analog[1]; auxSampleIndexer += 1; } // Manage the Respiration Values if (resp) { //s += frames[i].analog[2]; //s += " "; sample[i, auxSampleIndexer] = frames[i].analog[2]; auxSampleIndexer += 1; } if (emg) { sample[i, auxSampleIndexer] = frames[i].analog[3]; auxSampleIndexer += 1; } if (egg) { sample[i, auxSampleIndexer] = frames[i].analog[4]; auxSampleIndexer += 1; } } s += " LENGTH = " + frames.Length; // Delegate the Output Values to the Streaming Text Box streamingOutputBox.Dispatcher.Invoke( new UpdateStreamBoxCallback(this.AppendStreamTextBox), new object[] { "Receiving Data: " + s }); double end_clock = liblsl.local_clock(); // Record local clock after chunk processing lslout.push_chunk(sample, (end_clock + start_clock) / 2.0); // Push the chunk through LabStream Layer using the average time between start and end } dev.stop(); streamingOutputBox.Dispatcher.Invoke( new UpdateStreamBoxCallback(this.AppendStreamTextBox), new object[] { "Thread Successfully Closed" }); }
void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { var reference = e.FrameReference.AcquireFrame(); // Body using (var frame = reference.BodyFrameReference.AcquireFrame()) { if (frame != null) { _bodies = new Body[frame.BodyFrameSource.BodyCount]; frame.GetAndRefreshBodyData(_bodies); foreach (var body in _bodies) { if (body != null) { if (body.IsTracked) { Joint spineBase = body.Joints[JointType.SpineBase]; Joint spineMid = body.Joints[JointType.SpineMid]; Joint spineShoulder = body.Joints[JointType.SpineShoulder]; Joint shoulderLeft = body.Joints[JointType.ShoulderLeft]; Joint elbowLeft = body.Joints[JointType.ElbowLeft]; Joint wristLeft = body.Joints[JointType.WristLeft]; Joint handLeft = body.Joints[JointType.HandLeft]; Joint thumbLeft = body.Joints[JointType.ThumbLeft]; Joint shoulderRight = body.Joints[JointType.ShoulderRight]; Joint elbowRight = body.Joints[JointType.ElbowRight]; Joint wristRight = body.Joints[JointType.WristRight]; Joint handRight = body.Joints[JointType.HandRight]; Joint thumbRight = body.Joints[JointType.ThumbRight]; float[,] KINECTdata; switch (kinectLimb) { case "trunkLeft": KINECTdata = new float[1, 21] { { spineBase.Position.X, spineBase.Position.Y, spineBase.Position.Z, spineMid.Position.X, spineMid.Position.Y, spineMid.Position.Z, spineShoulder.Position.X, spineShoulder.Position.Y, spineShoulder.Position.Z, shoulderLeft.Position.X, shoulderLeft.Position.Y, shoulderLeft.Position.Z, elbowLeft.Position.X, elbowLeft.Position.Y, elbowLeft.Position.Z, wristLeft.Position.X, wristLeft.Position.Y, wristLeft.Position.Z, handLeft.Position.X, handLeft.Position.Y, handLeft.Position.Z } }; KINECToutlet.push_chunk(KINECTdata); break; case "trunkRight": KINECTdata = new float[1, 21] { { spineBase.Position.X, spineBase.Position.Y, spineBase.Position.Z, spineMid.Position.X, spineMid.Position.Y, spineMid.Position.Z, spineShoulder.Position.X, spineShoulder.Position.Y, spineShoulder.Position.Z, shoulderRight.Position.X, shoulderRight.Position.Y, shoulderRight.Position.Z, elbowRight.Position.X, elbowRight.Position.Y, elbowRight.Position.Z, wristRight.Position.X, wristRight.Position.Y, wristRight.Position.Z, handRight.Position.X, handRight.Position.Y, handRight.Position.Z } }; KINECToutlet.push_chunk(KINECTdata); break; case "armLeft": KINECTdata = new float[1, 18] { { spineShoulder.Position.X, spineShoulder.Position.Y, spineShoulder.Position.Z, shoulderLeft.Position.X, shoulderLeft.Position.Y, shoulderLeft.Position.Z, elbowLeft.Position.X, elbowLeft.Position.Y, elbowLeft.Position.Z, wristLeft.Position.X, wristLeft.Position.Y, wristLeft.Position.Z, handLeft.Position.X, handLeft.Position.Y, handLeft.Position.Z, thumbLeft.Position.X, thumbLeft.Position.Y, thumbLeft.Position.Z } }; KINECToutlet.push_chunk(KINECTdata); break; case "armRight": KINECTdata = new float[1, 18] { { spineShoulder.Position.X, spineShoulder.Position.Y, spineShoulder.Position.Z, shoulderRight.Position.X, shoulderRight.Position.Y, shoulderRight.Position.Z, elbowRight.Position.X, elbowRight.Position.Y, elbowRight.Position.Z, wristRight.Position.X, wristRight.Position.Y, wristRight.Position.Z, handRight.Position.X, handRight.Position.Y, handRight.Position.Z, thumbRight.Position.X, thumbRight.Position.Y, thumbRight.Position.Z } }; KINECToutlet.push_chunk(KINECTdata); break; case "spine": KINECTdata = new float[1, 9] { { spineBase.Position.X, spineBase.Position.Y, spineBase.Position.Z, spineMid.Position.X, spineMid.Position.Y, spineMid.Position.Z, spineShoulder.Position.X, spineShoulder.Position.Y, spineShoulder.Position.Z } }; //Debug.WriteLine("SpineShoulderX: " + KINECTdata[0,6] + "; SpineShoulderY: " + KINECTdata[0, 7] + "; SpineShoulderZ: " + KINECTdata[0, 8]); KINECToutlet.push_chunk(KINECTdata); break; default: KINECTdata = new float[1, 39] { { spineBase.Position.X, spineBase.Position.Y, spineBase.Position.Z, spineMid.Position.X, spineMid.Position.Y, spineMid.Position.Z, spineShoulder.Position.X, spineShoulder.Position.Y, spineShoulder.Position.Z, shoulderLeft.Position.X, shoulderLeft.Position.Y, shoulderLeft.Position.Z, elbowLeft.Position.X, elbowLeft.Position.Y, elbowLeft.Position.Z, wristLeft.Position.X, wristLeft.Position.Y, wristLeft.Position.Z, handLeft.Position.X, handLeft.Position.Y, handLeft.Position.Z, thumbLeft.Position.X, thumbLeft.Position.Y, thumbLeft.Position.Z, shoulderRight.Position.X, shoulderRight.Position.Y, shoulderRight.Position.Z, elbowRight.Position.X, elbowRight.Position.Y, elbowRight.Position.Z, wristRight.Position.X, wristRight.Position.Y, wristRight.Position.Z, handRight.Position.X, handRight.Position.Y, handRight.Position.Z, thumbRight.Position.X, thumbRight.Position.Y, thumbRight.Position.Z } }; KINECToutlet.push_chunk(KINECTdata); break; } } } } } } }