#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 subframe[0], subframe[1], sample_count,
interlacing_shift, interlacing_leftweight;
OUTPUT "decorrelated left and right sample lists";
VAR subframe "subframe";
VAR sample_count "sample count";
VAR interlacing_shift "interlacing shift";
VAR interlacing_leftweight "interlacing leftweight";
VAR left "left";
VAR right "right";
for i <- 0 to sample_count {
    right[i] <- subframe[0][i] -
                floor(frac(subframe[1][i] * interlacing_leftweight,
                           2 ^ interlacing_shift));
    left[i] <- subframe[1][i] + right[i];
}
return left,right;
