static unsigned int rms(const int *data, int f)
{
    const int *c;
    int x;
    unsigned int res;
    int b;

    c = data;
    b = 0;
    res = 0x10000;
    for (x=0; x<10; x++) {
        res = (((0x1000000 - (*c) * (*c)) >> 12) * res) >> 12;

        if (res == 0)
            return 0;

        if (res <= 0x3fff) {
            while (res <= 0x3fff) {
                b++;
                res <<= 2;
            }
        } else {
            if (res > 0x10000)
                return 0; /* We're screwed, might as well go out with a bang. :P */
        }
        c++;
    }

    if (res > 0)
        res = t_sqrt(res);

    res >>= (b + 10);
    res = (res * f) >> 10;
    return res;
}