How do I determine audio capabilities on Android?
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)?
精彩评论