public static double[] lpc2lsf(double[] oneMinusA,int type){
  int order=oneMinusA.length - 1;
  double[] g1=new double[100];
  double[] g2=new double[100];
  double[] g1r=new double[100];
  double[] g2r=new double[100];
  boolean even;
  int g1_order, g2_order;
  int orderd2;
  int i, j;
  int swap;
  double Factor;
  even=(order & 1) == 0;
  if (even)   g1_order=g2_order=order / 2;
 else {
    g1_order=(order + 1) / 2;
    g2_order=g1_order - 1;
    throw new IllegalArgumentException("Odd order not implemented yet");
  }
  orderd2=(order + 1) / 2;
  g1[orderd2]=oneMinusA[0];
  for (i=1; i <= orderd2; i++)   g1[g1_order - i]=oneMinusA[i] + oneMinusA[order + 1 - i];
  g2[orderd2]=oneMinusA[0];
  for (i=1; i <= orderd2; i++)   g2[orderd2 - i]=oneMinusA[i] - oneMinusA[order + 1 - i];
  if (even) {
    for (i=1; i <= orderd2; i++)     g1[orderd2 - i]-=g1[orderd2 - i + 1];
    for (i=1; i <= orderd2; i++)     g2[orderd2 - i]+=g2[orderd2 - i + 1];
  }
 else {
    for (i=2; i <= orderd2; i++)     g2[orderd2 - i]+=g2[orderd2 - i + 2];
  }
  if (type == 1) {
    cheby1(g1,g1_order);
    cheby1(g2,g2_order);
    Factor=0.5;
  }
 else   if (type == 2) {
    cheby2(g1,g1_order);
    cheby2(g2,g2_order);
    Factor=0.5;
  }
 else   if (type == 3) {
    cheby3(g1,g1_order);
    cheby3(g2,g2_order);
    Factor=1.0;
  }
 else   if (type == 4) {
    kw(g1,g1_order);
    kw(g2,g2_order);
    Factor=0.5;
  }
 else {
    throw new IllegalArgumentException("valid type values are 1 to 4.\n");
  }
  cacm283(g1,g1_order,g1r);
  cacm283(g2,g2_order,g2r);
  double[] lsp=new double[order];
  for (i=0, j=0; ; ) {
    lsp[j++]=Math.acos(Factor * g1r[i]) / MathUtils.TWOPI;
    if (j >= order)     break;
    lsp[j++]=Math.acos(Factor * g2r[i]) / MathUtils.TWOPI;
    if (j >= order)     break;
    i++;
  }
  return lsp;
}

public static double [ ] lpc2lsf ( double [ ] oneMinusA , int type ) { int order = oneMinusA . length - 1 ; double [ ] g1 = new double [ 100 ] ; double [ ] g2 = new double [ 100 ] ; double [ ] g1r = new double [ 100 ] ; double [ ] g2r = new double [ 100 ] ; boolean even ; int g1_order , g2_order ; int orderd2 ; int i , j ; int swap ; double Factor ; even = ( order & 1 ) == 0 ; if ( even ) g1_order = g2_order = order / 2 ; else { g1_order = ( order + 1 ) / 2 ; g2_order = g1_order - 1 ; throw new IllegalArgumentException ( "Odd order not implemented yet" ) ; } orderd2 = ( order + 1 ) / 2 ; g1 [ orderd2 ] = oneMinusA [ 0 ] ; for ( i = 1 ; i <= orderd2 ; i ++ ) g1 [ g1_order - i ] = oneMinusA [ i ] + oneMinusA [ order + 1 - i ] ; g2 [ orderd2 ] = oneMinusA [ 0 ] ; for ( i = 1 ; i <= orderd2 ; i ++ ) g2 [ orderd2 - i ] = oneMinusA [ i ] - oneMinusA [ order + 1 - i ] ; if ( even ) { for ( i = 1 ; i <= orderd2 ; i ++ ) g1 [ orderd2 - i ] -= g1 [ orderd2 - i + 1 ] ; for ( i = 1 ; i <= orderd2 ; i ++ ) g2 [ orderd2 - i ] += g2 [ orderd2 - i + 1 ] ; } else { for ( i = 2 ; i <= orderd2 ; i ++ ) g2 [ orderd2 - i ] += g2 [ orderd2 - i + 2 ] ; } if ( type == 1 ) { cheby1 ( g1 , g1_order ) ; cheby1 ( g2 , g2_order ) ; Factor = 0.5 ; } else if ( type == 2 ) { cheby2 ( g1 , g1_order ) ; cheby2 ( g2 , g2_order ) ; Factor = 0.5 ; } else if ( type == 3 ) { cheby3 ( g1 , g1_order ) ; cheby3 ( g2 , g2_order ) ; Factor = 1.0 ; } else if ( type == 4 ) { kw ( g1 , g1_order ) ; kw ( g2 , g2_order ) ; Factor = 0.5 ; } else { throw new IllegalArgumentException ( "valid type values are 1 to 4.\n" ) ; } cacm283 ( g1 , g1_order , g1r ) ; cacm283 ( g2 , g2_order , g2r ) ; double [ ] lsp = new double [ order ] ; for ( i = 0 , j = 0 ; ; ) { lsp [ j ++ ] = Math . acos ( Factor * g1r [ i ] ) / MathUtils . TWOPI ; if ( j >= order ) break ; lsp [ j ++ ] = Math . acos ( Factor * g2r [ i ] ) / MathUtils . TWOPI ; if ( j >= order ) break ; i ++ ; } return lsp ; }
convert filter coefficients to lsp coefficients .
