如何找出平板电脑支持的采样率? [英] How can I find out what Sampling rates are supported on my tablet?

查看:191
本文介绍了如何找出平板电脑支持的采样率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以在多种设备(Xoom,Xyboard等)上完美运行的应用程序,但在Galaxy 10.1的这一行上失败了

I have an app that works perfectly on a bunch of devices (Xoom, Xyboard, etc) but that fails at this line on the Galaxy 10.1

mrec.setAudioSamplingRate(44100);

当我对此行发表评论时,一切都会顺利进行. (我不确定默认情况下使用什么速率.)

When I comment this line out, everything works swimmingly. (I'm not sure what rate it uses by default).

我的猜测是该设备不支持该特定采样率,但是我没有在文档中看到关于我可以使用哪种对象的哪种方法来找出支持的采样率的任何信息.

My guess is that the device doesn't support this particular sample rate, but I'm not seeing anything in the docs for what method of what Object I can look to, to find out what the supported sample rates are.

感谢所有帮助.

推荐答案

是的,Android没有提供明确的方法来检查它,但是AudioRecord类可以解决此问题.

Yes, Android does not provide an explicit method to check it but there is a work-around with AudioRecord class' getMinBufferSize function.

public void getValidSampleRates() {
    for (int rate : new int[] {8000, 11025, 16000, 22050, 44100}) {  // add the rates you wish to check against
        int bufferSize = AudioRecord.getMinBufferSize(rate, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, AudioFormat.ENCODING_PCM_16BIT);
        if (bufferSize > 0) {
            // buffer size is valid, Sample rate supported

        }
    }
}

如果您选中了功能描述,如果不支持输入的参数之一,它将返回负值.假设您输入的所有其他输入均有效,那么如果不支持采样率,我们希望它返回负的缓冲区大小.

If you checked the function description, it will return a negative value if one of the parameters entered are not supported. Assuming you enter all other inputs as valid, we are expecting it to return a negative buffersize if sample rate is not supported.

但是,有些人报告说,即使不支持采样率,它也返回正值,因此可以通过尝试初始化

However, some people reported that it was returning positive even if sampling rate is not supported so an additional check could be done by trying to initialize an AudioRecord object, which will throw an IllegalArgumentException if it thinks it cannot deal with that sampling rate.

最后,它们都不提供保证的支票,但是同时使用它们会增加获得受支持的支票的机会.

Finally, none of them provide a guaranteed check but using both increases your chances of getting the supported one.

在大多数情况下,44100和48000对我有用,但是当然,这在设备之间是不同的.

Most of the time, 44100 and 48000 work for me but of course, it differs from device to device.

这篇关于如何找出平板电脑支持的采样率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