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;}

最新文章

  1. mac好用的markdown编辑器
  2. Spring概念
  3. Mac系统如何编辑hosts文件
  4. linux常见问题集锦-1
  5. php大力力 [014节] 八杆子打不着的非技术文章,哈哈
  6. cocos2d-x 中 TTF 字体文件的位置
  7. solr英文使用的基本分词器和过滤器配置
  8. leetcode@ [139/140] Word Break & Word Break II
  9. 宿舍局域网与Internet连接
  10. ExtJs 第二章,Ext.form.Basic表单操作
  11. easyUI的datagrid控件日期列不能正确显示Json格式数据的解决方案
  12. centos6.4 ceph安装部署之cephFS
  13. Openjudge-NOI题库-简单算术表达式求值
  14. 前端笔记之JavaScript面向对象(四)组件化开发&轮播图|俄罗斯方块实战
  15. ios View 向上拉界面源码
  16. Tomcat系列(11)——Tomcat 部署web应用的4种方法
  17. Python下用Scrapy和MongoDB构建爬虫系统(1)
  18. Java11实战:模块化的 Netty RPC 服务项目
  19. [日常] Go语言圣经--并发的web爬虫
  20. BZOJ.3143.[HNOI2013]游走(概率 期望 高斯消元)

热门文章

  1. 力扣---213. 打家劫舍 II
  2. .NET Core项目部署到Windows系统Docker
  3. Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 1x.x
  4. qt元对象系统之 Q_PROPERTY宏
  5. 关于vue项目和内嵌iframe页面之间的通信问题
  6. 有趣的python库-pyttsx3
  7. JZOJ 2020.02.16【NOIP提高组】模拟A 组
  8. WHAT IS PPM Encoder ?
  9. VSCode 自定义代码片段
  10. vue2+ts 设计一个扑克牌比大小的游戏