[FFmpeg-devel] [PATCH] EVRC decoder

Michael Niedermayer michaelni at gmx.at
Sat Jan 12 15:57:42 CET 2013


On Fri, Jan 11, 2013 at 04:37:11PM +0000, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
> TODO:
>     frame erasure
>     excitation for quant rate
>     postfilter
[...]

> +/*
> + * Convert the quantized, interpolated line spectral frequencies,
> + * to prediction coefficients.
> + *
> + * TIA/IS-127 5.2.3.2
> + */
> +static void decode_predictor_coeffs(const float *ilspf, float *ilpc)
> +{
> +    double lsp[FILTER_ORDER];
> +    float a[FILTER_ORDER / 2 + 1], b[FILTER_ORDER / 2 + 1];
> +    float a1[FILTER_ORDER / 2] = { 0 };
> +    float a2[FILTER_ORDER / 2] = { 0 };
> +    float b1[FILTER_ORDER / 2] = { 0 };
> +    float b2[FILTER_ORDER / 2] = { 0 };
> +    int i, k;
> +
> +    ff_acelp_lsf2lspd(lsp, ilspf, FILTER_ORDER);
> +
> +    for (k = 0; k <= FILTER_ORDER; k++) {
> +        a[0] = k < 2 ? 0.25 : 0;
> +        b[0] = k < 2 ? k < 1 ? 0.25 : -0.25 : 0;
> +
> +        for (i = 0; i < FILTER_ORDER / 2; i++) {
> +            a[i + 1] = a[i] - 2 * lsp[i * 2    ] * a1[i] + a2[i];
> +            b[i + 1] = b[i] - 2 * lsp[i * 2 + 1] * b1[i] + b2[i];
> +            a2[i] = a1[i];
> +            a1[i] = a[i];
> +            b2[i] = b1[i];
> +            b1[i] = b[i];
> +        }
> +
> +        if (k)
> +            ilpc[k - 1] = 2.0 * (a[FILTER_ORDER / 2] + b[FILTER_ORDER / 2]);
> +    }
> +}

some of the arrays feel avoidable but maybe theres no point in avoiding
them


> +
> +static void bl_intrp(EVRCContext *e, float *ex, float delay)
> +{
> +    float *f;
> +    int offset, i, coef_idx;
> +    int16_t t;
> +

> +    if (delay > 0)
> +        offset = delay + 0.5;
> +    else
> +        offset = -delay + 0.5;

looks like
offset = lrintf(fabs(delay))



> +
> +    t = (offset - delay + 0.5) * 8.0 + 0.5;
> +    if (t == 8) {
> +        t = 0;
> +        offset--;
> +    }
> +
> +    f = ex - offset - 8;
> +
> +    coef_idx = t * (2 * 8 + 1);
> +
> +    ex[0] = 0.0;
> +    for (i = 0; i < 2 * 8 + 1; i++)
> +        ex[0] += e->blintrp[coef_idx + i] * f[i];
> +}
> +
> +static void acb_excitation(EVRCContext *e, float *excitation, float gain,
> +                           const float delay[3], int length)
> +{
> +    float denom, locdelay, dpr, invl;
> +    int i;
> +
> +    invl = 1.0 / ((float) length);
> +    dpr = length;
> +
> +    /* first at-most extra samples */
> +    denom = (delay[1] - delay[0]) * invl;
> +    for (i = 0; i < dpr; i++) {
> +        locdelay = delay[0] + i * denom;
> +        bl_intrp(e, excitation + i, locdelay);
> +    }
> +
> +    denom = (delay[2] - delay[1]) * invl;
> +    /* interpolation */
> +    for (i = dpr; i < dpr + 10; i++) {
> +        locdelay = delay[1] + (i - dpr) * denom;
> +        bl_intrp(e, excitation + i, locdelay);
> +    }
> +
> +    for (i = 0; i < length; i++)
> +        excitation[i] *= gain;
> +}
> +

> +/*
> + * TIA/IS-127 5.2.3.7
> + */
> +static void decode_8_pulses_35bits(const uint16_t *fixed_index, float *cod)
> +{
> +    int i, k, pos1, pos2, offset;
> +    float sign;
> +
> +    for (i = 0; i < 55; i++)
> +        cod[i] = 0.0;
> +
> +    offset = (fixed_index[3] >> 9) & 3;
> +
> +    for (k = 0; k < 3; k++) {
> +        pos1 = ((fixed_index[k] & 127) / 11) * 5 + ((k + offset) % 5);
> +        pos2 = ((fixed_index[k] & 127) % 11) * 5 + ((k + offset) % 5);

% and / could be done by a LUT if speed matters
similarly teh %5 can be done my a 8 entry LUT

[...]
> +
> +    if (e->bitrate == RATE_FULL || e->bitrate == RATE_HALF) {
> +        /* Pitch delay parameter checking as per TIA/IS-127 5.1.5.1 */
> +        if (e->frame.pitch_delay > MAX_DELAY - MIN_DELAY) {
> +            e->error_flag = 1;
> +            return -1;
> +        }

error codes should be more specific than -1

[...}
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130112/235e09d8/attachment.asc>


More information about the ffmpeg-devel mailing list