#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 block_channel_count,decorrelation_term_count,decorrelation_weights;
OUTPUT decorrelation_weights;

VAR block_channel_count "block channel count";
VAR decorrelation_term_count "term count";
VAR decorrelation_weights "weights";

for p <- 0 to decorrelation_term_count {
    for c <- 0 to block_channel_count {
        /*store weight as 8 bit value*/;
        if decorrelation_weights[p][c] > 0 {
            w[p][c] <- floor((decorrelation_weights[p][c] -
                             floor((decorrelation_weights[p][c] + 2 ^ 6) /
                                   2 ^ 7) + 4) / 2 ^ 3);
        } elif decorrelation_weights[p][c] == 0 {
            w[p][c] <- 0;
        } else {
            w[p][c] <- floor((decorrelation_weights[p][c] + 4) / 2 ^ 3);
        }
        ;
        /*restore weight to 16 bit value*/;
        if w[p][c] > 0 {
            decorrelation_weights[p][c] <-
                ((w[p][c] * 2 ^ 3) + floor((w[p][c] * 2 ^ 3 + 2 ^ 6) / 2 ^ 7));
        } elif w[p][c] == 0 {
            decorrelation_weights[p][c] <- 0;
        } else {
            decorrelation_weights[p][c] <- w[p][c] * 2 ^ 3;
        }
    }
}
return decorrelation_weights;
