예제 #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 ShortBuffer(ByteBuffer _bytebuffer)
 {
     bytebuffer = _bytebuffer;
 }
예제 #3
0
 public LongBuffer(ByteBuffer _bytebuffer)
 {
     bytebuffer = _bytebuffer;
 }
예제 #4
0
 public IntBuffer(ByteBuffer _bytebuffer)
 {
     bytebuffer = _bytebuffer;
 }
예제 #5
0
 public FloatBuffer(ByteBuffer _bytebuffer)
 {
     bytebuffer = _bytebuffer;
 }
예제 #6
0
 public DoubleBuffer(ByteBuffer _bytebuffer)
 {
     bytebuffer = _bytebuffer;
 }
예제 #7
0
 public ByteBuffer Slice()
 {
     ByteBuffer newBuffer = new ByteBuffer((int)(stream.Capacity - stream.Position), 0, this.stream);
     newBuffer.bitConverter = this.bitConverter;
     newBuffer.byteorder = this.byteorder;
     newBuffer.reader = this.reader;
     newBuffer.writer = this.writer;
     return newBuffer;
 }
예제 #8
0
 //other functions
 public static ByteBuffer Allocate(int capacity)
 {
     ByteBuffer newBuffer = new ByteBuffer(capacity);
     return newBuffer;
 }
예제 #9
0
 public void serialize(ByteBuffer buf)
 {
     buf.putInt(wType.type);
     buf.putInt(wType.numel);
     buf.putInt(wValue.type);
     buf.putInt(wValue.numel);
     buf.putInt(sample);
     buf.putInt(offset);
     buf.putInt(duration);
     buf.putInt(wType.size+wValue.size);
     wType.serialize(buf);
     wValue.serialize(buf);
 }
예제 #10
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;
        }
예제 #11
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);
            }
        }
예제 #12
0
파일: Header.cs 프로젝트: Wieke/buffer_bci
 public void serialize(ByteBuffer buf)
 {
     buf.putInt(nChans);
     buf.putInt(nSamples);
     buf.putInt(nEvents);
     buf.putFloat(fSample);
     buf.putInt(dataType);
     if (channelNameSize <= nChans) {
         // channel names are all empty or array length does not match
         buf.putInt(0);
     } else {
         buf.putInt(8 + channelNameSize);	// 8 bytes for chunk def
         buf.putInt(CHUNK_CHANNEL_NAMES);
         buf.putInt(channelNameSize);
         for (int i=0;i<nChans;i++) {
             if (labels[i] != null)
                 buf.putString( labels[i]);
             buf.putByte((byte) 0);
         }
     }
 }
예제 #13
0
 /// <summary>
 /// Serializes the Header to the specified buffer.
 /// </summary>
 /// <param name="buf">The buffer to write the serialized header to.</param>
 public void Serialize(ByteBuffer buf)
 {
     buf.PutInt(NumChans);
     buf.PutInt(NumSamples);
     buf.PutInt(NumEvents);
     buf.PutFloat(FSample);
     buf.PutInt(DataType);
     if (ChannelNameSize <= NumChans) {
         // channel names are all empty or array length does not match
         buf.PutInt(0);
     } else {
         buf.PutInt(8 + ChannelNameSize);	// 8 bytes for chunk def
         buf.PutInt(CHUNK_CHANNEL_NAMES);
         buf.PutInt(ChannelNameSize);
         for (int i = 0; i < NumChans; i++) {
             if (Labels[i] != null)
                 buf.PutString(Labels[i]);
             buf.PutByte((byte)0);
         }
     }
 }
예제 #14
0
 public void Serialize(ByteBuffer buf)
 {
     buf.PutInt(wType.Type);
     buf.PutInt(wType.Numel);
     buf.PutInt(wValue.Type);
     buf.PutInt(wValue.Numel);
     buf.PutInt(Sample);
     buf.PutInt(Offset);
     buf.PutInt(Duration);
     buf.PutInt(wType.Size + wValue.Size);
     wType.Serialize(buf);
     wValue.Serialize(buf);
 }
예제 #15
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;
        }
예제 #16
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;
            }
        }