android audiorecord初始化失败相关资料收集

We're also struggling with audio recording on some Samsung Android Devices. Unfortunately it seems to be very broken, as even different revisions of the same phone model are behaving differently with the same codebase.

Here are my current findings, hoping you find something useful:

1. Broken Initialization:

Unfortunately, the strategy you are using to query for valid recording configurations will fail at least on Samsung Galaxy Young and Ace models running Android 2.3 The problem is that some invalid AudioRecord configurations instead of simply failing, will completely brick the audio capture subsystem if tried. You'll need to reset the phone to recover from this state.

2. Inconsistent Sampling-Rate support along revisions of same phone model

On an older Galaxy Ace Phone, recording @ 11025Hz, 16-bit mono will succeed. On newer Ace revisions, this AudioRecord configuration will be accepted as valid, but the resulting recording will be distorted, with a "chipmunk" effect. A very popular guitar tuner app that has hardcoded this sampling rate is failing to give proper tuning readings on these phones precisely because of this problem!

3. Extremely low volume audio capture on some configurations.

In Galaxy Young and Galaxy Ace, recording from the mic or default audio source @ 44,100Hz (the supposedly canonical rate where everything should work fine) produces an undistorted, but extremely low-volume recording. I haven't found yet a way to fix this other than software amplification (which is the equivalent of magnifying a very low res image, with the consecuent "jageddnes" of the result).

4. Failure to support the canonical 44,100Hz sampling rate on every audio capture source.

In Galaxy Young and Galaxy Ace, recording from the Camcorder source fails @ 44,100Hz. (again, the configuration will be accepted as valid) producing complete garbage. However, recording @ 8,000Hz, 16,000Hz and 48,000Hz works fine and produces a recording with very acceptable volume levels. What is frustrating is that according to the Android documentation, 44,100Hz is a sampling rate all devices SHOULD support.

5. OpenSL does not fix any of the problems reported.

Working with the NDK and OpenSL produces the same described results. It seems that the AudioRecorder class is simply wrapping calls to OpenSL, and the problem is either hardware based, or buried at a lower-level tier in the kernel code.

This situation is very unfortunately indeed, as these models are becoming very popular - at least in Mexico.

Good luck - and please report if you had better luck working with these phones. =)

 

 

一种通用的初始化audiorecord的方式:

private static int[] mSampleRates = new int[] { 8000, 11025, 22050, 44100 }; 

 public AudioRecord findAudioRecord() {

     for ( int rate: mSampleRates) {
         for ( short audioFormat:  new  short[] {
            AudioFormat.ENCODING_PCM_8BIT, AudioFormat.ENCODING_PCM_16BIT
        }) {
             for ( short channelConfig:  new  short[] {
                AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO
            }) {
                 try {
                    Log.i("vipul", "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: " + channelConfig);
                     int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);

                     if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {
                         //  check if we can instantiate and have a success
                        AudioRecord recorder =  new AudioRecord(
                        AudioSource.DEFAULT, rate, channelConfig, audioFormat, bufferSize);

                         if (recorder.getState() == AudioRecord.STATE_INITIALIZED)  return recorder;
                    }
                }  catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
     return  null;
}

转载于:https://www.cnblogs.com/binfenworld/p/3337027.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值