/* * shine_iteration_loop: * ------------------ */ void shine_iteration_loop(shine_global_config *config) { shine_psy_xmin_t l3_xmin; gr_info *cod_info; int max_bits; int ch, gr, i; int *ix; for(ch=config->wave.channels; ch--; ) { for(gr=0; gr<config->mpeg.granules_per_frame; gr++) { /* setup pointers */ ix = config->l3_enc[ch][gr]; config->l3loop.xr = config->mdct_freq[ch][gr]; /* Precalculate the square, abs, and maximum, * for use later on. */ for (i=GRANULE_SIZE, config->l3loop.xrmax=0; i--;) { config->l3loop.xrsq[i] = mulsr(config->l3loop.xr[i],config->l3loop.xr[i]); config->l3loop.xrabs[i] = labs(config->l3loop.xr[i]); if(config->l3loop.xrabs[i]>config->l3loop.xrmax) config->l3loop.xrmax=config->l3loop.xrabs[i]; } cod_info = (gr_info *) &(config->side_info.gr[gr].ch[ch]); cod_info->sfb_lmax = SFB_LMAX - 1; /* gr_deco */ calc_xmin(&config->ratio, cod_info, &l3_xmin, gr, ch ); if ( config->mpeg.version == MPEG_I ) calc_scfsi(&l3_xmin,ch,gr,config); /* calculation of number of available bit( per granule ) */ max_bits = shine_max_reservoir_bits(&config->pe[ch][gr],config); /* reset of iteration variables */ memset(config->scalefactor.l[gr][ch],0,sizeof(config->scalefactor.l[gr][ch])); memset(config->scalefactor.s[gr][ch],0,sizeof(config->scalefactor.s[gr][ch])); for ( i=4; i--; ) cod_info->slen[i] = 0; cod_info->part2_3_length = 0; cod_info->big_values = 0; cod_info->count1 = 0; cod_info->scalefac_compress = 0; cod_info->table_select[0] = 0; cod_info->table_select[1] = 0; cod_info->table_select[2] = 0; cod_info->region0_count = 0; cod_info->region1_count = 0; cod_info->part2_length = 0; cod_info->preflag = 0; cod_info->scalefac_scale = 0; cod_info->count1table_select= 0; /* all spectral values zero ? */ if(config->l3loop.xrmax) cod_info->part2_3_length = shine_outer_loop(max_bits,&l3_xmin,ix, gr,ch,config); shine_ResvAdjust(cod_info, config ); cod_info->global_gain = cod_info->quantizerStepSize+210; } /* for gr */ } /* for ch */ shine_ResvFrameEnd(config); }
/* * L3_iteration_loop: * ------------------ */ void L3_iteration_loop(struct config_t *cfg, double pe[][2], long mdct_freq_org[2][2][samp_per_frame2], L3_psy_ratio_t *ratio, L3_side_info_t *side_info, int l3_enc[2][2][samp_per_frame2], int mean_bits, L3_scalefac_t *scalefactor) { L3_psy_xmin_t l3_xmin; gr_info *cod_info; int *main_data_begin; int max_bits; int ch, gr, i; static int firstcall = 1; int *ix; main_data_begin = &side_info->main_data_begin; if ( firstcall ) { *main_data_begin = 0; firstcall=0; } scalefac_band_long = &sfBandIndex[cfg->mpeg.samplerate_index + (cfg->mpeg.type * 3)].l[0]; for(ch=cfg->wave.channels; ch--; ) { for(gr=0; gr<2; gr++) { /* setup pointers */ ix = l3_enc[gr][ch]; xr = mdct_freq_org[gr][ch]; /* Precalculate the square, abs, and maximum, * for use later on. */ for (i=samp_per_frame2, xrmax=0; i--;) { xrsq[i] = mulsr(xr[i],xr[i]); xrabs[i] = labs(xr[i]); if(xrabs[i]>xrmax) xrmax=xrabs[i]; } cod_info = (gr_info *) &(side_info->gr[gr].ch[ch]); cod_info->sfb_lmax = SFB_LMAX - 1; /* gr_deco */ calc_xmin(ratio, cod_info, &l3_xmin, gr, ch ); calc_scfsi(side_info,&l3_xmin,ch,gr); /* calculation of number of available bit( per granule ) */ max_bits = ResvMaxBits(cfg, side_info,&pe[gr][ch],mean_bits); /* reset of iteration variables */ memset(scalefactor->l[gr][ch],0,22); memset(scalefactor->s[gr][ch],0,14); for ( i=4; i--; ) cod_info->slen[i] = 0; cod_info->part2_3_length = 0; cod_info->big_values = 0; cod_info->count1 = 0; cod_info->scalefac_compress = 0; cod_info->table_select[0] = 0; cod_info->table_select[1] = 0; cod_info->table_select[2] = 0; cod_info->region0_count = 0; cod_info->region1_count = 0; cod_info->part2_length = 0; cod_info->preflag = 0; cod_info->scalefac_scale = 0; cod_info->count1table_select= 0; /* all spectral values zero ? */ if(xrmax) cod_info->part2_3_length = outer_loop(max_bits,&l3_xmin,ix, scalefactor, gr,ch,side_info ); ResvAdjust(cfg, cod_info, side_info, mean_bits ); cod_info->global_gain = cod_info->quantizerStepSize+210; } /* for gr */ } /* for ch */ ResvFrameEnd(cfg, side_info,mean_bits); }