/// <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; } }