3

In my application i'm using media recorder for audio recording. I want to use different bit rates 32,64,128,160 etc.

recorder = new MediaRecorder();
    /******Audio Source******/
    try{
        if(audio_source.equals("Camcorder"))
            recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        else if(audio_source.equals("MIC"))
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        else recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    }
    catch(Exception e){
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    }



    /******Audio Channel******/
    try{
        if(audio_channel.equalsIgnoreCase("mono")){
            recorder.setAudioChannels(1);
        }
        else if(audio_channel.equalsIgnoreCase("stereo")){
            recorder.setAudioChannels(2);
        }
    }
    catch(Exception e){
        recorder.setAudioChannels(1);
    }

    System.out.println(" bitrate -- "+bit_rate);

    if (Build.VERSION.SDK_INT >= 10) {
        recorder.setAudioSamplingRate(44100);//44100

    }
    else{
        recorder.setAudioSamplingRate(8000);//44100

    }
    /******AudioEncodingBitRate******/
    try{
        System.out.println(" in try ..."+bit_rate);
        if(bit_rate.equalsIgnoreCase("32")){
            recorder.setAudioEncodingBitRate(32000);
        }
        else if(bit_rate.equalsIgnoreCase("64")){
            recorder.setAudioEncodingBitRate(64000);
        }
        else if(bit_rate.equalsIgnoreCase("96")){
            recorder.setAudioEncodingBitRate(96000);
        }
        else if(bit_rate.equalsIgnoreCase("128")){
            recorder.setAudioEncodingBitRate(128000);
        }
        else if(bit_rate.equalsIgnoreCase("160")){
            recorder.setAudioEncodingBitRate(160000);
        }
    }
    catch(Exception e){
        recorder.setAudioEncodingBitRate(64);
    }
    /******File Format******/
    //recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    if(format.equals(".mp4"))
    {
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    }
    else
    {
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    }

    if (Build.VERSION.SDK_INT >= 10) {
        recorder.setAudioSamplingRate(44100);//44100
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); 
    }
    else{
        recorder.setAudioSamplingRate(8000);//44100
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    }

    recorder.setOutputFile(audiofile.getAbsolutePath()); 
    recorder.prepare();

But I didn't get any change for quality using all above different bit rate conditions. How can I use it?

yuva ツ
  • 3,707
  • 9
  • 50
  • 78
  • MPEG4 is the _container_ format. It doesn't look like you've specified which _encoder_ to use (`setAudioEncoder`). There's a reasonable probability that the default encoder is AMR_NB, which has a very low maximum bitrate and a fixed sampling rate. – Michael Apr 24 '14 at 11:52
  • I have use it. AMR_NB.see updated code – yuva ツ Apr 24 '14 at 11:53
  • In that case, see the second part of my previous comment. If you want better quality recordings, specify a different encoder, like AAC. – Michael Apr 24 '14 at 11:56
  • But I want bit rate wise quality.i'm providing options for bit rate like 32,64,128 ... – yuva ツ Apr 24 '14 at 11:58
  • AMR_NB has a maximum bitrate of 12.2 kbit/s, and a fixed sampling rate (8000 Hz). Again; if you expect something with decent quality, use a different encoder. – Michael Apr 24 '14 at 12:03
  • @Michael see my updated code.now it records only for 3 to 4 seconds. – yuva ツ Apr 24 '14 at 12:31

1 Answers1

5

According to the documentation the bitrate is set in bits per second and

Prepare() may perform additional checks on the parameter to make sure whether the specified bit rate is applicable, and sometimes the passed bitRate will be clipped internally to ensure the audio recording can proceed smoothly based on the capabilities of the platform.

I assume, that clipping happened in this case since even 160 bits per second is ridiculously low.

Henry
  • 42,982
  • 7
  • 68
  • 84