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

Hi
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,
          AudioFormat.CHANNEL_CONFIGURATION_MONO,
          AudioFormat.ENCODING_PCM_8BIT);
      
   

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



      short[] buffer = new short[bufferSize];
      arec.startRecording();
arec.read(buffer, 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,
            AudioTrack.MODE_STREAM);

      atrack.setPlaybackRate(sampleRate);
atrack.play();
         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.

Thanks.
sarah.kho
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Dec 20, 2010 5:31 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot] and 7 guests