[FFmpeg-devel] [GSoC] avcodec/als: Add ALS encoder

Michael Niedermayer michael at niedermayer.cc
Tue Oct 4 16:20:08 EEST 2016


On Tue, Oct 04, 2016 at 12:22:38AM +0530, Umair Khan wrote:
> Hi,
> 
> Patch attached.
> 
> It fixes the fate tests.
> However, there's a slight bug in the encoder in handling the last frame.
> I'll definitely fix it later.
> I hope the patch can be merged in this state.
[...]
> +/**
> + * Quantize and rescale a single PARCOR coefficient.
> + * @param ctx Encoder context
> + * @param parcor double-precision PARCOR coefficient
> + * @param index  coefficient index number
> + * @param[out] q_parcor 7-bit quantized coefficient
> + * @param[out] r_parcor 21-bit reconstructed coefficient
> + * @return the number of bits used to encode the coefficient
> + */
> +static int quantize_single_parcor_coeff(ALSEncContext *ctx, double parcor,
> +                                        int index, int32_t *q_parcor,
> +                                        int32_t *r_parcor)
> +{
> +    int rice_param, offset;
> +    int sign = !index - index;
> +
> +    // compand coefficient for index 0 or 1
> +    if (index < 2)
> +        parcor = sqrt(2.0 * (sign * parcor + 1.0)) - 1.0;
> +
> +    // quantize to signed 7-bit

> +    *q_parcor = av_clip((int32_t)floor(64.0 * parcor), -64, 63);

could use av_clip_intp2()


[...]
> +/**
> + * Determine the number of samples in each frame, which is constant for all
> + * frames in the stream except the very last one which may be smaller.
> + */
> +static void frame_partitioning(ALSEncContext *ctx)
> +{
> +    AVCodecContext *avctx    = ctx->avctx;
> +    ALSSpecificConfig *sconf = &ctx->sconf;
> +
> +    // choose default frame size if not specified by the user
> +    if (avctx->frame_size <= 0) {
> +        if (avctx->sample_rate <= 24000)
> +            avctx->frame_size = 1024;
> +        else if(avctx->sample_rate <= 48000)
> +            avctx->frame_size = 2048;
> +        else if(avctx->sample_rate <= 96000)
> +            avctx->frame_size = 4096;
> +        else
> +            avctx->frame_size = 8192;
> +
> +        // increase frame size if block switching is used
> +        if (sconf->block_switching)
> +            avctx->frame_size <<= sconf->block_switching >> 1;
> +    }
> +
> +    // ensure a certain boundary for the frame size
> +    // frame length - 1 in ALSSpecificConfig is 16-bit, so max value is 65536
> +    // frame size == 1 is not allowed because it is used in ffmpeg as a
> +    // special-case value to indicate PCM audio
> +    avctx->frame_size   = av_clip(avctx->frame_size, 2, 65536);
> +    sconf->frame_length = avctx->frame_size;
> +
> +    // determine distance between ra-frames. 0 = no ra, 1 = all ra
> +    // defaults to 10s intervals for random access
> +    sconf->ra_distance = avctx->gop_size;
> +    /* There is an API issue where the required output audio buffer size cannot
> +       be known to the user, and the default buffer size in ffmpeg.c is too
> +       small to consistently fit more than about 7 frames.  Once this issue
> +       is resolved, the maximum value can be changed from 7 to 255. */

> +    sconf->ra_distance = av_clip(sconf->ra_distance, 0, 7);

av_clip_uintp2()

[...]

-- 
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: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161004/cee55c3f/attachment.sig>


More information about the ffmpeg-devel mailing list