Code example for AudioRecord

Methods: getAudioFormatgetChannelCountgetSampleRate

0
     * Creates PCM buffer capable to hold 5 seconds of audio. 
     * 
     * @return PCM buffer 
     */ 
    protected byte[] createPCMBuffer() { 
        int audioFormat = mAudioRecord.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT ? 16 : 8;
        return new byte[mAudioRecord.getSampleRate() * (audioFormat / 8) * mAudioRecord.getChannelCount() * 5];
    } 
 
    /** 
     * Computes minimum size of the buffer. 
     * 
     * @return minimum size of the buffer 
     */ 
    protected int getMinBufferSize() { 
        final int minBufferSize = AudioRecord.getMinBufferSize(
                mAudioRecord.getSampleRate(), mAudioRecord.getChannelConfiguration(), mAudioRecord.getAudioFormat());
        if (minBufferSize < 0) {
            throw new IllegalStateException("Invalid audio recorder - cannot compute minimum buffer size");
        } 
        return minBufferSize;