#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 "stream's sample rate in Hz";
OUTPUT "encoded sample rate as 4 bit value";
VAR sample_rate "sample rate";
switch sample_rate {
case {8000} {return 4;}
case {16000} {return 5;}
case {22050} {return 6;}
case {24000} {return 7;}
case {32000} {return 8;}
case {44100} {return 9;}
case {48000} {return 10;}
case {88200} {return 1;}
case {96000} {return 11;}
case {176400} {return 2;}
case {192000} {return 3;}
default {
    if ((sample_rate % 1000) == 0) and (sample_rate <= 255000) {
        return 12;
    } elif ((sample_rate % 10) == 0) and (sample_rate <= 655350) {
        return 14;
    } elif (sample_rate <= 65535) {
        return 13;
    } else {
        return 0;
    }
}
}
