#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",max_matrix_channel[s];
OUTPUT matrix_params[s][m];
VAR max_matrix_channel "max matrix channel";
VAR out_channel "out channel";
VAR fractional_bits "fractional bits";
VAR lsb_bypass "LSB bypass";
VAR matrix_coeff "matrix coefficient";
VAR matrix_params "matrix parameters";
out_channel[s][m] <- read 4 unsigned;
fractional_bits <- read 4 unsigned;
lsb_bypass[s][m] <- read 1 unsigned;
assert out_channel[s][m] <= max_matrix_channel[s];
assert fractional_bits <= 14;
for c <- 0 to (max_matrix_channel[s] + 3) {
    if (read 1 unsigned) == 1 {
       matrix_coeff[s][m][c] <-
           (read (fractional_bits + 2) signed) * 2 ^ {14 - fractional_bits};
    } else {
        matrix_coeff[s][m][c] <- 0;
    }
}
matrix_params[s][m] <- out_channel[s][m],lsb_bypass[s][m],matrix_coeff[s][m];
return matrix_params[s][m];
