def estimate_best_lpc_order(options, block_size, bits_per_sample, error):
    """returns an order integer of the best LPC order to use"""
    from math import log
    error_scale = log(2) ** 2
    best_order = 0
    best_subframe_bits = 1e+32
    for i in range(options.max_lpc_order):
        order = i + 1
        if error[i] > 0.0:
            header_bits = order * (bits_per_sample + options.qlp_precision)
            bits_per_residual = max(log(error[i] * error_scale) / (log(2) *
                2), 0.0)
            estimated_subframe_bits = header_bits + bits_per_residual * (
                block_size - order)
            if estimated_subframe_bits < best_subframe_bits:
                best_order = order
                best_subframe_bits = estimated_subframe_bits
        elif error[i] == 0.0:
            return order
    else:
        return best_order
