[FFmpeg-devel] [PATCH] Add 32 bit-per-sample capability to FLAC encoder

Michael Niedermayer michael at niedermayer.cc
Fri Dec 17 13:43:30 EET 2021


On Thu, Dec 16, 2021 at 08:43:21PM +0100, Martijn van Beurden wrote:

[...]

> @@ -972,7 +1007,25 @@ static int encode_residual_ch(FlacEncodeContext *s, int ch)
>      for (i = 0; i < sub->order; i++)
>          sub->coefs[i] = coefs[sub->order-1][i];
>  
> -    if (s->bps_code * 4 + s->options.lpc_coeff_precision + av_log2(opt_order) <= 32) {
> +    if (s->avctx->bits_per_raw_sample > 24) {
> +        if (!ff_flacdsp_lpc_encode_c_32_overflow_detect(res, smp, n, sub->order,
> +                                                       sub->coefs, sub->shift)) {
> +            /* The found LPC coefficients produce predictions that overflow
> +             * 32-bit signed integer or produce residuals that do not fall
> +             * between -2^30 and 2^30. First try again with slightly smaller
> +             * coefficients so that the prediction undershoots, if that
> +             * doesn't help return a verbatim subframe instead */
> +            for (i = 0; i < sub->order; i++) {
> +                sub->coefs[i] = sub->coefs[i]*0.98;
                                                 ^^^^
This is ugly, the amount of actual overflow should be known at this point
so no arbitrary downscale should be needed here
                                                 
                                                 

> +                if (!ff_flacdsp_lpc_encode_c_32_overflow_detect(res, smp, n, sub->order,
> +                                                                sub->coefs, sub->shift)) {
> +                    sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM;
> +                    memcpy(res, smp, n * sizeof(int32_t));
> +                    return subframe_count_exact(s, sub, 0);

How often does this occur ?

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20211217/eb4249db/attachment.sig>


More information about the ffmpeg-devel mailing list