src/main/java/net/sourceforge/jaad/aac/sbr/FBT.java
public static int master_frequency_table(SBR sbr, int k0, int k2,
		int bs_freq_scale, boolean bs_alter_scale) {
		int k, bands;
		boolean twoRegions;
		int k1;
		int nrBand0, nrBand1;
		int[] vDk0 = new int[64], vDk1 = new int[64];
		int[] vk0 = new int[64], vk1 = new int[64];
		int[] temp1 = {6, 5, 4};
		float q, qk;
		int A_1;

		/* mft only defined for k2 > k0 */
		if(k2<=k0) {
			sbr.N_master = 0;
			return 1;
		}

		bands = temp1[bs_freq_scale-1];

		if((float) k2/(float) k0>2.2449) {
			twoRegions = true;
			k1 = k0<<1;
		}
		else {
			twoRegions = false;
			k1 = k2;
		}

		nrBand0 = (2*find_bands(0, bands, k0, k1));
		nrBand0 = Math.min(nrBand0, 63);
		if(nrBand0<=0)
			return 1;

		q = find_initial_power(nrBand0, k0, k1);
		qk = k0;
		A_1 = (int) (qk+0.5f);
		for(k = 0; k<=nrBand0; k++) {
			int A_0 = A_1;
			qk *= q;
			A_1 = (int) (qk+0.5f);
			vDk0[k] = A_1-A_0;
		}

		/* needed? */
		//qsort(vDk0, nrBand0, sizeof(vDk0[0]), longcmp);
		Arrays.sort(vDk0, 0, nrBand0);

		vk0[0] = k0;
		for(k = 1; k<=nrBand0; k++) {
			vk0[k] = vk0[k-1]+vDk0[k-1];
			if(vDk0[k-1]==0)
				return 1;
		}

		if(!twoRegions) {
			for(k = 0; k<=nrBand0; k++) {
				sbr.f_master[k] = vk0[k];
			}

			sbr.N_master = nrBand0;
			sbr.N_master = Math.min(sbr.N_master, 64);
			return 0;
		}

		nrBand1 = (2*find_bands(1 /* warped */, bands, k1, k2));
		nrBand1 = Math.min(nrBand1, 63);

		q = find_initial_power(nrBand1, k1, k2);
		qk = k1;
		A_1 = (int) (qk+0.5f);
		for(k = 0; k<=nrBand1-1; k++) {
			int A_0 = A_1;
			qk *= q;
			A_1 = (int) (qk+0.5f);
			vDk1[k] = A_1-A_0;
		}

		if(vDk1[0]<vDk0[nrBand0-1]) {
			int change;

			/* needed? */
			//qsort(vDk1, nrBand1+1, sizeof(vDk1[0]), longcmp);
			Arrays.sort(vDk1, 0, nrBand1+1);
			change = vDk0[nrBand0-1]-vDk1[0];
			vDk1[0] = vDk0[nrBand0-1];
			vDk1[nrBand1-1] = vDk1[nrBand1-1]-change;
		}

		/* needed? */
		//qsort(vDk1, nrBand1, sizeof(vDk1[0]), longcmp);
		Arrays.sort(vDk1, 0, nrBand1);
		vk1[0] = k1;
		for(k = 1; k<=nrBand1; k++) {
			vk1[k] = vk1[k-1]+vDk1[k-1];
			if(vDk1[k-1]==0)
				return 1;
		}

		sbr.N_master = nrBand0+nrBand1;
		sbr.N_master = Math.min(sbr.N_master, 64);
		for(k = 0; k<=nrBand0; k++) {
			sbr.f_master[k] = vk0[k];
		}
		for(k = nrBand0+1; k<=sbr.N_master; k++) {
			sbr.f_master[k] = vk1[k-nrBand0];
		}

		return 0;
	}
