Пример #1
0
        /// <summary>
        /// Initializes a Header from the specified <see cref="FieldTrip.Buffer.ByteBuffer"/>.
        /// </summary>
        /// <param name="buf">The buffer to read the header from.</param>
        public Header(ByteBuffer buf)
        {
            NumChans = buf.GetInt();
            NumSamples = buf.GetInt();
            NumEvents = buf.GetInt();
            FSample = buf.GetFloat();
            DataType = buf.GetInt();
            int size = buf.GetInt();
            Labels = new string[NumChans];

            while (size > 0) {
                int chunkType = buf.GetInt();
                int chunkSize = buf.GetInt();
                byte[] bs = new byte[chunkSize];
                buf.Get(ref bs);

                if (chunkType == CHUNK_CHANNEL_NAMES) {
                    int n = 0, len = 0, index = 0;
                    for (int pos = 0; pos < chunkSize; pos++) {
                        if (bs[pos] == 0) {
                            if (len > 0) {
                                Labels[n] = Encoding.Default.GetString(bs, index, len);
                                index = pos + 1;
                            }
                            len = 0;
                            if (++n == NumChans)
                                break;
                        } else {
                            len++;
                        }
                    }
                } else {
                    // ignore all other chunks for now
                }
                size -= 8 + chunkSize;
            }
        }
Пример #2
0
        public static int Count(ByteBuffer buf)
        {
            int num = 0;
            long pos = buf.Position;

            while (buf.Remaining >= 32) {
                int typeType = buf.GetInt();
                int typeNumEl = buf.GetInt();
                int valueType = buf.GetInt();
                int valueNumEl = buf.GetInt();
                buf.GetInt(); // sample
                buf.GetInt(); // offset
                buf.GetInt(); // duration
                int size = buf.GetInt();
                int sizeType = typeNumEl * DataType.wordSize[typeType];
                int sizeValue = valueNumEl * DataType.wordSize[valueType];

                if (sizeType < 0 || sizeValue < 0 || sizeType + sizeValue > size) {
                    return -(1 + num);
                }

                buf.Position = buf.Position + size;
                num++;
            }
            buf.Position = pos;
            return num;
        }
Пример #3
0
        public BufferEvent(ByteBuffer buf)
        {
            wType = new WrappedObject();
            wValue = new WrappedObject();

            wType.Type = buf.GetInt();
            wType.Numel = buf.GetInt();
            wValue.Type = buf.GetInt();
            wValue.Numel = buf.GetInt();
            Sample = buf.GetInt();
            Offset = buf.GetInt();
            Duration = buf.GetInt();
            int size = buf.GetInt();

            wType.Array = DataType.GetObject(wType.Type, wType.Numel, buf);
            if (wType.Array != null) {
                wType.Size = wType.Numel * DataType.wordSize[wType.Type];
            }

            wValue.Array = DataType.GetObject(wValue.Type, wValue.Numel, buf);
            if (wValue.Array != null) {
                wValue.Size = wValue.Numel * DataType.wordSize[wValue.Type];
            }

            size -= wType.Size + wValue.Size;
            if (size != 0) {
                buf.Position = buf.Position + size;
            }
        }