[Ffmpeg-devel] [PATCH] THP PCM decoder (GSoC Qualification)

Mike Melanson mike
Tue Apr 3 21:04:52 CEST 2007


Marco Gerards wrote:
> +    case CODEC_ID_ADPCM_THP:
> +      {
> +        GetBitContext gb;
> +        long table[16][2];
> +        int samplecnt;
> +        int prev1[2], prev2[2];
> +        int ch;
> +
> +        if (buf_size < 80) {
> +            av_log(avctx, AV_LOG_ERROR, "frame too small\n");
> +            return -1;
> +        }
> +
> +        init_get_bits(&gb, src, buf_size * 8);
> +        src += buf_size;
> +
> +                    get_bits(&gb, 32); /* Channel size */
> +        samplecnt = get_bits(&gb, 32);
> +
> +        for (ch = 0; ch < 2; ch++)
> +            for (i = 0; i < 16; i++)
> +                table[i][ch] = get_sbits(&gb, 16);

I think this should be table[ch][i].

> +        /* Initialize the previous sample.  */
> +        for (ch = 0; ch < 2; ch++) {
> +            prev1[ch] = get_sbits(&gb, 16);
> +            prev2[ch] = get_sbits(&gb, 16);
> +        }
> +
> +        if (samples + samplecnt >= samples_end) {
> +            av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
> +            return -1;
> +        }
> +
> +        for (ch = 0; ch <= st; ch++) {
> +            /* Read in every sample for this channel.  */
> +            for (i = 0; i < samplecnt / 14; i++) {
> +                uint8_t index = get_bits (&gb, 4) & 7;
> +                int exp = get_bits (&gb, 4);
> +                long factor1 = table[index * 2][ch];
> +                long factor2 = table[index * 2 + 1][ch];
> +
> +                /* Decode 14 samples.  */
> +                for (n = 0; n < 14; n++) {
> +                    int sampledat = get_sbits (&gb, 4);
> +                    *samples = ((prev1[ch]*factor1 
> +                                + prev2[ch]*factor2) >> 11) + (sampledat << exp);
> +                    prev2[ch] = prev1[ch];
> +                    prev1[ch] = *samples++;
> +                }
> +            }
> +        }

Indeed, the interleaving is not correct here.

-- 
	-Mike Melanson




More information about the ffmpeg-devel mailing list