Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine audio capabilities on Android?

Tags:

android

audio

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,
    AudioFormat.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?

like image 267
Seth Avatar asked Mar 10 '10 21:03

Seth


1 Answers

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

like image 105
Marc Bernstein Avatar answered Sep 19 '22 11:09

Marc Bernstein