Java Code Examples for android.media.AudioFormat#CHANNEL_OUT_QUAD
The following examples show how to use
android.media.AudioFormat#CHANNEL_OUT_QUAD .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaCodecBridge.java From 365browser with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private int getAudioFormat(int channelCount) { switch (channelCount) { case 1: return AudioFormat.CHANNEL_OUT_MONO; case 2: return AudioFormat.CHANNEL_OUT_STEREO; case 4: return AudioFormat.CHANNEL_OUT_QUAD; case 6: return AudioFormat.CHANNEL_OUT_5POINT1; case 8: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; } else { return AudioFormat.CHANNEL_OUT_7POINT1; } default: return AudioFormat.CHANNEL_OUT_DEFAULT; } }
Example 2
Source File: SonicAudioPlayer.java From AntennaPod-AudioPlayer with Apache License 2.0 | 6 votes |
private static int findFormatFromChannels(int numChannels) { switch (numChannels) { case 1: return AudioFormat.CHANNEL_OUT_MONO; case 2: return AudioFormat.CHANNEL_OUT_STEREO; case 3: return AudioFormat.CHANNEL_OUT_STEREO | AudioFormat.CHANNEL_OUT_FRONT_CENTER; case 4: return AudioFormat.CHANNEL_OUT_QUAD; case 5: return AudioFormat.CHANNEL_OUT_QUAD | AudioFormat.CHANNEL_OUT_FRONT_CENTER; case 6: return AudioFormat.CHANNEL_OUT_5POINT1; case 7: return AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_BACK_CENTER; case 8: if (Build.VERSION.SDK_INT >= 23) { return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; } else { return -1; } default: return -1; // Error } }
Example 3
Source File: Util.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Returns the audio track channel configuration for the given channel count, or {@link * AudioFormat#CHANNEL_INVALID} if output is not poossible. * * @param channelCount The number of channels in the input audio. * @return The channel configuration or {@link AudioFormat#CHANNEL_INVALID} if output is not * possible. */ public static int getAudioTrackChannelConfig(int channelCount) { switch (channelCount) { case 1: return AudioFormat.CHANNEL_OUT_MONO; case 2: return AudioFormat.CHANNEL_OUT_STEREO; case 3: return AudioFormat.CHANNEL_OUT_STEREO | AudioFormat.CHANNEL_OUT_FRONT_CENTER; case 4: return AudioFormat.CHANNEL_OUT_QUAD; case 5: return AudioFormat.CHANNEL_OUT_QUAD | AudioFormat.CHANNEL_OUT_FRONT_CENTER; case 6: return AudioFormat.CHANNEL_OUT_5POINT1; case 7: return AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_BACK_CENTER; case 8: if (Util.SDK_INT >= 23) { return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; } else if (Util.SDK_INT >= 21) { // Equal to AudioFormat.CHANNEL_OUT_7POINT1_SURROUND, which is hidden before Android M. return AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_SIDE_LEFT | AudioFormat.CHANNEL_OUT_SIDE_RIGHT; } else { // 8 ch output is not supported before Android L. return AudioFormat.CHANNEL_INVALID; } default: return AudioFormat.CHANNEL_INVALID; } }
Example 4
Source File: Util.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Returns the audio track channel configuration for the given channel count, or {@link * AudioFormat#CHANNEL_INVALID} if output is not poossible. * * @param channelCount The number of channels in the input audio. * @return The channel configuration or {@link AudioFormat#CHANNEL_INVALID} if output is not * possible. */ public static int getAudioTrackChannelConfig(int channelCount) { switch (channelCount) { case 1: return AudioFormat.CHANNEL_OUT_MONO; case 2: return AudioFormat.CHANNEL_OUT_STEREO; case 3: return AudioFormat.CHANNEL_OUT_STEREO | AudioFormat.CHANNEL_OUT_FRONT_CENTER; case 4: return AudioFormat.CHANNEL_OUT_QUAD; case 5: return AudioFormat.CHANNEL_OUT_QUAD | AudioFormat.CHANNEL_OUT_FRONT_CENTER; case 6: return AudioFormat.CHANNEL_OUT_5POINT1; case 7: return AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_BACK_CENTER; case 8: if (Util.SDK_INT >= 23) { return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; } else if (Util.SDK_INT >= 21) { // Equal to AudioFormat.CHANNEL_OUT_7POINT1_SURROUND, which is hidden before Android M. return AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_SIDE_LEFT | AudioFormat.CHANNEL_OUT_SIDE_RIGHT; } else { // 8 ch output is not supported before Android L. return AudioFormat.CHANNEL_INVALID; } default: return AudioFormat.CHANNEL_INVALID; } }
Example 5
Source File: Util.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Returns the audio track channel configuration for the given channel count, or {@link * AudioFormat#CHANNEL_INVALID} if output is not poossible. * * @param channelCount The number of channels in the input audio. * @return The channel configuration or {@link AudioFormat#CHANNEL_INVALID} if output is not * possible. */ public static int getAudioTrackChannelConfig(int channelCount) { switch (channelCount) { case 1: return AudioFormat.CHANNEL_OUT_MONO; case 2: return AudioFormat.CHANNEL_OUT_STEREO; case 3: return AudioFormat.CHANNEL_OUT_STEREO | AudioFormat.CHANNEL_OUT_FRONT_CENTER; case 4: return AudioFormat.CHANNEL_OUT_QUAD; case 5: return AudioFormat.CHANNEL_OUT_QUAD | AudioFormat.CHANNEL_OUT_FRONT_CENTER; case 6: return AudioFormat.CHANNEL_OUT_5POINT1; case 7: return AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_BACK_CENTER; case 8: if (Util.SDK_INT >= 23) { return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; } else if (Util.SDK_INT >= 21) { // Equal to AudioFormat.CHANNEL_OUT_7POINT1_SURROUND, which is hidden before Android M. return AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_SIDE_LEFT | AudioFormat.CHANNEL_OUT_SIDE_RIGHT; } else { // 8 ch output is not supported before Android L. return AudioFormat.CHANNEL_INVALID; } default: return AudioFormat.CHANNEL_INVALID; } }
Example 6
Source File: AudioPlayback.java From MediaPlayer-Extended with Apache License 2.0 | 4 votes |
/** * Initializes or reinitializes the audio track with the supplied format for playback * while keeping the playstate. Keeps the current configuration and skips reinitialization * if the new format is the same as the current format. */ public void init(MediaFormat format) { Log.d(TAG, "init"); boolean playing = false; if(isInitialized()) { if(!checkIfReinitializationRequired(format)) { // Set new format that equals the old one (in case we compare references somewhere) mAudioFormat = format; return; } playing = isPlaying(); pause(); stopAndRelease(false); } else { // deferred creation of the audio thread until its first use mAudioThread = new AudioThread(); mAudioThread.setPaused(true); mAudioThread.start(); } mAudioFormat = format; int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT); int bytesPerSample = 2; mFrameSize = bytesPerSample * channelCount; mSampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE); int channelConfig = AudioFormat.CHANNEL_OUT_DEFAULT; switch(channelCount) { case 1: channelConfig = AudioFormat.CHANNEL_OUT_MONO; break; case 2: channelConfig = AudioFormat.CHANNEL_OUT_STEREO; break; case 4: channelConfig = AudioFormat.CHANNEL_OUT_QUAD; break; case 6: channelConfig = AudioFormat.CHANNEL_OUT_5POINT1; break; case 8: channelConfig = AudioFormat.CHANNEL_OUT_7POINT1; } mPlaybackBufferSize = mFrameChunkSize * channelCount; mAudioTrack = new AudioTrack( mAudioStreamType, mSampleRate, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mPlaybackBufferSize, // at least twice the size to enable double buffering (according to docs) AudioTrack.MODE_STREAM, mAudioSessionId); if(mAudioTrack.getState() != AudioTrack.STATE_INITIALIZED) { stopAndRelease(); throw new IllegalStateException("audio track init failed"); } mAudioSessionId = mAudioTrack.getAudioSessionId(); mAudioStreamType = mAudioTrack.getStreamType(); setStereoVolume(mVolumeLeft, mVolumeRight); mPresentationTimeOffsetUs = PTS_NOT_SET; if(playing) { play(); } }