public static int master_frequency_table(SBR sbr, int k0, int k2,
		int bs_freq_scale, boolean bs_alter_scale) {
		int k, bands;
		boolean twoRegions;
		int k1;
		int nrBand0, nrBand1;
		int[] vDk0 = new int[64], vDk1 = new int[64];
		int[] vk0 = new int[64], vk1 = new int[64];
		int[] temp1 = {6, 5, 4};
		float q, qk;
		int A_1;

		/* mft only defined for k2 > k0 */
		if(k2<=k0) {
			sbr.N_master = 0;
			return 1;
		}

		bands = temp1[bs_freq_scale-1];

		if((float) k2/(float) k0>2.2449) {
			twoRegions = true;
			k1 = k0<<1;
		}
		else {
			twoRegions = false;
			k1 = k2;
		}

		nrBand0 = (2*find_bands(0, bands, k0, k1));
		nrBand0 = Math.min(nrBand0, 63);
		if(nrBand0<=0)
			return 1;

		q = find_initial_power(nrBand0, k0, k1);
		qk = k0;
		A_1 = (int) (qk+0.5f);
		for(k = 0; k<=nrBand0; k++) {
			int A_0 = A_1;
			qk *= q;
			A_1 = (int) (qk+0.5f);
			vDk0[k] = A_1-A_0;
		}

		/* needed? */
		//qsort(vDk0, nrBand0, sizeof(vDk0[0]), longcmp);
		Arrays.sort(vDk0, 0, nrBand0);

		vk0[0] = k0;
		for(k = 1; k<=nrBand0; k++) {
			vk0[k] = vk0[k-1]+vDk0[k-1];
			if(vDk0[k-1]==0)
				return 1;
		}

		if(!twoRegions) {
			for(k = 0; k<=nrBand0; k++) {
				sbr.f_master[k] = vk0[k];
			}

			sbr.N_master = nrBand0;
			sbr.N_master = Math.min(sbr.N_master, 64);
			return 0;
		}

		nrBand1 = (2*find_bands(1 /* warped */, bands, k1, k2));
		nrBand1 = Math.min(nrBand1, 63);

		q = find_initial_power(nrBand1, k1, k2);
		qk = k1;
		A_1 = (int) (qk+0.5f);
		for(k = 0; k<=nrBand1-1; k++) {
			int A_0 = A_1;
			qk *= q;
			A_1 = (int) (qk+0.5f);
			vDk1[k] = A_1-A_0;
		}

		if(vDk1[0]<vDk0[nrBand0-1]) {
			int change;

			/* needed? */
			//qsort(vDk1, nrBand1+1, sizeof(vDk1[0]), longcmp);
			Arrays.sort(vDk1, 0, nrBand1+1);
			change = vDk0[nrBand0-1]-vDk1[0];
			vDk1[0] = vDk0[nrBand0-1];
			vDk1[nrBand1-1] = vDk1[nrBand1-1]-change;
		}

		/* needed? */
		//qsort(vDk1, nrBand1, sizeof(vDk1[0]), longcmp);
		Arrays.sort(vDk1, 0, nrBand1);
		vk1[0] = k1;
		for(k = 1; k<=nrBand1; k++) {
			vk1[k] = vk1[k-1]+vDk1[k-1];
			if(vDk1[k-1]==0)
				return 1;
		}

		sbr.N_master = nrBand0+nrBand1;
		sbr.N_master = Math.min(sbr.N_master, 64);
		for(k = 0; k<=nrBand0; k++) {
			sbr.f_master[k] = vk0[k];
		}
		for(k = nrBand0+1; k<=sbr.N_master; k++) {
			sbr.f_master[k] = vk1[k-nrBand0];
		}

		return 0;
	}
