Skip to content

Instantly share code, notes, and snippets.

@njvack
Last active April 21, 2017 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njvack/0f994cb1c670f42e7923005bf6da52fc to your computer and use it in GitHub Desktop.
Save njvack/0f994cb1c670f42e7923005bf6da52fc to your computer and use it in GitHub Desktop.
Three to four-byte conversion
def convert_three_byte(frame):
data_out = np.zeros(128, dtype=np.int32) # You're looking to make a 128-element array of int32.
data_out.dtype = np.byte
data_out = data_out.reshape(-1, 4) # Shape is now (128,4) and dtype is byte
# Now, copy the data from chans08to00 into data_out. We need to specify which bytes to put it in.
# Also, we need to reverse the data in frame.
# You'd change 0:3 to 1:4 if the stuff in frame is big-endian, I think? You'll need to experiment.
data_out[0:8, 0:3] = frame['chans08to00'][::-1]
# ... and so on with channels
data_out.dtype = np.int32
# The last thing that's a little messed up is that shape(data_out) is now (128,1) instead of (128,) --
# it's become a 2-d array with the second dimension's size as 1. flatten() will fix it
data_out = data_out.flatten
return data_out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment