def _normalize_framerate(rate, min_rate=16, max_rate=32):
    """Limits the frame rate between min_rate and max_rate by integer multiples.
    """
    if rate < min_rate:
        factor = min_rate // rate
        if min_rate % rate > 0:
            factor += 1
        return rate * factor
    if rate > max_rate:
        factor = rate // max_rate
        if rate % max_rate > 0:
            factor += 1
        return rate / factor
    return rate
