app/src/main/java/org/sil/hearthis/WavAudioRecorder.java
//	periodic updates on the progress of the record head
periodic updates on the progress of the record head
periodic updates on the progress of the record head
public void onPeriodicNotification(AudioRecord recorder) {
			if (State.ERROR == state)
				return;
			if (State.STOPPED == state) {
				Log.d(WavAudioRecorder.this.getClass().getName(), "recorder stopped");
				return;
			}
			int numOfBytes = audioRecorder.read(buffer, 0, buffer.length); 
			if (monitorListener != null) {
				short maxAmp = 0;
				for (int i = 0; i < numOfBytes / 2; i++) {
					short current = (short) Math.abs((short) (buffer[i * 2 + 1] << 8 | buffer[i * 2]));
					if (current > maxAmp) maxAmp = current;
				}
				monitorListener.maxLevel(maxAmp);
			}
			if (state.RECORDING != state) {
				return;
			}
			try { 
				randomAccessWriter.write(buffer); 		  
				payloadSize += buffer.length;
			} catch (IOException e) {
				Log.e(WavAudioRecorder.class.getName(), "Error occured in updateListener, recording is aborted");
				e.printStackTrace();
			}
		}
public void onPeriodicNotification ( AudioRecord recorder ) { if ( State . ERROR == state ) return ; if ( State . STOPPED == state ) { Log . d ( WavAudioRecorder . this . getClass ( ) . getName ( ) , "recorder stopped" ) ; return ; } int numOfBytes = audioRecorder . read ( buffer , 0 , buffer . length ) ; if ( monitorListener != null ) { short maxAmp = 0 ; for ( int i = 0 ; i < numOfBytes / 2 ; i ++ ) { short current = ( short ) Math . abs ( ( short ) ( buffer [ i * 2 + 1 ] << 8 | buffer [ i * 2 ] ) ) ; if ( current > maxAmp ) maxAmp = current ; } monitorListener . maxLevel ( maxAmp ) ; } if ( state . RECORDING != state ) { return ; } try { randomAccessWriter . write ( buffer ) ; payloadSize += buffer . length ; } catch ( IOException e ) { Log . e ( WavAudioRecorder . class . getName ( ) , "Error occured in updateListener, recording is aborted" ) ; e . printStackTrace ( ) ; } }
periodic updates on the progress of the record head
periodic updates on the progress of the record head
// read audio data to buffer //			Log.d(WavAudioRecorder.this.getClass().getName(), state + ":" + numOfBytes); // I'm using 16-bit mono, so buffer contains 2-byte little-endian samples.  (Enhance: eventually consider handling other modes). // Find largest amplitude. //  Report it to the app. // write audio data to file