开发者

How do I determine audio capabilities on Android?

开发者 https://www.devze.com 2022-12-23 00:43 出处:网络
I\'m experimenting with Android\'s audio recording and playback. Is there a way to enumerate the available audio parameters on my device?

I'm experimenting with Android's audio recording and playback. Is there a way to enumerate the available audio parameters on my device?

Right now, when I pass a combination of parameters that the hardware (or emulator) doesn't like, I just get an error. So I am having to "guess":

int bufferSize; 
int sampleRate;

// does the audio hardware do 44 kHz? 
sampleRate = 44100;
bufferSize = AudioRecord.getMinBufferSize(sampleRate, 
    AudioFormat.CHANNEL_CONFIGURATION_MONO,
    AudioFor开发者_Go百科mat.ENCODING_PCM_16BIT);

if (bufferSize != AudioTrack.ERROR_BAD_VALUE) {
    // Nope, how about 22 kHz? 
    sampleRate = 22050;
}

bufferSize = AudioRecord.getMinBufferSize(sampleRate, 
    AudioFormat.CHANNEL_CONFIGURATION_MONO,
    AudioFormat.ENCODING_PCM_16BIT);

if (bufferSize != AudioTrack.ERROR_BAD_VALUE) { 
    ...

Surely there's a better way!


This chart indicates that the only supported audio input sampling rate is 8 kHz? Is that correct?


Have you already looked at AudioTrack.getNativeOutputSampleRate(int streamType)?

0

精彩评论

暂无评论...
验证码 换一张
取 消