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;
    unsigned int js_blocks[2];
    uint32_t bs_info = 0;
    int ret;
    // 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;
            get_block_sizes(ctx, div_blocks, &bs_info);
            // 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) {
                ret = decode_blocks_ind(ctx, ra_frame, c,
                                        div_blocks, js_blocks);
                if (ret < 0)
                    return ret;
                independent_bs--;
            } else {
                ret = decode_blocks(ctx, ra_frame, c, div_blocks, js_blocks);
                if (ret < 0)
                    return ret;
                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
        ALSBlockData   bd = { 0 };
        int            b, ret;
        int            *reverted_channels = ctx->reverted_channels;
        unsigned int   offset             = 0;
        for (c = 0; c < avctx->channels; c++)
            if (ctx->chan_data[c] < ctx->chan_data_buffer) {
                av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data.\n");
        memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels);
        bd.ra_block         = ra_frame;
        bd.prev_raw_samples = ctx->prev_raw_samples;
        get_block_sizes(ctx, div_blocks, &bs_info);
        for (b = 0; b < ctx->num_blocks; b++) {
            bd.block_length = div_blocks[b];
            if (bd.block_length <= 0) {
                av_log(ctx->avctx, AV_LOG_WARNING,
                       "Invalid block length %u in channel data!\n",
                       bd.block_length);
                continue;
            for (c = 0; c < avctx->channels; c++) {
                bd.const_block = ctx->const_block + c;
                bd.shift_lsbs  = ctx->shift_lsbs + c;
                bd.opt_order   = ctx->opt_order + c;
                bd.store_prev_samples = ctx->store_prev_samples + c;
                bd.use_ltp     = ctx->use_ltp + c;
                bd.ltp_lag     = ctx->ltp_lag + c;
                bd.ltp_gain    = ctx->ltp_gain[c];
                bd.lpc_cof     = ctx->lpc_cof[c];
                bd.quant_cof   = ctx->quant_cof[c];
                bd.raw_samples = ctx->raw_samples[c] + offset;
                bd.raw_other   = NULL;
                if ((ret = read_block(ctx, &bd)) < 0)
                    return ret;
                if ((ret = read_channel_data(ctx, ctx->chan_data[c], c)) < 0)
                    return ret;
            for (c = 0; c < avctx->channels; c++) {
                ret = revert_channel_correlation(ctx, &bd, ctx->chan_data,
                                                 reverted_channels, offset, c);
                if (ret < 0)
                    return ret;
            for (c = 0; c < avctx->channels; c++) {
                bd.const_block = ctx->const_block + c;
                bd.shift_lsbs  = ctx->shift_lsbs + c;
                bd.opt_order   = ctx->opt_order + c;
                bd.store_prev_samples = ctx->store_prev_samples + c;
                bd.use_ltp     = ctx->use_ltp + c;
                bd.ltp_lag     = ctx->ltp_lag + c;
                bd.ltp_gain    = ctx->ltp_gain[c];
                bd.lpc_cof     = ctx->lpc_cof[c];
                bd.quant_cof   = ctx->quant_cof[c];
                bd.raw_samples = ctx->raw_samples[c] + offset;
                if ((ret = decode_block(ctx, &bd)) < 0)
                    return ret;
            memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels));
            offset      += div_blocks[b];
            bd.ra_block  = 0;
        // store carryover raw samples
        for (c = 0; c < avctx->channels; c++)
            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);
    // TODO: read_diff_float_data
    return 0;
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];                
    unsigned int c;
    unsigned int js_blocks[2];
    uint32_t bs_info = 0;
    int ret;
    
    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;
            get_block_sizes(ctx, div_blocks, &bs_info);
            
            
            if (sconf->joint_stereo && sconf->block_switching)
                if (bs_info >> 31)
                    independent_bs = 2;
            
            if (c == avctx->channels - 1)
                independent_bs = 1;
            if (independent_bs) {
                ret = decode_blocks_ind(ctx, ra_frame, c,
                                        div_blocks, js_blocks);
                if (ret < 0)
                    return ret;
                independent_bs--;
            } else {
                ret = decode_blocks(ctx, ra_frame, c, div_blocks, js_blocks);
                if (ret < 0)
                    return ret;
                c++;
            
            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 { 
        ALSBlockData   bd = { 0 };
        int            b, ret;
        int            *reverted_channels = ctx->reverted_channels;
        unsigned int   offset             = 0;
        for (c = 0; c < avctx->channels; c++)
            if (ctx->chan_data[c] < ctx->chan_data_buffer) {
                av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data.\n");
        memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels);
        bd.ra_block         = ra_frame;
        bd.prev_raw_samples = ctx->prev_raw_samples;
        get_block_sizes(ctx, div_blocks, &bs_info);
        for (b = 0; b < ctx->num_blocks; b++) {
            bd.block_length = div_blocks[b];
            if (bd.block_length <= 0) {
                av_log(ctx->avctx, AV_LOG_WARNING,
                       "Invalid block length %u in channel data!\n",
                       bd.block_length);
                continue;
            for (c = 0; c < avctx->channels; c++) {
                bd.const_block = ctx->const_block + c;
                bd.shift_lsbs  = ctx->shift_lsbs + c;
                bd.opt_order   = ctx->opt_order + c;
                bd.store_prev_samples = ctx->store_prev_samples + c;
                bd.use_ltp     = ctx->use_ltp + c;
                bd.ltp_lag     = ctx->ltp_lag + c;
                bd.ltp_gain    = ctx->ltp_gain[c];
                bd.lpc_cof     = ctx->lpc_cof[c];
                bd.quant_cof   = ctx->quant_cof[c];
                bd.raw_samples = ctx->raw_samples[c] + offset;
                bd.raw_other   = NULL;
                if ((ret = read_block(ctx, &bd)) < 0)
                    return ret;
                if ((ret = read_channel_data(ctx, ctx->chan_data[c], c)) < 0)
                    return ret;
            for (c = 0; c < avctx->channels; c++) {
                ret = revert_channel_correlation(ctx, &bd, ctx->chan_data,
                                                 reverted_channels, offset, c);
                if (ret < 0)
                    return ret;
            for (c = 0; c < avctx->channels; c++) {
                bd.const_block = ctx->const_block + c;
                bd.shift_lsbs  = ctx->shift_lsbs + c;
                bd.opt_order   = ctx->opt_order + c;
                bd.store_prev_samples = ctx->store_prev_samples + c;
                bd.use_ltp     = ctx->use_ltp + c;
                bd.ltp_lag     = ctx->ltp_lag + c;
                bd.ltp_gain    = ctx->ltp_gain[c];
                bd.lpc_cof     = ctx->lpc_cof[c];
                bd.quant_cof   = ctx->quant_cof[c];
                bd.raw_samples = ctx->raw_samples[c] + offset;
                if ((ret = decode_block(ctx, &bd)) < 0)
                    return ret;
            memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels));
            offset      += div_blocks[b];
            bd.ra_block  = 0;
        
        for (c = 0; c < avctx->channels; c++)
            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);
    
    return 0;
static int FUNC_0(ALSDecContext *VAR_0, unsigned int VAR_1)
{
    ALSSpecificConfig *sconf = &VAR_0->sconf;
    AVCodecContext *avctx    = VAR_0->avctx;
    GetBitContext *gb = &VAR_0->gb;
    unsigned int VAR_2[32];                
    unsigned int VAR_3;
    unsigned int VAR_4[2];
    uint32_t bs_info = 0;
    int VAR_5;
    
    if (sconf->ra_flag == RA_FLAG_FRAMES && VAR_1)
        skip_bits_long(gb, 32);
    if (sconf->mc_coding && sconf->joint_stereo) {
        VAR_0->js_switch = get_bits1(gb);
        align_get_bits(gb);
    if (!sconf->mc_coding || VAR_0->js_switch) {
        int VAR_6 = !sconf->joint_stereo;
        for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++) {
            VAR_4[0] = 0;
            VAR_4[1] = 0;
            get_block_sizes(VAR_0, VAR_2, &bs_info);
            
            
            if (sconf->joint_stereo && sconf->block_switching)
                if (bs_info >> 31)
                    VAR_6 = 2;
            
            if (VAR_3 == avctx->channels - 1)
                VAR_6 = 1;
            if (VAR_6) {
                VAR_5 = decode_blocks_ind(VAR_0, VAR_1, VAR_3,
                                        VAR_2, VAR_4);
                if (VAR_5 < 0)
                    return VAR_5;
                VAR_6--;
            } else {
                VAR_5 = decode_blocks(VAR_0, VAR_1, VAR_3, VAR_2, VAR_4);
                if (VAR_5 < 0)
                    return VAR_5;
                VAR_3++;
            
            memmove(VAR_0->raw_samples[VAR_3] - sconf->max_order,
                    VAR_0->raw_samples[VAR_3] - sconf->max_order + sconf->frame_length,
                    sizeof(*VAR_0->raw_samples[VAR_3]) * sconf->max_order);
    } else { 
        ALSBlockData   bd = { 0 };
        int            b, VAR_5;
        int            *reverted_channels = VAR_0->reverted_channels;
        unsigned int   offset             = 0;
        for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++)
            if (VAR_0->chan_data[VAR_3] < VAR_0->chan_data_buffer) {
                av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid channel data.\n");
        memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels);
        bd.ra_block         = VAR_1;
        bd.prev_raw_samples = VAR_0->prev_raw_samples;
        get_block_sizes(VAR_0, VAR_2, &bs_info);
        for (b = 0; b < VAR_0->num_blocks; b++) {
            bd.block_length = VAR_2[b];
            if (bd.block_length <= 0) {
                av_log(VAR_0->avctx, AV_LOG_WARNING,
                       "Invalid block length %u in channel data!\n",
                       bd.block_length);
                continue;
            for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++) {
                bd.const_block = VAR_0->const_block + VAR_3;
                bd.shift_lsbs  = VAR_0->shift_lsbs + VAR_3;
                bd.opt_order   = VAR_0->opt_order + VAR_3;
                bd.store_prev_samples = VAR_0->store_prev_samples + VAR_3;
                bd.use_ltp     = VAR_0->use_ltp + VAR_3;
                bd.ltp_lag     = VAR_0->ltp_lag + VAR_3;
                bd.ltp_gain    = VAR_0->ltp_gain[VAR_3];
                bd.lpc_cof     = VAR_0->lpc_cof[VAR_3];
                bd.quant_cof   = VAR_0->quant_cof[VAR_3];
                bd.raw_samples = VAR_0->raw_samples[VAR_3] + offset;
                bd.raw_other   = NULL;
                if ((VAR_5 = read_block(VAR_0, &bd)) < 0)
                    return VAR_5;
                if ((VAR_5 = read_channel_data(VAR_0, VAR_0->chan_data[VAR_3], VAR_3)) < 0)
                    return VAR_5;
            for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++) {
                VAR_5 = revert_channel_correlation(VAR_0, &bd, VAR_0->chan_data,
                                                 reverted_channels, offset, VAR_3);
                if (VAR_5 < 0)
                    return VAR_5;
            for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++) {
                bd.const_block = VAR_0->const_block + VAR_3;
                bd.shift_lsbs  = VAR_0->shift_lsbs + VAR_3;
                bd.opt_order   = VAR_0->opt_order + VAR_3;
                bd.store_prev_samples = VAR_0->store_prev_samples + VAR_3;
                bd.use_ltp     = VAR_0->use_ltp + VAR_3;
                bd.ltp_lag     = VAR_0->ltp_lag + VAR_3;
                bd.ltp_gain    = VAR_0->ltp_gain[VAR_3];
                bd.lpc_cof     = VAR_0->lpc_cof[VAR_3];
                bd.quant_cof   = VAR_0->quant_cof[VAR_3];
                bd.raw_samples = VAR_0->raw_samples[VAR_3] + offset;
                if ((VAR_5 = decode_block(VAR_0, &bd)) < 0)
                    return VAR_5;
            memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels));
            offset      += VAR_2[b];
            bd.ra_block  = 0;
        
        for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++)
            memmove(VAR_0->raw_samples[VAR_3] - sconf->max_order,
                    VAR_0->raw_samples[VAR_3] - sconf->max_order + sconf->frame_length,
                    sizeof(*VAR_0->raw_samples[VAR_3]) * sconf->max_order);
    
    return 0;
static int FUNC_0(ALSDecContext *VAR_0, unsigned int VAR_1)
{ ALSSpecificConfig *sconf = &VAR_0->sconf; AVCodecContext *avctx    = VAR_0->avctx; GetBitContext *gb = &VAR_0->gb; unsigned int VAR_2[32]; unsigned int VAR_3; unsigned int VAR_4[2]; uint32_t bs_info = 0; int VAR_5; if (sconf->ra_flag == RA_FLAG_FRAMES && VAR_1)
skip_bits_long(gb, 32); if (sconf->mc_coding && sconf->joint_stereo) { VAR_0->js_switch = get_bits1(gb); align_get_bits(gb); if (!sconf->mc_coding || VAR_0->js_switch) { int VAR_6 = !sconf->joint_stereo; for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++) { VAR_4[0] = 0; VAR_4[1] = 0; get_block_sizes(VAR_0, VAR_2, &bs_info); if (sconf->joint_stereo && sconf->block_switching)
if (bs_info >> 31)
VAR_6 = 2; if (VAR_3 == avctx->channels - 1)
VAR_6 = 1; if (VAR_6) { VAR_5 = decode_blocks_ind(VAR_0, VAR_1, VAR_3,
VAR_2, VAR_4); if (VAR_5 < 0)
return VAR_5; VAR_6--; } else { VAR_5 = decode_blocks(VAR_0, VAR_1, VAR_3, VAR_2, VAR_4); if (VAR_5 < 0)
return VAR_5; VAR_3++; memmove(VAR_0->raw_samples[VAR_3] - sconf->max_order,
VAR_0->raw_samples[VAR_3] - sconf->max_order + sconf->frame_length,
sizeof(*VAR_0->raw_samples[VAR_3]) * sconf->max_order); } else { ALSBlockData   bd = { 0 }; int            b, VAR_5; int            *reverted_channels = VAR_0->reverted_channels; unsigned int   offset             = 0; for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++) if (VAR_0->chan_data[VAR_3] < VAR_0->chan_data_buffer) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid channel data.\n"); memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels); bd.ra_block         = VAR_1; bd.prev_raw_samples = VAR_0->prev_raw_samples; get_block_sizes(VAR_0, VAR_2, &bs_info); for (b = 0; b < VAR_0->num_blocks; b++) { bd.block_length = VAR_2[b]; if (bd.block_length <= 0) { av_log(VAR_0->avctx, AV_LOG_WARNING,
"Invalid block length %u in channel data!\n",
bd.block_length); continue; for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++) { bd.const_block = VAR_0->const_block + VAR_3; bd.shift_lsbs  = VAR_0->shift_lsbs + VAR_3; bd.opt_order   = VAR_0->opt_order + VAR_3; bd.store_prev_samples = VAR_0->store_prev_samples + VAR_3; bd.use_ltp     = VAR_0->use_ltp + VAR_3; bd.ltp_lag     = VAR_0->ltp_lag + VAR_3; bd.ltp_gain    = VAR_0->ltp_gain[VAR_3]; bd.lpc_cof     = VAR_0->lpc_cof[VAR_3]; bd.quant_cof   = VAR_0->quant_cof[VAR_3]; bd.raw_samples = VAR_0->raw_samples[VAR_3] + offset; bd.raw_other   = NULL; if ((VAR_5 = read_block(VAR_0, &bd)) < 0)
return VAR_5; if ((VAR_5 = read_channel_data(VAR_0, VAR_0->chan_data[VAR_3], VAR_3)) < 0)
return VAR_5; for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++) { VAR_5 = revert_channel_correlation(VAR_0, &bd, VAR_0->chan_data,
reverted_channels, offset, VAR_3); if (VAR_5 < 0)
return VAR_5; for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++) { bd.const_block = VAR_0->const_block + VAR_3; bd.shift_lsbs  = VAR_0->shift_lsbs + VAR_3; bd.opt_order   = VAR_0->opt_order + VAR_3; bd.store_prev_samples = VAR_0->store_prev_samples + VAR_3; bd.use_ltp     = VAR_0->use_ltp + VAR_3; bd.ltp_lag     = VAR_0->ltp_lag + VAR_3; bd.ltp_gain    = VAR_0->ltp_gain[VAR_3]; bd.lpc_cof     = VAR_0->lpc_cof[VAR_3]; bd.quant_cof   = VAR_0->quant_cof[VAR_3]; bd.raw_samples = VAR_0->raw_samples[VAR_3] + offset; if ((VAR_5 = decode_block(VAR_0, &bd)) < 0)
return VAR_5; memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels)); offset      += VAR_2[b]; bd.ra_block  = 0; for (VAR_3 = 0; VAR_3 < avctx->channels; VAR_3++) memmove(VAR_0->raw_samples[VAR_3] - sconf->max_order,
VAR_0->raw_samples[VAR_3] - sconf->max_order + sconf->frame_length,
sizeof(*VAR_0->raw_samples[VAR_3]) * sconf->max_order); return 0;