private Sound generateSound(SoundPool soundPool,File dir,String name,int lengthMsec,int freqHz){
  Sound sound=null;
  File outFile=new File(dir,name + ".wav");
  if (!outFile.exists()) {
    try {
      FileOutputStream fos=new FileOutputStream(outFile);
      int sampleCount=lengthMsec * SAMPLE_RATE / 1000;
      ByteBuffer buf=generateWavHeader(sampleCount);
      byte[] array=buf.array();
      fos.write(array);
      buf=generateWavData(sampleCount,freqHz);
      array=buf.array();
      fos.write(array);
      fos.close();
      Log.d(TAG,"Wrote sound file " + outFile.toString());
    }
 catch (    IOException ioe) {
      Log.e(TAG,"sound file op failed: " + ioe.getMessage());
      throw new RuntimeException(ioe);
    }
  }
 else {
  }
  int handle=soundPool.load(outFile.toString(),1);
  return new Sound(name,soundPool,handle);
}

private Sound generateSound ( SoundPool soundPool , File dir , String name , int lengthMsec , int freqHz ) { Sound sound = null ; File outFile = new File ( dir , name + ".wav" ) ; if ( ! outFile . exists ( ) ) { try { FileOutputStream fos = new FileOutputStream ( outFile ) ; int sampleCount = lengthMsec * SAMPLE_RATE / 1000 ; ByteBuffer buf = generateWavHeader ( sampleCount ) ; byte [ ] array = buf . array ( ) ; fos . write ( array ) ; buf = generateWavData ( sampleCount , freqHz ) ; array = buf . array ( ) ; fos . write ( array ) ; fos . close ( ) ; Log . d ( TAG , "Wrote sound file " + outFile . toString ( ) ) ; } catch ( IOException ioe ) { Log . e ( TAG , "sound file op failed: " + ioe . getMessage ( ) ) ; throw new RuntimeException ( ioe ) ; } } else { } int handle = soundPool . load ( outFile . toString ( ) , 1 ) ; return new Sound ( name , soundPool , handle ) ; }
generate a sound with specific characteristics .
