src/main/java/net/sourceforge/jaad/aac/sbr/FBT.java
public static int derived_frequency_table(SBR sbr, int bs_xover_band,
		int k2) {
		int k, i = 0;
		int minus;

		/* The following relation shall be satisfied: bs_xover_band < N_Master */
		if(sbr.N_master<=bs_xover_band)
			return 1;

		sbr.N_high = sbr.N_master-bs_xover_band;
		sbr.N_low = (sbr.N_high>>1)+(sbr.N_high-((sbr.N_high>>1)<<1));

		sbr.n[0] = sbr.N_low;
		sbr.n[1] = sbr.N_high;

		for(k = 0; k<=sbr.N_high; k++) {
			sbr.f_table_res[HI_RES][k] = sbr.f_master[k+bs_xover_band];
		}

		sbr.M = sbr.f_table_res[HI_RES][sbr.N_high]-sbr.f_table_res[HI_RES][0];
		sbr.kx = sbr.f_table_res[HI_RES][0];
		if(sbr.kx>32)
			return 1;
		if(sbr.kx+sbr.M>64)
			return 1;

		minus = ((sbr.N_high&1)!=0) ? 1 : 0;

		for(k = 0; k<=sbr.N_low; k++) {
			if(k==0)
				i = 0;
			else
				i = (2*k-minus);
			sbr.f_table_res[LO_RES][k] = sbr.f_table_res[HI_RES][i];
		}

		sbr.N_Q = 0;
		if(sbr.bs_noise_bands==0) {
			sbr.N_Q = 1;
		}
		else {
			sbr.N_Q = (Math.max(1, find_bands(0, sbr.bs_noise_bands, sbr.kx, k2)));
			sbr.N_Q = Math.min(5, sbr.N_Q);
		}

		for(k = 0; k<=sbr.N_Q; k++) {
			if(k==0) {
				i = 0;
			}
			else {
				/* i = i + (int32_t)((sbr.N_low - i)/(sbr.N_Q + 1 - k)); */
				i += (sbr.N_low-i)/(sbr.N_Q+1-k);
			}
			sbr.f_table_noise[k] = sbr.f_table_res[LO_RES][i];
		}

		/* build table for mapping k to g in hf patching */
		for(k = 0; k<64; k++) {
			int g;
			for(g = 0; g<sbr.N_Q; g++) {
				if((sbr.f_table_noise[g]<=k)
					&&(k<sbr.f_table_noise[g+1])) {
					sbr.table_map_k_to_g[k] = g;
					break;
				}
			}
		}
		return 0;
	}
public static int derived_frequency_table(SBR sbr, int bs_xover_band,
		int k2) {
		int k, i = 0;
		int minus;

		/* The following relation shall be satisfied: bs_xover_band < N_Master */
		if(sbr.N_master<=bs_xover_band)
			return 1;

		sbr.N_high = sbr.N_master-bs_xover_band;
		sbr.N_low = (sbr.N_high>>1)+(sbr.N_high-((sbr.N_high>>1)<<1));

		sbr.n[0] = sbr.N_low;
		sbr.n[1] = sbr.N_high;

		for(k = 0; k<=sbr.N_high; k++) {
			sbr.f_table_res[HI_RES][k] = sbr.f_master[k+bs_xover_band];
		}

		sbr.M = sbr.f_table_res[HI_RES][sbr.N_high]-sbr.f_table_res[HI_RES][0];
		sbr.kx = sbr.f_table_res[HI_RES][0];
		if(sbr.kx>32)
			return 1;
		if(sbr.kx+sbr.M>64)
			return 1;

		minus = ((sbr.N_high&1)!=0) ? 1 : 0;

		for(k = 0; k<=sbr.N_low; k++) {
			if(k==0)
				i = 0;
			else
				i = (2*k-minus);
			sbr.f_table_res[LO_RES][k] = sbr.f_table_res[HI_RES][i];
		}

		sbr.N_Q = 0;
		if(sbr.bs_noise_bands==0) {
			sbr.N_Q = 1;
		}
		else {
			sbr.N_Q = (Math.max(1, find_bands(0, sbr.bs_noise_bands, sbr.kx, k2)));
			sbr.N_Q = Math.min(5, sbr.N_Q);
		}

		for(k = 0; k<=sbr.N_Q; k++) {
			if(k==0) {
				i = 0;
			}
			else {
				/* i = i + (int32_t)((sbr.N_low - i)/(sbr.N_Q + 1 - k)); */
				i += (sbr.N_low-i)/(sbr.N_Q+1-k);
			}
			sbr.f_table_noise[k] = sbr.f_table_res[LO_RES][i];
		}

		/* build table for mapping k to g in hf patching */
		for(k = 0; k<64; k++) {
			int g;
			for(g = 0; g<sbr.N_Q; g++) {
				if((sbr.f_table_noise[g]<=k)
					&&(k<sbr.f_table_noise[g+1])) {
					sbr.table_map_k_to_g[k] = g;
					break;
				}
			}
		}
		return 0;
	}
