#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 bits_per_sample, block_size, filtered;
OUTPUT "a channel's predicted samples";
VAR bits_per_sample "bits-per-sample";
VAR block_size "block size";
VAR filtered "filtered";
VAR predicted "predicted";
VAR shift "shift";
switch bits_per_sample {
    case 8 {
        shift <- 4;
    }
    case 16 {
        shift <- 5;
    }
    case 24 {
        shift <- 5;
    }
}
predicted[0] <- filtered[0];
for i <- 1 to block_size {
    predicted[i] <- filtered[i] +
                    floor(frac((predicted[i - 1] * 2 ^ shift) -
                               predicted[i - 1], 2 ^ shift));
}
return predicted;
