public byte[] iteration_loop(SideInfoEnc side_info, FrameDataQuantized fd, int mean_bits) {
		int channels = fd.getChannels();

		EChannel cod_info;

		int max_bits;


		int enc[][][] = fd.ix;

		SideInfo side_info_dec = fd.si;

		int freq_index = fd.getFsIndex();
		scalefac_band_long = sfBandIndex[freq_index][0];
		scalefac_band_short = sfBandIndex[freq_index][1];

		// part2_len = 0;
		for (int ch = 0; ch < channels; ch ++)
			for (int i = 0; i < 4 ; i++){
				side_info.scfsi[ch][i] = fd.si.scfsi[ch][i];
			}

		//  ResvFrameBegin( side_info, mean_bits, 418*8 );
		for( int gr = 0; gr < GR_MAX; gr++ ) {
			for( int ch = 0; ch < channels; ch++ ) {

				cod_info = side_info.gr[gr].ch[ch];
				Channel gr_info_dec = side_info_dec.gr[gr].ch[ch];

				/* calculation of number of available bit( per granule ) */
				max_bits = mean_bits / channels;

				cod_info.part2_3_length    = 0;
				cod_info.setBigValues(0);
				cod_info.setCount1(0);
				cod_info.scalefac_compress = gr_info_dec.scalefac_compress;
				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.window_switching_flag = gr_info_dec.window_switching_flag;
				cod_info.preflag           = gr_info_dec.preflag;
				cod_info.scalefac_scale    = gr_info_dec.scalefac_scale;
				cod_info.block_type        = gr_info_dec.block_type;
				cod_info.subblock_gain[0]   = gr_info_dec.subblock_gain[0];
				cod_info.subblock_gain[1]   = gr_info_dec.subblock_gain[1];
				cod_info.subblock_gain[2]   = gr_info_dec.subblock_gain[2];


				cod_info.mixed_block_flag  = gr_info_dec.mixed_block_flag;

				// if(ch==0){
				this.scalefac0L[gr][ch] = fd.scalefac0L[gr][ch];
				this.scalefac0S[gr][ch] = fd.scalefac0S[gr][ch];
				/*} else{
                    this.scalefac1L = fd.scalefac1L[ch][ch];
                    this.scalefac1S = fd.scalefac1S[ch][ch];
                }*/
				// bigvalues_region = FREQUENCY_LINES;
				//cod_info.quantizerStepSize = 0.0;
				cod_info.count1table_select = 0;
				int ix_abs[] = new int [FREQUENCY_LINES];
				int [] ix = enc[gr][ch];
				for(int i = 0; i < FREQUENCY_LINES; i++)
					ix_abs[i] = Math.abs(ix[i]);
				outer_loop(max_bits, ix_abs, gr, ch, side_info );

				cod_info.global_gain = gr_info_dec.global_gain;


			} /* for ch */
		} /* for ch */

		for(int gr = 0; gr < GR_MAX; gr++ ){
			for(int ch = 0; ch < channels; ch++ ) {
				int [] ix = enc[gr][ch];

				cod_info = side_info.gr[gr].ch[ch];
				write_scalefactors(side_info, ch, gr);
				int bits = Huffmancodebits( ix, cod_info );
				cod_info.part2_3_length = cod_info.part2_length + bits;
			}
		}

		return mn.format_main_data();
	}