tags:

views:

261

answers:

1

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?

+1  A: 

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

Marc Bernstein
Hi Marc - yes, I've seen that and it's one piece of the puzzle, but I'm hoping for something more comprehensive (and includes input settings too).
Seth
Bummer. Seems like looping through the possible parameters might be the only way possible currently. See http://bit.ly/c3BieY for another developer's work on this. I agree this is not very optimal, a getCapabilities() function would be nice to have.
Marc Bernstein