app/src/main/java/org/sil/hearthis/WavAudioRecorder.java
/**
	 * 
	* 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
	* 	 
	*/
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
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
public void prepare() {
		try {
			if (state == State.INITIALIZING) {
				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*nChannels*mBitsPersample/8)); 
					randomAccessWriter.writeShort(Short.reverseBytes((short)(nChannels*mBitsPersample/8))); 
					randomAccessWriter.writeShort(Short.reverseBytes(mBitsPersample)); 
					randomAccessWriter.writeBytes("data");
					randomAccessWriter.writeInt(0); 
					buffer = new byte[mPeriodInFrames*mBitsPersample/8*nChannels];
					state = State.READY;
				} else {
					Log.e(WavAudioRecorder.class.getName(), "prepare() method called on uninitialized recorder");
					state = State.ERROR;
				}
			} else {
				Log.e(WavAudioRecorder.class.getName(), "prepare() method called on illegal state");
				release();
				state = State.ERROR;
			}
		} catch(Exception e) {
			if (e.getMessage() != null) {
				Log.e(WavAudioRecorder.class.getName(), e.getMessage());
			} else {
				Log.e(WavAudioRecorder.class.getName(), "Unknown error occured in prepare()");
			}
			state = State.ERROR;
		}
	}
public void prepare ( ) { try { if ( state == State . INITIALIZING ) { 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 * nChannels * mBitsPersample / 8 ) ) ; randomAccessWriter . writeShort ( Short . reverseBytes ( ( short ) ( nChannels * mBitsPersample / 8 ) ) ) ; randomAccessWriter . writeShort ( Short . reverseBytes ( mBitsPersample ) ) ; randomAccessWriter . writeBytes ( "data" ) ; randomAccessWriter . writeInt ( 0 ) ; buffer = new byte [ mPeriodInFrames * mBitsPersample / 8 * nChannels ] ; state = State . READY ; } else { Log . e ( WavAudioRecorder . class . getName ( ) , "prepare() method called on uninitialized recorder" ) ; state = State . ERROR ; } } else { Log . e ( WavAudioRecorder . class . getName ( ) , "prepare() method called on illegal state" ) ; release ( ) ; state = State . ERROR ; } } catch ( Exception e ) { if ( e . getMessage ( ) != null ) { Log . e ( WavAudioRecorder . class . getName ( ) , e . getMessage ( ) ) ; } else { Log . e ( WavAudioRecorder . class . getName ( ) , "Unknown error occured in prepare()" ) ; } 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.
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 .
// write file header // Set file length to 0, to prevent unexpected behavior in case the file already existed // Final file size not known yet, write 0  // Sub-chunk size, 16 for PCM // AudioFormat, 1 for PCM // Number of channels, 1 for mono, 2 for stereo // Sample rate // Byte rate, SampleRate*NumberOfChannels*mBitsPersample/8 // Block align, NumberOfChannels*mBitsPersample/8 // Bits per sample // Data chunk size not known yet, write 0