[英]Experiencing Android Audio Stuttering during Screen Lock/Wake
I'm working on an Android app centered around audio playback and I'm experiencing some erratic behavior (audio stuttering and hiccups) that I suspect might be inherent to certain devices, OS versions or perhaps the native buffer size of the device. 我正在开发一个以音频播放为中心的Android应用程序,并且遇到了一些不稳定的行为(音频停顿和打h),我怀疑这可能是某些设备,操作系统版本或设备的本机缓冲区大小所固有的。
About my implementation - I'm in need of low latency so I'm processing my audio in OpenSL ES callbacks and using a fairly small buffer size of 128 samples to enqueue the buffers. 关于我的实现-我需要低延迟,因此我正在处理OpenSL ES回调中的音频,并使用较小的128个样本的缓冲区大小使缓冲区入队。 I am doing mp3 decoding during the callback, but with my ring buffer size, I do not need to decode during every callback cycle. 我在回调过程中正在执行mp3解码,但是由于我的环形缓冲区大小,我不需要在每个回调周期中都进行解码。
I'm using a remote testing service to gauge audio playback quality on a variety of devices and OS versions and here's a few examples of the inconsistencies I'm finding. 我正在使用远程测试服务来评估各种设备和操作系统版本上的音频播放质量,下面是一些我发现的不一致示例。
Personally, I have a Galaxy S3 w/ 4.1.2 and a Nexus 5 with 4.4 and don't ever experience these issues. 就个人而言,我有一个配备4.1.2的Galaxy S3和一个配备4.4的Nexus 5,并且从未遇到过这些问题。 I also have a few older 2.3.7 devices where these issues do not occur (2010 Droid Incredible, LG Optimus Elite). 我还拥有一些不会出现这些问题的较旧的2.3.7设备(2010 Droid Incredible,LG Optimus Elite)。
I am fairly confident that I'm not over-working the processor since I can get this running on older, Gingerbread devices just fine. 我相当有信心,我不会使处理器工作过度,因为我可以在较旧的Gingerbread设备上正常运行它。
My questions: 我的问题:
Thanks. 谢谢。
Increasing buffer size solves some problems regarding distortion and noise. 增加缓冲区大小可以解决一些有关失真和噪声的问题。 Yes, you can detect native buffer size from the hardware when your SDK is above 4.2 with this: 是的,当SDK高于4.2时,您可以通过以下方式从硬件检测本机缓冲区大小:
String size = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
But yet another approach to get the minimum buffer size for Audio Record is: 但是获取音频记录的最小缓冲区大小的另一种方法是:
int minForAudioRecord = AudioRecord.getMinBufferSize(8000,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT);
And for Audio Playback: 对于音频播放:
int minForAudioTrack = AudioTrack.getMinBufferSize(8000,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT);
If your SDK version is greater than or equal to 4.2, then you can have preferred sample rate for your audio. 如果您的SDK版本大于或等于4.2,则可以为音频设置首选的采样率。
String rate = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
I've found samsung devices are the worst while dealing with these things because each device has different approach to deal with audio drivers. 我发现处理这些问题时,三星设备最差,因为每种设备使用不同的方法来处理音频驱动程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.