Esempio n. 1
0
        private async Task LSLOpenStream()
        {
            bool sendSecondaryTimestamp = TimestampFormat2.GetType() != typeof(DummyTimestampFormat);

            var channelsInfo = new List <LSLBridgeChannelInfo>();

            foreach (var c in channelLabels)
            {
                channelsInfo.Add(new LSLBridgeChannelInfo {
                    Label = c, Type = Constants.EEG_STREAM_TYPE, Unit = Constants.EEG_UNITS
                });
            }

            streamInfo = new LSLBridgeStreamInfo()
            {
                BufferLength           = Constants.MUSE_LSL_BUFFER_LENGTH,
                Channels               = channelsInfo,
                ChannelCount           = channelCount,
                ChannelDataType        = ChannelDataType.DataType,
                ChunkSize              = Constants.MUSE_SAMPLE_COUNT,
                DeviceManufacturer     = deviceInfoManufacturer,
                DeviceName             = deviceInfoName,
                NominalSRate           = Constants.MUSE_SAMPLE_RATE,
                StreamType             = Constants.EEG_STREAM_TYPE,
                SendSecondaryTimestamp = sendSecondaryTimestamp,
                StreamName             = EEGStreamName
            };

            ValueSet message = new ValueSet
            {
                { LSLBridge.Constants.LSL_MESSAGE_STREAM_INFO, JsonConvert.SerializeObject(streamInfo) }
            };
            await AppServiceManager.SendMessageAsync(LSLBridge.Constants.LSL_MESSAGE_TYPE_OPEN_STREAM, message);
        }
Esempio n. 2
0
        // Get timestamps for a chunk using LSL local_clock.
        public static double[] GenerateLSLNativeTimestamps(LSLBridgeStreamInfo streamInfo)
        {
            int    chunkSize         = streamInfo.ChunkSize;
            double sampleTimeSeconds = 1.0d / streamInfo.NominalSRate;

            double[] timestamps  = new double[chunkSize];
            double   baseSeconds = liblsl.local_clock(); // local_clock in seconds.

            for (int i = 0; i < streamInfo.ChunkSize; i++)
            {
                timestamps[i] = baseSeconds - ((chunkSize - i) * sampleTimeSeconds); // Offset times based on sample rate.
                timestamps[i] = timestamps[i];                                       // Convert to seconds, as this is a more standard timestamp format.
            }

            return(timestamps);
        }