[FFmpeg-devel] [PATCH] ALS decoder

Thilo Borgmann thilo.borgmann
Sat Aug 29 22:17:41 CEST 2009


Herv? W. schrieb:
> On 29/08/2009, Thilo Borgmann <thilo.borgmann at googlemail.com> wrote:
>> Michael Niedermayer schrieb:
>>> On Wed, Aug 26, 2009 at 08:28:43PM +0200, Thilo Borgmann wrote:
>>>> Revision 11 attached.
>>> [...]
>>>> +/** Reads the block data for a non-constant block
>>>> + */
>>>> +static int read_var_block(ALSDecContext *ctx, unsigned int ra_block,
>>>> +                          int32_t *raw_samples, unsigned int
>>>> block_length,
>>>> +                          unsigned int *js_blocks, int32_t *raw_other,
>>>> +                          unsigned int *shift_lsbs)
>>>> +{
>>>> ...
>>>> +        if (opt_order) {
>>>> +            if (sconf->coef_table == 3) {
>>>> +                // read coefficient 0
>>>> +                quant_cof[0] = parcor_scaled_values[get_bits(gb, 7)];
>>>> +
>>>> +                // read coefficient 1
>>>> +                quant_cof[1] = -parcor_scaled_values[get_bits(gb, 7)];
>>>> +
>>>> +                // read coefficients 2 to opt_order
>>>> +                for (k = 2; k < opt_order; k++)
>>>> +                    quant_cof[k] = (get_bits(gb, 7) << 14) - (0x7F <<
>>>> 13);
>>>> +            } else {
>>>> +                int offset, rice_param, k_max;
>>>> +                int64_t quant_index;
>>>> +
>>>> +
>>>> +                // read coefficient 0 to 19
>>>> +                k_max = FFMIN(20, opt_order);
>>>> +                for (k = 0; k < k_max; k++) {
>>>> +                    offset       =
>>>> parcor_rice_table[sconf->coef_table][k][0];
>>>> +                    rice_param   =
>>>> parcor_rice_table[sconf->coef_table][k][1];
>>>> +                    quant_cof[k] = decode_rice(gb, rice_param) + offset;
>>>> +                }
>>>> +
>>>> +                quant_cof[0] =  parcor_scaled_values[quant_cof[0] + 64];
>>>> +                quant_cof[1] = -parcor_scaled_values[quant_cof[1] + 64];
>>>> +
>>>> +                for (k = 2; k < k_max; k++)
>>>> +                    quant_cof[k] = (quant_cof[k] << 14) + (1 << 13);
>>>> +
>>>> +                // read coefficients 20 to 126
>>>> +                k_max = FFMIN(127, opt_order);
>>>> +                for (; k < k_max; k++) {
>>>> +                    offset       = k & 1;
>>>> +                    rice_param   = 2;
>>>> +                    quant_index  = decode_rice(gb, rice_param) + offset;
>>>> +                    quant_cof[k] = (quant_index << 14) + (1 << 13);
>>>> +                }
>>>> +
>>>> +                // read coefficients 127 to opt_order
>>>> +                for (; k < opt_order; k++) {
>>>> +                    offset       = 0;
>>>> +                    rice_param   = 1;
>>>> +                    quant_index  = decode_rice(gb, rice_param) + offset;
>>>> +                    quant_cof[k] = (quant_index << 14) + (1 << 13);
>>>> +                }
>>> // read coefficient 0 to 19
>>> k_max = FFMIN( 20, opt_order);
>>> for (k = 0; k < k_max; k++) {
>>>     int offset     = parcor_rice_table[sconf->coef_table][k][0];
>>>     int rice_param = parcor_rice_table[sconf->coef_table][k][1];
>>>     quant_cof[k] = decode_rice(gb, rice_param) + offset;
>>> }
>>>
>>> // read coefficients 20 to 126
>>> k_max = FFMIN(127, opt_order);
>>> for (; k < k_max; k++)
>>>     quant_cof[k] = decode_rice(gb, 2) + (k&1);
>>>
>>> // read coefficients 127 to opt_order
>>> for (; k < opt_order; k++)
>>>     quant_cof[k] = decode_rice(gb, 1);
>>>
>>> quant_cof[0] =  parcor_scaled_values[quant_cof[0] + 64];
>>> quant_cof[1] = -parcor_scaled_values[quant_cof[1] + 64];
>>>
>>> for (k = 2; k < opt_order; k++)
>>>     quant_cof[k] = (quant_cof[k] << 14) + (1 << 13);
> 
>> It has to be for(..; k < k_max; ...) with k_max = FFMIN(20, opt_order)...
> 
> because you already stored the result of a decode_rice(gb, rice_param)
> + offset for k=0 to FFMIN(20,opt_order)
> Michaels suggestion is doing the same for the other ranges, 20 to
> FFMIN(127,opt_order) and 127 to opt_order. In other words: store your
> quant_index's in quant_cof[] and then do _all_ the
> shift_by_14_and_add_2^13  in a single loop. From what I can tell
> (using pen and paper) Michaels suggestion results in the same values
> as yours.
> 
> 
>>> and this likely can be factored with the sconf->coef_table == 3 case
> 
>> ... thus it cannot be merged with sconf->... == 3 which uses the whole k
>> < opt_oder range.
> 
> Maybe you should reconsider this as well. I haven't figured out how to
> do that just yet, though
Oh, you're right!

Also, I could factor it out. Will be part of the next revision!

Thanks!


-Thilo



More information about the ffmpeg-devel mailing list