static void decode_gain_and_index(QCELPContext  *q,
                                  float *gain) {
    int   i, subframes_count, g1[16];
    float slope;
    if(q->bitrate >= RATE_QUARTER)
    {
        switch(q->bitrate)
        {
            case RATE_FULL: subframes_count = 16; break;
            case RATE_HALF: subframes_count = 4;  break;
            default:        subframes_count = 5;
        }
        for(i=0; i<subframes_count; i++)
        {
            g1[i] = 4 * q->frame.cbgain[i];
            if(q->bitrate == RATE_FULL && !((i+1) & 3))
            {
                g1[i] += av_clip((g1[i-1] + g1[i-2] + g1[i-3]) / 3 - 6, 0, 32);
            }
            gain[i] = qcelp_g12ga[g1[i]];
            if(q->frame.cbsign[i])
            {
                gain[i] = -gain[i];
                q->frame.cindex[i] = (q->frame.cindex[i]-89) & 127;
            }
        }
        q->prev_g1[0] = g1[i-2];
        q->prev_g1[1] = g1[i-1];
        q->last_codebook_gain = qcelp_g12ga[g1[i-1]];
        if(q->bitrate == RATE_QUARTER)
        {
            gain[7] =     gain[4];
            gain[6] = 0.4*gain[3] + 0.6*gain[4];
            gain[5] =     gain[3];
            gain[4] = 0.8*gain[2] + 0.2*gain[3];
            gain[3] = 0.2*gain[1] + 0.8*gain[2];
            gain[2] =     gain[1];
            gain[1] = 0.6*gain[0] + 0.4*gain[1];
        }
    }else
    {
        if(q->bitrate == RATE_OCTAVE)
        {
            g1[0] = 2 * q->frame.cbgain[0]
                  + av_clip((q->prev_g1[0] + q->prev_g1[1]) / 2 - 5, 0, 54);
            subframes_count = 8;
        }else
        {
            assert(q->bitrate == I_F_Q);
            g1[0] = q->prev_g1[1];
            switch(q->erasure_count)
            {
                case 1 : break;
                case 2 : g1[0] -= 1; break;
                case 3 : g1[0] -= 2; break;
                default: g1[0] -= 6;
            }
            if(g1[0] < 0)
                g1[0] = 0;
            subframes_count = 4;
        }
        slope = 0.5*(qcelp_g12ga[g1[0]] - q->last_codebook_gain) / subframes_count;
        for(i=1; i<=subframes_count; i++)
            gain[i-1] = q->last_codebook_gain + slope * i;
        q->last_codebook_gain = gain[i-2];
        q->prev_g1[0] = q->prev_g1[1];
        q->prev_g1[1] = g1[0];
    }
}
['static void decode_gain_and_index(QCELPContext  *q,\n                                  float *gain) {\n    int   i, subframes_count, g1[16];\n    float slope;\n    if(q->bitrate >= RATE_QUARTER)\n    {\n        switch(q->bitrate)\n        {\n            case RATE_FULL: subframes_count = 16; break;\n            case RATE_HALF: subframes_count = 4;  break;\n            default:        subframes_count = 5;\n        }\n        for(i=0; i<subframes_count; i++)\n        {\n            g1[i] = 4 * q->frame.cbgain[i];\n            if(q->bitrate == RATE_FULL && !((i+1) & 3))\n            {\n                g1[i] += av_clip((g1[i-1] + g1[i-2] + g1[i-3]) / 3 - 6, 0, 32);\n            }\n            gain[i] = qcelp_g12ga[g1[i]];\n            if(q->frame.cbsign[i])\n            {\n                gain[i] = -gain[i];\n                q->frame.cindex[i] = (q->frame.cindex[i]-89) & 127;\n            }\n        }\n        q->prev_g1[0] = g1[i-2];\n        q->prev_g1[1] = g1[i-1];\n        q->last_codebook_gain = qcelp_g12ga[g1[i-1]];\n        if(q->bitrate == RATE_QUARTER)\n        {\n            gain[7] =     gain[4];\n            gain[6] = 0.4*gain[3] + 0.6*gain[4];\n            gain[5] =     gain[3];\n            gain[4] = 0.8*gain[2] + 0.2*gain[3];\n            gain[3] = 0.2*gain[1] + 0.8*gain[2];\n            gain[2] =     gain[1];\n            gain[1] = 0.6*gain[0] + 0.4*gain[1];\n        }\n    }else\n    {\n        if(q->bitrate == RATE_OCTAVE)\n        {\n            g1[0] = 2 * q->frame.cbgain[0]\n                  + av_clip((q->prev_g1[0] + q->prev_g1[1]) / 2 - 5, 0, 54);\n            subframes_count = 8;\n        }else\n        {\n            assert(q->bitrate == I_F_Q);\n            g1[0] = q->prev_g1[1];\n            switch(q->erasure_count)\n            {\n                case 1 : break;\n                case 2 : g1[0] -= 1; break;\n                case 3 : g1[0] -= 2; break;\n                default: g1[0] -= 6;\n            }\n            if(g1[0] < 0)\n                g1[0] = 0;\n            subframes_count = 4;\n        }\n        slope = 0.5*(qcelp_g12ga[g1[0]] - q->last_codebook_gain) / subframes_count;\n        for(i=1; i<=subframes_count; i++)\n            gain[i-1] = q->last_codebook_gain + slope * i;\n        q->last_codebook_gain = gain[i-2];\n        q->prev_g1[0] = q->prev_g1[1];\n        q->prev_g1[1] = g1[0];\n    }\n}']