Skip to content

Instantly share code, notes, and snippets.

@intervigilium
Created September 23, 2010 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intervigilium/593200 to your computer and use it in GitHub Desktop.
Save intervigilium/593200 to your computer and use it in GitHub Desktop.
Android audio format autodetection code
do {
switch (sampleRate) {
case -1:
sampleRate = Constants.SAMPLE_RATE_22KHZ;
break;
case Constants.SAMPLE_RATE_44KHZ:
sampleRate = Constants.SAMPLE_RATE_22KHZ;
break;
case Constants.SAMPLE_RATE_22KHZ:
sampleRate = Constants.SAMPLE_RATE_11KHZ;
break;
case Constants.SAMPLE_RATE_11KHZ:
sampleRate = Constants.SAMPLE_RATE_8KHZ;
break;
default:
Log.w("AudioHelper", String.format("Hardware does not support recording!"));
DialogHelper.showWarning(context, R.string.unable_to_configure_audio_title, R.string.unable_to_configure_audio_warning);
return;
}
bufferSize = AudioRecord.getMinBufferSize(
sampleRate,
Constants.DEFAULT_CHANNEL_CONFIG,
Constants.DEFAULT_PCM_FORMAT);
} while (bufferSize == AudioRecord.ERROR_BAD_VALUE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment