简体   繁体   English

在屏幕锁定/唤醒过程中遇到Android音频卡顿

[英]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. 我正在使用远程测试服务来评估各种设备和操作系统版本上的音频播放质量,下面是一些我发现的不一致示例。

  • Samsung Galaxy S4 w/ Android 4.4 - no audio playback issues 带有Android 4.4的Samsung Galaxy S4-没有音频播放问题
  • Samsung Galaxy S4 w/ Android 4.3 - user experiences audio drop-outs/stuttering when locking/un-locking the device 带Android 4.3的Samsung Galaxy S4-锁定/解锁设备时,用户会遇到音频丢失/卡顿的情况
  • Samsung Galaxy Note 2 w/ Android 4.1.2 - no issues 带Android 4.1.2的Samsung Galaxy Note 2-没问题
  • Samsung Galaxy Note 2 w/ Android 4.3 - audio drop-outs during playback and stuttering when locking/unlocking screen. 带Android 4.3的Samsung Galaxy Note 2-锁定/解锁屏幕时播放和停顿期间音频丢失。

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: 我的问题:

  1. If I raise my base SDK to 4.2, I can detect native buffer size from the hardware and use some multiple of this during my buffer queue callbacks. 如果将基本SDK提升到4.2,则可以从硬件检测本机缓冲区大小,并在缓冲区队列回调期间使用此值的倍数。 Would this make much of a difference in cases where stuttering and drop-outs are problematic especially during screen lock? 如果在屏幕锁定期间出现结结和脱落问题的情况下,这会产生很大的不同吗?
  2. Is there a known bug with Android 4.3 where audio playback suffers, especially during screen lock actions? Android 4.3是否存在一个已知的错误,音频回放会受到影响,尤其是在屏幕锁定操作期间? Is this possibly just a Samsung issue? 这可能只是三星的问题吗?
  3. Are there other ways of improving performance to avoid this problem? 还有其他提高性能的方法可以避免此问题? I absolutely need OpenSL ES for my app. 我的应用程序绝对需要OpenSL ES。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM