#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 "the FLAC file stream",max_block_size,
streaminfo_sample_rate,
streaminfo_bps;
OUTPUT "stream information and subframe decoding parameters";
VAR max_block_size "maximum block size";
VAR streaminfo_sample_rate "STREAMINFO sample rate";
VAR streaminfo_bps "STREAMINFO bits-per-sample";
VAR sync_code "sync code";
VAR blocking_strategy "blocking strategy";
VAR encoded_block_size "encoded block size";
VAR encoded_sample_rate "encoded sample rate";
VAR encoded_channels "encoded channels";
VAR encoded_bps "encoded bits-per-sample";
VAR frame_number "frame number";
VAR block_size "block size";
VAR sample_rate "sample rate";
VAR bps "bits-per-sample";
VAR channel_count "channel count";
VAR channel_assignment "channel assignment";
VAR crc "CRC8";
FUNC read_utf8 "read frame number as UTF-8 value" "flac:read_utf8";
FUNC decode_block_size "decode block size" "flac:decode_block_size";
FUNC decode_sample_rate "decode sample rate" "flac:decode_sample_rate";
FUNC decode_bps "decode bits-per-sample" "flac:decode_bps";
FUNC decode_channels "decode channels" "flac:decode_channels";
FUNC verify_crc "verify header checksum";
sync_code <- read 14 unsigned;
assert sync_code == 16382;
skip 1;
blocking_strategy <- read 1 unsigned;
encoded_block_size <- read 4 unsigned;
encoded_sample_rate <- read 4 unsigned;
encoded_channels <- read 4 unsigned;
encoded_bps <- read 3 unsigned;
skip 1;
frame_number <- read_utf8();
block_size <- decode_block_size(encoded_block_size,
                                max_block_size);
sample_rate <- decode_sample_rate(encoded_sample_rate,
                                  streaminfo_sample_rate);
bps <- decode_bps(encoded_bps,
                  streaminfo_bps);
channel_count,channel_assignment <- decode_channels(encoded_channels);
crc <- read 8 unsigned;
verify_crc(crc);
;
return block_size,sample_rate,bps,channel_count,channel_assignment;
