Code example for AudioRecord

Methods: getAudioFormatgetChannelCountgetSampleRate

0
//		long chunkSize = 2; 
//		long subChunk1Size = 16; 
//		int blockAlign = 2; 
 
		int audioFormat = 1;
		int sampleRate = recorder.getSampleRate();
		int bitsPerSample = (recorder.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT ? 16 : 8);
		int channels = recorder.getChannelCount();
		long chunkSize = 36 + subChunk2Size;
		long subChunk1Size = 16;
		int blockAlign = channels * bitsPerSample / 8;   // == NumChannels * BitsPerSample/8
		int byteRate = sampleRate * channels * bitsPerSample / 8;  // == SampleRate * NumChannels * BitsPerSample/8
		 
		try { 
			fos.write(RIFF_HEADER.getBytes());
			// little endian 
			fos.write(new byte[] { (byte) (chunkSize), (byte) (chunkSize >> 8),
					(byte) (chunkSize >> 16), (byte) (chunkSize >> 24) });
			fos.write(WAVE_HEADER.getBytes());
			fos.write(FMT_HEADER.getBytes());
			fos.write(new byte[] { (byte) (subChunk1Size),