@@ -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