Anyone able to use ENCODING_PCM_8BIT in recording and playin

All your problems with Audio, Video and Images.

Anyone able to use ENCODING_PCM_8BIT in recording and playin

Postby sarah.kho » Mon Dec 20, 2010 5:34 pm

I am trying to use AudioFormat.ENCODING_PCM_8BIT with AudioRecord and AudioTrack to record some voice from mic and then play it to the speaker.

Here is my code:

Code: Select all

int   sampleRate = 11025;
      int   bufferSize = AudioRecord.getMinBufferSize(11025*2,

      AudioRecord arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
            sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO,
            AudioFormat.ENCODING_PCM_8BIT, bufferSize);

      short[] buffer = new short[bufferSize];
      arec.startRecording();, 0, bufferSize);

and here is the code portion for playing the content from the buffer

Code: Select all
      AudioTrack atrack = new AudioTrack(AudioManager.STREAM_MUSIC,
            sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO,
            AudioFormat.ENCODING_PCM_8BIT, bufferSize,

         atrack.write(buffer, 0, buffer.length);

The error I get is an IllegalArgumentException in the line where I am initializing the arec object. Any idea why it is happening?

The same code works fine with ENCODING_PCM_16BIT and I do not know what is wrong with it. I tried using byte[] with no luck.

Once Poster
Once Poster
Posts: 1
Joined: Mon Dec 20, 2010 5:31 pm


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 8 guests