protected void computeDoublesForAllZoomLevels(){
  int numFrames=mSoundFile.getNumFrames();
  float maxGain=1.0f;
  for (int i=0; i < numFrames; i++) {
    float gain=getGain(i,numFrames,mSoundFile.getFrameGains());
    if (gain > maxGain) {
      maxGain=gain;
    }
  }
  scaleFactor=1.0f;
  if (maxGain > 255.0) {
    scaleFactor=255 / maxGain;
  }
  maxGain=0;
  int gainHist[]=new int[256];
  for (int i=0; i < numFrames; i++) {
    int smoothedGain=(int)(getGain(i,numFrames,mSoundFile.getFrameGains()) * scaleFactor);
    if (smoothedGain < 0)     smoothedGain=0;
    if (smoothedGain > 255)     smoothedGain=255;
    if (smoothedGain > maxGain)     maxGain=smoothedGain;
    gainHist[smoothedGain]++;
  }
  minGain=0;
  int sum=0;
  while (minGain < 255 && sum < numFrames / 20) {
    sum+=gainHist[(int)minGain];
    minGain++;
  }
  sum=0;
  while (maxGain > 2 && sum < numFrames / 100) {
    sum+=gainHist[(int)maxGain];
    maxGain--;
  }
  range=maxGain - minGain;
  mNumZoomLevels=4;
  mLenByZoomLevel=new int[4];
  mZoomFactorByZoomLevel=new float[4];
  float ratio=getMeasuredWidth() / (float)numFrames;
  if (ratio < 1) {
    mLenByZoomLevel[0]=Math.round(numFrames * ratio);
    mZoomFactorByZoomLevel[0]=ratio;
    mLenByZoomLevel[1]=numFrames;
    mZoomFactorByZoomLevel[1]=1.0f;
    mLenByZoomLevel[2]=numFrames * 2;
    mZoomFactorByZoomLevel[2]=2.0f;
    mLenByZoomLevel[3]=numFrames * 3;
    mZoomFactorByZoomLevel[3]=3.0f;
    mZoomLevel=0;
  }
 else {
    mLenByZoomLevel[0]=numFrames;
    mZoomFactorByZoomLevel[0]=1.0f;
    mLenByZoomLevel[1]=numFrames * 2;
    mZoomFactorByZoomLevel[1]=2f;
    mLenByZoomLevel[2]=numFrames * 3;
    mZoomFactorByZoomLevel[2]=3.0f;
    mLenByZoomLevel[3]=numFrames * 4;
    mZoomFactorByZoomLevel[3]=4.0f;
    mZoomLevel=0;
    for (int i=0; i < 4; i++) {
      if (mLenByZoomLevel[mZoomLevel] - getMeasuredWidth() > 0) {
        break;
      }
 else {
        mZoomLevel=i;
      }
    }
  }
  mInitialized=true;
}

protected void computeDoublesForAllZoomLevels ( ) { int numFrames = mSoundFile . getNumFrames ( ) ; float maxGain = 1.0f ; for ( int i = 0 ; i < numFrames ; i ++ ) { float gain = getGain ( i , numFrames , mSoundFile . getFrameGains ( ) ) ; if ( gain > maxGain ) { maxGain = gain ; } } scaleFactor = 1.0f ; if ( maxGain > 255.0 ) { scaleFactor = 255 / maxGain ; } maxGain = 0 ; int gainHist [ ] = new int [ 256 ] ; for ( int i = 0 ; i < numFrames ; i ++ ) { int smoothedGain = ( int ) ( getGain ( i , numFrames , mSoundFile . getFrameGains ( ) ) * scaleFactor ) ; if ( smoothedGain < 0 ) smoothedGain = 0 ; if ( smoothedGain > 255 ) smoothedGain = 255 ; if ( smoothedGain > maxGain ) maxGain = smoothedGain ; gainHist [ smoothedGain ] ++ ; } minGain = 0 ; int sum = 0 ; while ( minGain < 255 && sum < numFrames / 20 ) { sum += gainHist [ ( int ) minGain ] ; minGain ++ ; } sum = 0 ; while ( maxGain > 2 && sum < numFrames / 100 ) { sum += gainHist [ ( int ) maxGain ] ; maxGain -- ; } range = maxGain - minGain ; mNumZoomLevels = 4 ; mLenByZoomLevel = new int [ 4 ] ; mZoomFactorByZoomLevel = new float [ 4 ] ; float ratio = getMeasuredWidth ( ) / ( float ) numFrames ; if ( ratio < 1 ) { mLenByZoomLevel [ 0 ] = Math . round ( numFrames * ratio ) ; mZoomFactorByZoomLevel [ 0 ] = ratio ; mLenByZoomLevel [ 1 ] = numFrames ; mZoomFactorByZoomLevel [ 1 ] = 1.0f ; mLenByZoomLevel [ 2 ] = numFrames * 2 ; mZoomFactorByZoomLevel [ 2 ] = 2.0f ; mLenByZoomLevel [ 3 ] = numFrames * 3 ; mZoomFactorByZoomLevel [ 3 ] = 3.0f ; mZoomLevel = 0 ; } else { mLenByZoomLevel [ 0 ] = numFrames ; mZoomFactorByZoomLevel [ 0 ] = 1.0f ; mLenByZoomLevel [ 1 ] = numFrames * 2 ; mZoomFactorByZoomLevel [ 1 ] = 2f ; mLenByZoomLevel [ 2 ] = numFrames * 3 ; mZoomFactorByZoomLevel [ 2 ] = 3.0f ; mLenByZoomLevel [ 3 ] = numFrames * 4 ; mZoomFactorByZoomLevel [ 3 ] = 4.0f ; mZoomLevel = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { if ( mLenByZoomLevel [ mZoomLevel ] - getMeasuredWidth ( ) > 0 ) { break ; } else { mZoomLevel = i ; } } } mInitialized = true ; }
called once when a new sound file is added
