static int scale_vector(int16_t *vector, int length)
{
    int bits, scale, max = 0;
    int i;

    const int16_t shift_table[16] = {
        0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
        0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x7fff
    };

    for (i = 0; i < length; i++)
        max = FFMAX(max, FFABS(vector[i]));

    bits  = normalize_bits(max, 0);
    scale = shift_table[bits];

    for (i = 0; i < length; i++)
        vector[i] = (int16_t)(av_clipl_int32(vector[i] * scale << 1) >> 4);

    return bits - 3;
}