javaandroidaudioaudiorecord

Why am I getting IllegalArgumentException: Unsupported channel configuration?


I'm using AudioRecord to collect audio data from a headphone jack on Android like so:

int frequency = 44100;
int channelConfiguration = AudioFormat.CHANNEL_OUT_MONO;
int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;

int bufferSize = AudioRecord.getMinBufferSize(frequency, channelConfiguration, audioEncoding);
AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, frequency, channelConfiguration, audioEncoding, bufferSize);
audioRecord.startRecording();

However, I get an error that says

java.lang.IllegalArgumentException: Unsupported channel configuration.

I haven't found anything helpful online, so I was wondering if anyone else had this issue.


Solution

  • I don't know if this is what CaseyB meant, but I changed AudioFormat.CHANNEL_OUT_MONO to AudioFormat.CHANNEL_IN_MONO. This made the error go away.