Muse Data File creation with Protocol Buffers


#1

I’ve got the Muse_v2.proto from https://sites.google.com/a/interaxon.ca/muse-developer-site/data-files and got it in my android project ok with protobuf-java-2.5.0.jar
I think I understand how to use MuseDataSerializer to read data, but what I want to do is create my own recordings for playback in the Muse Player.

Is this possible and if so could we have a quick example of creating a couple of data points to file?


#2

This java code works to create a file… but playback crashes muse-player, so I’ve no idea what the minimum data set is.
Can someone shed a little light on this for me please?

EEG eegData = EEG.newBuilder()
        .addValues(channelData.get(TP9))
        .addValues(channelData.get(FP1))
        .addValues(channelData.get(FP2))
        .addValues(channelData.get(TP10))
        .build();

MuseData museData = MuseData.newBuilder()
        .setTimestamp(System.currentTimeMillis())
        .setDatatype(Datatype.EEG)
        .setExtension(EEG.museData, eegData)
        .build();

MuseDataCollection museDataCollection = MuseDataCollection.newBuilder()
        .addCollection(museData)
        .build();

museDataCollection.writeTo(dataFileOutputStream);  

Playing it back dies:

\Muse\muse-player.exe -f test.muse -D
Muse Player 1.8.4
Input:
  * Muse file(s): ['test.muse']

Output:
  * Screen output mode
Exception in thread Thread-1:
Traceback (most recent call last):
  File "D:\Jenkins\workspace\MusePlayer-Win32-1.8.x\build\muse-player\out00-PYZ.pyz	hreading", line 810, in __bootstrap_inner
  File "D:\Jenkins\workspace\MusePlayer-Win32-1.8.x\build\muse-player\out00-PYZ.pyz	hreading", line 763, in run
  File "D:\Jenkins\workspace\MusePlayer-Win32-1.8.x\build\muse-player\out00-PYZ.pyz\input_handler", line 120, in parse_files
  File "D:\Jenkins\workspace\MusePlayer-Win32-1.8.x\build\muse-player\out00-PYZ.pyz\input_handler", line 149, in __parse_head
IndexError: list index out of range

#3

HI Enigma,

What you’re trying to do should definitely work, however what you’re missing here is that you didn’t give a protocol buffer version to your file.

Muse player is crashing because it’s failing to find a protocol version. I will make sure that the next release gives a better error to indicate the cause.

Each DataCollection should contain the protocol version. The newest version is protocol version 2.

On a side note, each DataCollection may contain more than one sample before writing it. In your code above it appears that you’re writing each sample to the file one at a time which means a significant amount of overhead for each sample.

Hope that helps.


#4

Thanks Farough. I managed to figure it out while the forum was offline :wink: For others struggling they key is to make sure the datalength and version are little endian!

            byte[] dataLengthBytes = ByteBuffer
                    .allocate(4)
                    .order(ByteOrder.LITTLE_ENDIAN)
                    .putInt(museDataCollection.getSerializedSize())
                    .array();
            
            byte[] versionBytes = ByteBuffer
                    .allocate(2)
                    .order(ByteOrder.LITTLE_ENDIAN)
                    .putShort((short)2)
                    .array();
            
            dataFileOutputStream.write(dataLengthBytes);//Data Length
            dataFileOutputStream.write(versionBytes);//Version