public int getValueForPosition ( int p ) { int pt = nPoints - 1 ; for ( int i = 0 ; i < pt ; i ++ ) { if ( p <= position [ i ] ) { pt = i ; break ; } } int x2 = position [ pt ] ; int x1 , v ; if ( p >= x2 ) { v = value [ pt ] << SHIFT ; x1 = x2 ; } else if ( pt > 0 ) { v = value [ pt - 1 ] << SHIFT ; x1 = position [ pt - 1 ] ; } else { v = x1 = 0 ; } if ( p > x2 ) p = x2 ; if ( ( x2 > x1 ) && ( p > x1 ) ) { v += ( ( p - x1 ) * ( ( value [ pt ] << SHIFT ) - v ) ) / ( x2 - x1 ) ; } if ( v < 0 ) v = 0 ; else if ( v > MAXVALUE ) v = MAXVALUE ; return v ; }
get the value at the position Returns values between 0 and 512