#This work is licensed under the
#Creative Commons Attribution-Share Alike 3.0 United States License.
#To view a copy of this license, visit
#http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
#Creative Commons,
#171 Second Street, Suite 300,
#San Francisco, California, 94105, USA.

INPUT "MLP substream data";
OUTPUT restart_header[s];
VAR header_sync "header sync";
VAR noise_type "noise type";
VAR output_timestamp "output timestamp";
VAR max_channel "max channel";
VAR min_channel "min channel";
VAR max_matrix_channel "max matrix channel";
VAR noise_shift "noise shift";
VAR noise_gen_seed "noise gen seed";
VAR check_data_present "check data present";
VAR lossless_check "lossless check";
VAR channel_assignment "channel assignment";
VAR restart_header "restart header";
header_sync <- read 13 unsigned;
noise_type <- read 1 unsigned;
output_timestamp <- read 16 unsigned;
min_channel <- read 4 unsigned;
max_channel <- read 4 unsigned;
max_matrix_channel <- read 4 unsigned;
noise_shift <- read 4 unsigned;
noise_gen_seed <- read 23 unsigned;
skip 19;
check_data_present <- read 1 unsigned;
lossless_check <- read 8 unsigned;
skip 16;
assert header_sync == 0x18f5;
assert noise_type == 0;
assert max_channel >= min_channel;
assert max_matrix_channel >= max_channel;
for c <- 0 to (max_matrix_channel + 1) {
    channel_assignment[c] <- read 6 unsigned;
    assert channel_assignment[c] <= max_matrix_channel;
}
restart_header[s] <- min_channel,max_channel,max_matrix_channel,noise_shift,
noise_gen_seed,channel_assignment;
return restart_header[s];