public static int master_frequency_table ( SBR sbr , int k0 , int k2 , int bs_freq_scale , boolean bs_alter_scale ) { int k , bands ; boolean twoRegions ; int k1 ; int nrBand0 , nrBand1 ; int [ ] vDk0 = new int [ 64 ] , vDk1 = new int [ 64 ] ; int [ ] vk0 = new int [ 64 ] , vk1 = new int [ 64 ] ; int [ ] temp1 = { 6 , 5 , 4 } ; float q , qk ; int A_1 ; /* mft only defined for k2 > k0 */ if ( k2 <= k0 ) { sbr . N_master = 0 ; return 1 ; } bands = temp1 [ bs_freq_scale - 1 ] ; if ( ( float ) k2 / ( float ) k0 > 2.2449 ) { twoRegions = true ; k1 = k0 << 1 ; } else { twoRegions = false ; k1 = k2 ; } nrBand0 = ( 2 * find_bands ( 0 , bands , k0 , k1 ) ) ; nrBand0 = Math . min ( nrBand0 , 63 ) ; if ( nrBand0 <= 0 ) return 1 ; q = find_initial_power ( nrBand0 , k0 , k1 ) ; qk = k0 ; A_1 = ( int ) ( qk + 0.5f ) ; for ( k = 0 ; k <= nrBand0 ; k ++ ) { int A_0 = A_1 ; qk *= q ; A_1 = ( int ) ( qk + 0.5f ) ; vDk0 [ k ] = A_1 - A_0 ; } /* needed? */ //qsort(vDk0, nrBand0, sizeof(vDk0[0]), longcmp); Arrays . sort ( vDk0 , 0 , nrBand0 ) ; vk0 [ 0 ] = k0 ; for ( k = 1 ; k <= nrBand0 ; k ++ ) { vk0 [ k ] = vk0 [ k - 1 ] + vDk0 [ k - 1 ] ; if ( vDk0 [ k - 1 ] == 0 ) return 1 ; } if ( ! twoRegions ) { for ( k = 0 ; k <= nrBand0 ; k ++ ) { sbr . f_master [ k ] = vk0 [ k ] ; } sbr . N_master = nrBand0 ; sbr . N_master = Math . min ( sbr . N_master , 64 ) ; return 0 ; } nrBand1 = ( 2 * find_bands ( 1 /* warped */ , bands , k1 , k2 ) ) ; nrBand1 = Math . min ( nrBand1 , 63 ) ; q = find_initial_power ( nrBand1 , k1 , k2 ) ; qk = k1 ; A_1 = ( int ) ( qk + 0.5f ) ; for ( k = 0 ; k <= nrBand1 - 1 ; k ++ ) { int A_0 = A_1 ; qk *= q ; A_1 = ( int ) ( qk + 0.5f ) ; vDk1 [ k ] = A_1 - A_0 ; } if ( vDk1 [ 0 ] < vDk0 [ nrBand0 - 1 ] ) { int change ; /* needed? */ //qsort(vDk1, nrBand1+1, sizeof(vDk1[0]), longcmp); Arrays . sort ( vDk1 , 0 , nrBand1 + 1 ) ; change = vDk0 [ nrBand0 - 1 ] - vDk1 [ 0 ] ; vDk1 [ 0 ] = vDk0 [ nrBand0 - 1 ] ; vDk1 [ nrBand1 - 1 ] = vDk1 [ nrBand1 - 1 ] - change ; } /* needed? */ //qsort(vDk1, nrBand1, sizeof(vDk1[0]), longcmp); Arrays . sort ( vDk1 , 0 , nrBand1 ) ; vk1 [ 0 ] = k1 ; for ( k = 1 ; k <= nrBand1 ; k ++ ) { vk1 [ k ] = vk1 [ k - 1 ] + vDk1 [ k - 1 ] ; if ( vDk1 [ k - 1 ] == 0 ) return 1 ; } sbr . N_master = nrBand0 + nrBand1 ; sbr . N_master = Math . min ( sbr . N_master , 64 ) ; for ( k = 0 ; k <= nrBand0 ; k ++ ) { sbr . f_master [ k ] = vk0 [ k ] ; } for ( k = nrBand0 + 1 ; k <= sbr . N_master ; k ++ ) { sbr . f_master [ k ] = vk1 [ k - nrBand0 ] ; } return 0 ; }
/*
version for bs_freq_scale > 0
/ * version for bs_freq_scale > 0