#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 "two channels of signed PCM samples",block_samples;
OUTPUT "mid and side channels of signed PCM samples";
VAR channel "channel";
VAR block_samples "block samples";
VAR mid "mid";
VAR side "side";
for i <- 0 to block_samples {
    mid[i] <- channel[0][i] - channel[1][i];
    side[i] <- floor((channel[0][i] + channel[1][i]) / 2);
}
return mid,side;
