[FFmpeg-devel] [PATCH] ALS decoder
Michael Niedermayer
michaelni
Wed Sep 16 21:25:54 CEST 2009
On Mon, Sep 14, 2009 at 03:23:12PM +0200, Thilo Borgmann wrote:
> Revision 20 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)
> +{
> + ALSSpecificConfig *sconf = &ctx->sconf;
> + AVCodecContext *avctx = ctx->avctx;
> + GetBitContext *gb = &ctx->gb;
> + unsigned int k;
> + unsigned int s[8];
> + unsigned int sub_blocks, log2_sub_blocks, sb_length;
> + unsigned int opt_order = 1;
> + int32_t *quant_cof = ctx->quant_cof;
> + int32_t *lpc_cof = ctx->lpc_cof;
> + unsigned int start = 0;
> + int smp = 0;
> + int sb, store_prev_samples;
> + int64_t y;
> +
> + *js_blocks = get_bits1(gb);
> +
> + // determine the number of subblocks for entropy decoding
> + if (!sconf->bgmc && !sconf->sb_part)
> + log2_sub_blocks = 0;
> + else {
should use {}
[...]
> +/** Reads the frame data.
> + */
> +static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
> +{
> + ALSSpecificConfig *sconf = &ctx->sconf;
> + AVCodecContext *avctx = ctx->avctx;
> + GetBitContext *gb = &ctx->gb;
> + unsigned int div_blocks[32]; ///< block sizes.
> + unsigned int c, b;
> + int32_t *raw_samples_L;
> + unsigned int js_blocks[2];
> +
> + uint32_t bs_info = 0;
> + unsigned int *ptr_div_blocks;
> +
> + // skip the size of the ra unit if present in the frame
> + if (sconf->ra_flag == RA_FLAG_FRAMES && ra_frame)
> + skip_bits_long(gb, 32);
> +
> + if (sconf->mc_coding && sconf->joint_stereo) {
> + ctx->js_switch = get_bits1(gb);
> + align_get_bits(gb);
> + }
> +
> + if (!sconf->mc_coding || ctx->js_switch) {
> + int independent_bs = !sconf->joint_stereo;
> +
> + for (c = 0; c < avctx->channels; c++) {
> + js_blocks[0] = 0;
> + js_blocks[1] = 0;
> +
> + if (sconf->block_switching) {
> + unsigned int bs_info_len = 1 << (sconf->block_switching + 2);
> + bs_info = get_bits_long(gb, bs_info_len);
> + bs_info <<= (32 - bs_info_len);
> + }
> +
> + ctx->num_blocks = 0;
> + ptr_div_blocks = &div_blocks[0];
> + parse_bs_info(bs_info, 0, 0, &ptr_div_blocks, &ctx->num_blocks);
> + reconstruct_block_sizes(ctx, div_blocks);
> +
> + // if joint_stereo and block_switching is set, independent decoding
> + // is signaled via the first bit of bs_info
> + if (sconf->joint_stereo && sconf->block_switching)
> + if (bs_info >> 31)
> + independent_bs = 2;
> +
> + // if this is the last channel, it has to be decoded independently
> + if (c == avctx->channels - 1)
> + independent_bs = 1;
> +
> + if (independent_bs) {
> + if (decode_blocks_ind(ctx, ra_frame, c, div_blocks, js_blocks))
> + return -1;
> +
> + if (independent_bs)
> + independent_bs--;
> + } else {
> + if (decode_blocks(ctx, ra_frame, c, div_blocks, js_blocks))
> + return -1;
> +
> + c++;
> + }
> +
> + // store carryover raw samples
> + memmove(ctx->raw_samples[c] - sconf->max_order,
> + ctx->raw_samples[c] - sconf->max_order + sconf->frame_length,
> + sizeof(*ctx->raw_samples[c]) * sconf->max_order);
> + }
> + } else { // multi-channel coding
> + if (sconf->block_switching) {
> + unsigned int bs_info_len = 1 << (sconf->block_switching + 2);
> + bs_info = get_bits_long(gb, bs_info_len);
> + bs_info <<= (32 - bs_info_len);
> + }
> +
> + ctx->num_blocks = 0;
> + ptr_div_blocks = div_blocks;
> + parse_bs_info(bs_info, 0, 0, &ptr_div_blocks, &ctx->num_blocks);
> + reconstruct_block_sizes(ctx, div_blocks);
duplicate of the code in the above loop
> +
> + // TODO: multi channel coding might use a temporary buffer instead as
> + // the actual channel is not known when read_block-data is called
> + raw_samples_L = ctx->raw_samples[0];
> +
> + for (b = 0; b < ctx->num_blocks; b++) {
> + if (read_block_data(ctx, ra_frame, raw_samples_L,
> + div_blocks[b], &js_blocks[0], NULL)) {
> + // damaged block, write zero for the rest of the frame
> + zero_remaining(b, ctx->num_blocks, div_blocks, raw_samples_L);
> + return -1;
> + }
> + raw_samples_L += div_blocks[b];
> + ra_frame = 0;
> + // TODO: read_channel_data
> + }
duplicate of decode_blocks_ind()
[...]
> +/** Scaled PARCOR values used for the first two PARCOR coefficients.
> + * To be indexed by the Rice coded indices.
> + * Generated by: parcor_scaled_values[i] = 32 + ((i * (i+1)) << 7) - (1 << 20)
> + */
> +static const int32_t parcor_scaled_values[] = {
fits in int16_t when divided by 32
except these i think your patch should be ok
[..]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090916/097de2d7/attachment.pgp>
More information about the ffmpeg-devel
mailing list