#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,is_signed,is_big_endian,channels,block_size;
OUTPUT "a written Shorten header";
VAR bits_per_sample "bits-per-sample";
VAR is_signed "is signed";
VAR is_big_endian "is big endian";
VAR channels "channels";
VAR block_size "block size";
VAR header "written Shorten header";
VAR format "format";
FUNC unsupported_bps "unsupported bits-per-sample";
FUNC write_long "write long" "shorten:write_long";

if (bits_per_sample == 8) and is_signed {
    format <- 1;
} elif (bits_per_sample == 8) and not is_signed {
    format <- 2;
} elif (bits_per_sample == 16) and is_signed and is_big_endian {
    format <- 3;
} elif (bits_per_sample == 16) and is_signed and not is_big_endian {
    format <- 5;
} elif (bits_per_sample == 16) and not is_signed and is_big_endian {
    format <- 4;
} elif (bits_per_sample == 16) and not is_signed and not is_big_endian {
    format <- 6;
} else {
    unsupported_bps();
}

bytes(97, 106, 107, 103) -> write 4 bytes /*magic number*/;
2 -> write 8 unsigned /*version*/;

write_long(format);
write_long(channels);
write_long(block_size);
write_long(0) /*maximum LPC*/;
write_long(0) /*mean count*/;
write_long(0) /*bytes to skip*/;
return header;
