Skip to content

Commit 1b8f499

Browse files
committed
Allow multichannel configurations in android.media.AudioTrack
Compare the channel configuration against a mask of the public channel masks in AudioFormat for up to 5.1 with back channels, and allow combinations within this mask. Change-Id: I84b72dfd88d4490f0c67bf10d13151a9eb06f6a8
1 parent 7725180 commit 1b8f499

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

media/java/android/media/AudioTrack.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ public AudioTrack(int streamType, int sampleRateInHz, int channelConfig, int aud
340340
}
341341
}
342342

343+
// mask of all the channels supported by this implementation
344+
private static final int SUPPORTED_OUT_CHANNELS =
345+
AudioFormat.CHANNEL_OUT_FRONT_LEFT |
346+
AudioFormat.CHANNEL_OUT_FRONT_RIGHT |
347+
AudioFormat.CHANNEL_OUT_FRONT_CENTER |
348+
AudioFormat.CHANNEL_OUT_LOW_FREQUENCY |
349+
AudioFormat.CHANNEL_OUT_BACK_LEFT |
350+
AudioFormat.CHANNEL_OUT_BACK_RIGHT |
351+
AudioFormat.CHANNEL_OUT_BACK_CENTER;
343352

344353
// Convenience method for the constructor's parameter checks.
345354
// This is where constructor IllegalArgumentException-s are thrown
@@ -392,10 +401,16 @@ private void audioParamCheck(int streamType, int sampleRateInHz,
392401
mChannels = AudioFormat.CHANNEL_OUT_STEREO;
393402
break;
394403
default:
395-
mChannelCount = 0;
396-
mChannels = AudioFormat.CHANNEL_INVALID;
397-
mChannelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_INVALID;
398-
throw(new IllegalArgumentException("Unsupported channel configuration."));
404+
if ((channelConfig & SUPPORTED_OUT_CHANNELS) != channelConfig) {
405+
// input channel configuration features unsupported channels
406+
mChannelCount = 0;
407+
mChannels = AudioFormat.CHANNEL_INVALID;
408+
mChannelConfiguration = AudioFormat.CHANNEL_INVALID;
409+
throw(new IllegalArgumentException("Unsupported channel configuration."));
410+
} else {
411+
mChannels = channelConfig;
412+
mChannelCount = Integer.bitCount(channelConfig);
413+
}
399414
}
400415

401416
//--------------
@@ -623,8 +638,13 @@ static public int getMinBufferSize(int sampleRateInHz, int channelConfig, int au
623638
channelCount = 2;
624639
break;
625640
default:
626-
loge("getMinBufferSize(): Invalid channel configuration.");
627-
return AudioTrack.ERROR_BAD_VALUE;
641+
if ((channelConfig & SUPPORTED_OUT_CHANNELS) != channelConfig) {
642+
// input channel configuration features unsupported channels
643+
loge("getMinBufferSize(): Invalid channel configuration.");
644+
return AudioTrack.ERROR_BAD_VALUE;
645+
} else {
646+
channelCount = Integer.bitCount(channelConfig);
647+
}
628648
}
629649

630650
if ((audioFormat != AudioFormat.ENCODING_PCM_16BIT)

0 commit comments

Comments
 (0)