#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 list of signed PCM samples",sample_count;
OUTPUT "the number of wasted bits-per-sample as an unsigned integer";
VAR sample "sample";
VAR sample_count "sample count";
VAR wasted "wasted";
VAR wasted_BPS "wasted BPS";
wasted_BPS <- infinity /*maximum unsigned integer*/;
for i <- 0 to sample_count {
    wasted[i] <- wasted(sample[i]);
    if wasted[i] == 0 {
        return 0;
    } elif wasted[i] < wasted_BPS {
        wasted_BPS <- wasted[i];
    }
}
if wasted_BPS != infinity {
    return wasted_BPS;
} else /*all samples are 0*/ {
    return 0;
}
