public void prepare(){
  try {
    if (state == State.INITIALIZING) {
      if (rUncompressed) {
        if ((audioRecorder.getState() == AudioRecord.STATE_INITIALIZED) & (filePath != null)) {
          randomAccessWriter=new RandomAccessFile(filePath,"rw");
          randomAccessWriter.setLength(0);
          randomAccessWriter.writeBytes("RIFF");
          randomAccessWriter.writeInt(0);
          randomAccessWriter.writeBytes("WAVE");
          randomAccessWriter.writeBytes("fmt ");
          randomAccessWriter.writeInt(Integer.reverseBytes(16));
          randomAccessWriter.writeShort(Short.reverseBytes((short)1));
          randomAccessWriter.writeShort(Short.reverseBytes(nChannels));
          randomAccessWriter.writeInt(Integer.reverseBytes(sRate));
          randomAccessWriter.writeInt(Integer.reverseBytes(sRate * bSamples * nChannels / 8));
          randomAccessWriter.writeShort(Short.reverseBytes((short)(nChannels * bSamples / 8)));
          randomAccessWriter.writeShort(Short.reverseBytes(bSamples));
          randomAccessWriter.writeBytes("data");
          randomAccessWriter.writeInt(0);
          buffer=new byte[framePeriod * bSamples / 8 * nChannels];
          state=State.READY;
        }
 else {
          state=State.ERROR;
        }
      }
 else {
        mediaRecorder.prepare();
        state=State.READY;
      }
    }
 else {
      release();
      state=State.ERROR;
    }
  }
 catch (  Exception e) {
    state=State.ERROR;
  }
}

public void prepare ( ) { try { if ( state == State . INITIALIZING ) { if ( rUncompressed ) { if ( ( audioRecorder . getState ( ) == AudioRecord . STATE_INITIALIZED ) & ( filePath != null ) ) { randomAccessWriter = new RandomAccessFile ( filePath , "rw" ) ; randomAccessWriter . setLength ( 0 ) ; randomAccessWriter . writeBytes ( "RIFF" ) ; randomAccessWriter . writeInt ( 0 ) ; randomAccessWriter . writeBytes ( "WAVE" ) ; randomAccessWriter . writeBytes ( "fmt " ) ; randomAccessWriter . writeInt ( Integer . reverseBytes ( 16 ) ) ; randomAccessWriter . writeShort ( Short . reverseBytes ( ( short ) 1 ) ) ; randomAccessWriter . writeShort ( Short . reverseBytes ( nChannels ) ) ; randomAccessWriter . writeInt ( Integer . reverseBytes ( sRate ) ) ; randomAccessWriter . writeInt ( Integer . reverseBytes ( sRate * bSamples * nChannels / 8 ) ) ; randomAccessWriter . writeShort ( Short . reverseBytes ( ( short ) ( nChannels * bSamples / 8 ) ) ) ; randomAccessWriter . writeShort ( Short . reverseBytes ( bSamples ) ) ; randomAccessWriter . writeBytes ( "data" ) ; randomAccessWriter . writeInt ( 0 ) ; buffer = new byte [ framePeriod * bSamples / 8 * nChannels ] ; state = State . READY ; } else { state = State . ERROR ; } } else { mediaRecorder . prepare ( ) ; state = State . READY ; } } else { release ( ) ; state = State . ERROR ; } } catch ( Exception e ) { state = State . ERROR ; } }
prepares the recorder for recording , in case the recorder is not in the initializing state and the file path was not set the recorder is set to the error state , which makes a reconstruction necessary . in case uncompressed recording is toggled , the header of the wave file is written . in case of an exception , the state is changed to error
