#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 "1 or 2 channels of shifted PCM data",
zero_bits, one_bits, duplicate_bits,block_samples,channel_count;
OUTPUT "1 or 2 channels of un-shifted PCM data";
VAR block_samples "block samples";
VAR channel_count "channel count";
VAR channel "channel";
VAR unshifted "un-shifted channel";
VAR sent_bits "sent bits";
VAR zero_bits "zero bits";
VAR one_bits "one bits";
VAR duplicate_bits "duplicate bits";
for c <- 0 to channel_count {
    for i <- 0 to block_samples {
        if zero_bits > 0 {
            unshifted[c][i] <- channel[c][i] * 2 ^ zero_bits;
        } elif one_bits > 0 {
            unshifted[c][i] <- channel[c][i] * 2 ^ one_bits + (2 ^ one_bits - 1);
        } elif duplicate_bits > 0 {
            if (channel[c][i] % 2) == 0 {
                unshifted[c][i] <- channel[c][i] * 2 ^ duplicate_bits;
            } else {
                unshifted[c][i] <- channel[c][i] * 2 ^ duplicate_bits + (2 ^ duplicate_bits - 1);
            }
        } else {
            unshifted[c][i] <- channel[c][i];
        }
    }
}
return unshifted;
