final float div2 = (float) k1/(float) k0;
float log = (float) Math.log(div2)/(float) (2*LOG2);
final int bandCount0 = 2*Math.round(bands*log);
//check requirement (4.6.18.6.3):
if(bandCount0<=0) throw new AACException("SBR: illegal band count for master frequency table: "+bandCount0);
final int[] vDk0 = new int[bandCount0];
float pow1, pow2;
for(int i = 0; i<bandCount0; i++) {
pow1 = (float) Math.pow(div2, (float) (i+1)/bandCount0);
pow2 = (float) Math.pow(div2, (float) i/bandCount0);
vDk0[i] = Math.round(k0*pow1)-Math.round(k0*pow2);
//check requirement (4.6.18.6.3):
if(vDk0[i]<=0) throw new AACException("SBR: illegal value in master frequency table: "+vDk0[i]);
}
Arrays.sort(vDk0);
final int[] vk0 = new int[bandCount0+1];
vk0[0] = k0;
for(int i = 1; i<=bandCount0; i++) {
vk0[i] = vk0[i-1]+vDk0[i-1];
}
if(twoRegions) {
div1 = (float) k2/(float) k1;
log = (float) Math.log(div1);
final int bandCount1 = 2*(int) Math.round(bands*log/(2*LOG2*warp));
final int[] vDk1 = new int[bandCount1];
int min = -1;
for(int i = 0; i<bandCount1; i++) {
pow1 = (float) Math.pow(div1, (float) (i+1)/bandCount1);
pow2 = (float) Math.pow(div1, (float) i/bandCount1);
vDk1[i] = Math.round(k1*pow1)-Math.round(k1*pow2);
if(min<0||vDk1[i]<min) min = vDk1[i];
//check requirement (4.6.18.6.3):
else if(vDk1[i]<=0) throw new AACException("SBR: illegal value in master frequency table: "+vDk1[i]);
}
if(min<vDk0[vDk0.length-1]) {
Arrays.sort(vDk1);
int change = vDk0[vDk0.length-1]-vDk1[0];