public static int derived_frequency_table ( SBR sbr , int bs_xover_band , int k2 ) { int k , i = 0 ; int minus ; /* The following relation shall be satisfied: bs_xover_band < N_Master */ if ( sbr . N_master <= bs_xover_band ) return 1 ; sbr . N_high = sbr . N_master - bs_xover_band ; sbr . N_low = ( sbr . N_high >> 1 ) + ( sbr . N_high - ( ( sbr . N_high >> 1 ) << 1 ) ) ; sbr . n [ 0 ] = sbr . N_low ; sbr . n [ 1 ] = sbr . N_high ; for ( k = 0 ; k <= sbr . N_high ; k ++ ) { sbr . f_table_res [ HI_RES ] [ k ] = sbr . f_master [ k + bs_xover_band ] ; } sbr . M = sbr . f_table_res [ HI_RES ] [ sbr . N_high ] - sbr . f_table_res [ HI_RES ] [ 0 ] ; sbr . kx = sbr . f_table_res [ HI_RES ] [ 0 ] ; if ( sbr . kx > 32 ) return 1 ; if ( sbr . kx + sbr . M > 64 ) return 1 ; minus = ( ( sbr . N_high & 1 ) != 0 ) ? 1 : 0 ; for ( k = 0 ; k <= sbr . N_low ; k ++ ) { if ( k == 0 ) i = 0 ; else i = ( 2 * k - minus ) ; sbr . f_table_res [ LO_RES ] [ k ] = sbr . f_table_res [ HI_RES ] [ i ] ; } sbr . N_Q = 0 ; if ( sbr . bs_noise_bands == 0 ) { sbr . N_Q = 1 ; } else { sbr . N_Q = ( Math . max ( 1 , find_bands ( 0 , sbr . bs_noise_bands , sbr . kx , k2 ) ) ) ; sbr . N_Q = Math . min ( 5 , sbr . N_Q ) ; } for ( k = 0 ; k <= sbr . N_Q ; k ++ ) { if ( k == 0 ) { i = 0 ; } else { /* i = i + (int32_t)((sbr.N_low - i)/(sbr.N_Q + 1 - k)); */ i += ( sbr . N_low - i ) / ( sbr . N_Q + 1 - k ) ; } sbr . f_table_noise [ k ] = sbr . f_table_res [ LO_RES ] [ i ] ; } /* build table for mapping k to g in hf patching */ for ( k = 0 ; k < 64 ; k ++ ) { int g ; for ( g = 0 ; g < sbr . N_Q ; g ++ ) { if ( ( sbr . f_table_noise [ g ] <= k ) && ( k < sbr . f_table_noise [ g + 1 ] ) ) { sbr . table_map_k_to_g [ k ] = g ; break ; } } } return 0 ; }
/* calculate the derived frequency border tables from f_master
/ * calculate the derived frequency border tables from f_master