#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 "a WavPack encoded file";
OUTPUT "signed PCM samples";
VAR channel_count "channel count";
VAR final_block "final block";
VAR block_index "block index";
VAR block_samples "block samples";
VAR total_samples "total samples";
VAR block_channel "block channel";
VAR output_channel "output channel";
FUNC decode_block "decode block" "wavpack:decode_block";
do {
   c <- 0;
   do {
       channel_count,
       final_block,
       block_index,
       block_samples,
       total_samples,
       block_channel <- decode_block();
       for i <- 0 to channel_count {
           output_channel[c + i] <- block_channel[i];
       }
       c <- c + channel_count;
   } while final_block == 0;
   return output_channel;
} while (block_index + block_samples) < total_samples;
