Java Code Examples for com.google.android.exoplayer2.C#ENCODING_PCM_8BIT
The following examples show how to use
com.google.android.exoplayer2.C#ENCODING_PCM_8BIT .
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: WavUtil.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** Returns the WAVE type value for the given {@code encoding}. */ public static int getTypeForEncoding(@C.PcmEncoding int encoding) { switch (encoding) { case C.ENCODING_PCM_8BIT: case C.ENCODING_PCM_16BIT: case C.ENCODING_PCM_24BIT: case C.ENCODING_PCM_32BIT: return TYPE_PCM; case C.ENCODING_PCM_A_LAW: return TYPE_A_LAW; case C.ENCODING_PCM_MU_LAW: return TYPE_MU_LAW; case C.ENCODING_PCM_FLOAT: return TYPE_FLOAT; case C.ENCODING_INVALID: case Format.NO_VALUE: default: throw new IllegalArgumentException(); } }
Example 2
Source File: Util.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Returns the frame size for audio with {@code channelCount} channels in the specified encoding. * * @param pcmEncoding The encoding of the audio data. * @param channelCount The channel count. * @return The size of one audio frame in bytes. */ public static int getPcmFrameSize(@C.PcmEncoding int pcmEncoding, int channelCount) { switch (pcmEncoding) { case C.ENCODING_PCM_8BIT: return channelCount; case C.ENCODING_PCM_16BIT: return channelCount * 2; case C.ENCODING_PCM_24BIT: return channelCount * 3; case C.ENCODING_PCM_32BIT: case C.ENCODING_PCM_FLOAT: return channelCount * 4; case C.ENCODING_PCM_A_LAW: case C.ENCODING_PCM_MU_LAW: case C.ENCODING_INVALID: case Format.NO_VALUE: default: throw new IllegalArgumentException(); } }
Example 3
Source File: Util.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Converts a sample bit depth to a corresponding PCM encoding constant. * * @param bitDepth The bit depth. Supported values are 8, 16, 24 and 32. * @return The corresponding encoding. One of {@link C#ENCODING_PCM_8BIT}, * {@link C#ENCODING_PCM_16BIT}, {@link C#ENCODING_PCM_24BIT} and * {@link C#ENCODING_PCM_32BIT}. If the bit depth is unsupported then * {@link C#ENCODING_INVALID} is returned. */ @C.PcmEncoding public static int getPcmEncoding(int bitDepth) { switch (bitDepth) { case 8: return C.ENCODING_PCM_8BIT; case 16: return C.ENCODING_PCM_16BIT; case 24: return C.ENCODING_PCM_24BIT; case 32: return C.ENCODING_PCM_32BIT; default: return C.ENCODING_INVALID; } }
Example 4
Source File: Util.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Returns the frame size for audio with {@code channelCount} channels in the specified encoding. * * @param pcmEncoding The encoding of the audio data. * @param channelCount The channel count. * @return The size of one audio frame in bytes. */ public static int getPcmFrameSize(@C.PcmEncoding int pcmEncoding, int channelCount) { switch (pcmEncoding) { case C.ENCODING_PCM_8BIT: return channelCount; case C.ENCODING_PCM_16BIT: return channelCount * 2; case C.ENCODING_PCM_24BIT: return channelCount * 3; case C.ENCODING_PCM_32BIT: case C.ENCODING_PCM_FLOAT: return channelCount * 4; case C.ENCODING_PCM_A_LAW: case C.ENCODING_PCM_MU_LAW: case C.ENCODING_INVALID: case Format.NO_VALUE: default: throw new IllegalArgumentException(); } }
Example 5
Source File: WavUtil.java From MediaSDK with Apache License 2.0 | 6 votes |
/** Returns the WAVE type value for the given {@code encoding}. */ public static int getTypeForEncoding(@C.PcmEncoding int encoding) { switch (encoding) { case C.ENCODING_PCM_8BIT: case C.ENCODING_PCM_16BIT: case C.ENCODING_PCM_24BIT: case C.ENCODING_PCM_32BIT: return TYPE_PCM; case C.ENCODING_PCM_A_LAW: return TYPE_A_LAW; case C.ENCODING_PCM_MU_LAW: return TYPE_MU_LAW; case C.ENCODING_PCM_FLOAT: return TYPE_FLOAT; case C.ENCODING_INVALID: case Format.NO_VALUE: default: throw new IllegalArgumentException(); } }
Example 6
Source File: Util.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Converts a sample bit depth to a corresponding PCM encoding constant. * * @param bitDepth The bit depth. Supported values are 8, 16, 24 and 32. * @return The corresponding encoding. One of {@link C#ENCODING_PCM_8BIT}, * {@link C#ENCODING_PCM_16BIT}, {@link C#ENCODING_PCM_24BIT} and * {@link C#ENCODING_PCM_32BIT}. If the bit depth is unsupported then * {@link C#ENCODING_INVALID} is returned. */ @C.PcmEncoding public static int getPcmEncoding(int bitDepth) { switch (bitDepth) { case 8: return C.ENCODING_PCM_8BIT; case 16: return C.ENCODING_PCM_16BIT; case 24: return C.ENCODING_PCM_24BIT; case 32: return C.ENCODING_PCM_32BIT; default: return C.ENCODING_INVALID; } }
Example 7
Source File: ResamplingAudioProcessor.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
@Override public boolean configure(int sampleRateHz, int channelCount, @C.Encoding int encoding) throws UnhandledFormatException { if (encoding != C.ENCODING_PCM_8BIT && encoding != C.ENCODING_PCM_16BIT && encoding != C.ENCODING_PCM_24BIT && encoding != C.ENCODING_PCM_32BIT) { throw new UnhandledFormatException(sampleRateHz, channelCount, encoding); } if (this.sampleRateHz == sampleRateHz && this.channelCount == channelCount && this.encoding == encoding) { return false; } this.sampleRateHz = sampleRateHz; this.channelCount = channelCount; this.encoding = encoding; return true; }
Example 8
Source File: Util.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Returns the frame size for audio with {@code channelCount} channels in the specified encoding. * * @param pcmEncoding The encoding of the audio data. * @param channelCount The channel count. * @return The size of one audio frame in bytes. */ public static int getPcmFrameSize(@C.PcmEncoding int pcmEncoding, int channelCount) { switch (pcmEncoding) { case C.ENCODING_PCM_8BIT: return channelCount; case C.ENCODING_PCM_16BIT: return channelCount * 2; case C.ENCODING_PCM_24BIT: return channelCount * 3; case C.ENCODING_PCM_32BIT: case C.ENCODING_PCM_FLOAT: return channelCount * 4; case C.ENCODING_INVALID: case Format.NO_VALUE: default: throw new IllegalArgumentException(); } }
Example 9
Source File: Util.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Converts a sample bit depth to a corresponding PCM encoding constant. * * @param bitDepth The bit depth. Supported values are 8, 16, 24 and 32. * @return The corresponding encoding. One of {@link C#ENCODING_PCM_8BIT}, * {@link C#ENCODING_PCM_16BIT}, {@link C#ENCODING_PCM_24BIT} and * {@link C#ENCODING_PCM_32BIT}. If the bit depth is unsupported then * {@link C#ENCODING_INVALID} is returned. */ @C.PcmEncoding public static int getPcmEncoding(int bitDepth) { switch (bitDepth) { case 8: return C.ENCODING_PCM_8BIT; case 16: return C.ENCODING_PCM_16BIT; case 24: return C.ENCODING_PCM_24BIT; case 32: return C.ENCODING_PCM_32BIT; default: return C.ENCODING_INVALID; } }
Example 10
Source File: Util.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Returns the frame size for audio with {@code channelCount} channels in the specified encoding. * * @param pcmEncoding The encoding of the audio data. * @param channelCount The channel count. * @return The size of one audio frame in bytes. */ public static int getPcmFrameSize(@C.PcmEncoding int pcmEncoding, int channelCount) { switch (pcmEncoding) { case C.ENCODING_PCM_8BIT: return channelCount; case C.ENCODING_PCM_16BIT: return channelCount * 2; case C.ENCODING_PCM_24BIT: return channelCount * 3; case C.ENCODING_PCM_32BIT: case C.ENCODING_PCM_FLOAT: return channelCount * 4; case C.ENCODING_INVALID: case Format.NO_VALUE: default: throw new IllegalArgumentException(); } }
Example 11
Source File: Util.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Converts a sample bit depth to a corresponding PCM encoding constant. * * @param bitDepth The bit depth. Supported values are 8, 16, 24 and 32. * @return The corresponding encoding. One of {@link C#ENCODING_PCM_8BIT}, * {@link C#ENCODING_PCM_16BIT}, {@link C#ENCODING_PCM_24BIT} and * {@link C#ENCODING_PCM_32BIT}. If the bit depth is unsupported then * {@link C#ENCODING_INVALID} is returned. */ @C.PcmEncoding public static int getPcmEncoding(int bitDepth) { switch (bitDepth) { case 8: return C.ENCODING_PCM_8BIT; case 16: return C.ENCODING_PCM_16BIT; case 24: return C.ENCODING_PCM_24BIT; case 32: return C.ENCODING_PCM_32BIT; default: return C.ENCODING_INVALID; } }
Example 12
Source File: Util.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Returns the frame size for audio with {@code channelCount} channels in the specified encoding. * * @param pcmEncoding The encoding of the audio data. * @param channelCount The channel count. * @return The size of one audio frame in bytes. */ public static int getPcmFrameSize(@C.PcmEncoding int pcmEncoding, int channelCount) { switch (pcmEncoding) { case C.ENCODING_PCM_8BIT: return channelCount; case C.ENCODING_PCM_16BIT: return channelCount * 2; case C.ENCODING_PCM_24BIT: return channelCount * 3; case C.ENCODING_PCM_32BIT: case C.ENCODING_PCM_FLOAT: return channelCount * 4; case C.ENCODING_PCM_A_LAW: case C.ENCODING_PCM_MU_LAW: case C.ENCODING_INVALID: case Format.NO_VALUE: default: throw new IllegalArgumentException(); } }
Example 13
Source File: Util.java From K-Sonic with MIT License | 5 votes |
/** * Returns the frame size for audio with {@code channelCount} channels in the specified encoding. * * @param pcmEncoding The encoding of the audio data. * @param channelCount The channel count. * @return The size of one audio frame in bytes. */ public static int getPcmFrameSize(@C.PcmEncoding int pcmEncoding, int channelCount) { switch (pcmEncoding) { case C.ENCODING_PCM_8BIT: return channelCount; case C.ENCODING_PCM_16BIT: return channelCount * 2; case C.ENCODING_PCM_24BIT: return channelCount * 3; case C.ENCODING_PCM_32BIT: return channelCount * 4; default: throw new IllegalArgumentException(); } }
Example 14
Source File: DefaultAudioSink.java From Telegram with GNU General Public License v2.0 | 5 votes |
private static int getMaximumEncodedRateBytesPerSecond(@C.Encoding int encoding) { switch (encoding) { case C.ENCODING_AC3: return 640 * 1000 / 8; case C.ENCODING_E_AC3: case C.ENCODING_E_AC3_JOC: return 6144 * 1000 / 8; case C.ENCODING_AC4: return 2688 * 1000 / 8; case C.ENCODING_DTS: // DTS allows an 'open' bitrate, but we assume the maximum listed value: 1536 kbit/s. return 1536 * 1000 / 8; case C.ENCODING_DTS_HD: return 18000 * 1000 / 8; case C.ENCODING_DOLBY_TRUEHD: return 24500 * 1000 / 8; case C.ENCODING_INVALID: case C.ENCODING_PCM_16BIT: case C.ENCODING_PCM_24BIT: case C.ENCODING_PCM_32BIT: case C.ENCODING_PCM_8BIT: case C.ENCODING_PCM_A_LAW: case C.ENCODING_PCM_FLOAT: case C.ENCODING_PCM_MU_LAW: case Format.NO_VALUE: default: throw new IllegalArgumentException(); } }
Example 15
Source File: ResamplingAudioProcessor.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public boolean configure(int sampleRateHz, int channelCount, @C.PcmEncoding int encoding) throws UnhandledFormatException { if (encoding != C.ENCODING_PCM_8BIT && encoding != C.ENCODING_PCM_16BIT && encoding != C.ENCODING_PCM_24BIT && encoding != C.ENCODING_PCM_32BIT) { throw new UnhandledFormatException(sampleRateHz, channelCount, encoding); } return setInputFormat(sampleRateHz, channelCount, encoding); }
Example 16
Source File: Util.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Returns whether {@code encoding} is one of the linear PCM encodings. * * @param encoding The encoding of the audio data. * @return Whether the encoding is one of the PCM encodings. */ public static boolean isEncodingLinearPcm(@C.Encoding int encoding) { return encoding == C.ENCODING_PCM_8BIT || encoding == C.ENCODING_PCM_16BIT || encoding == C.ENCODING_PCM_24BIT || encoding == C.ENCODING_PCM_32BIT || encoding == C.ENCODING_PCM_FLOAT; }
Example 17
Source File: ResamplingAudioProcessor.java From MediaSDK with Apache License 2.0 | 5 votes |
@Override public AudioFormat onConfigure(AudioFormat inputAudioFormat) throws UnhandledAudioFormatException { @C.PcmEncoding int encoding = inputAudioFormat.encoding; if (encoding != C.ENCODING_PCM_8BIT && encoding != C.ENCODING_PCM_16BIT && encoding != C.ENCODING_PCM_24BIT && encoding != C.ENCODING_PCM_32BIT) { throw new UnhandledAudioFormatException(inputAudioFormat); } return encoding != C.ENCODING_PCM_16BIT ? new AudioFormat( inputAudioFormat.sampleRate, inputAudioFormat.channelCount, C.ENCODING_PCM_16BIT) : AudioFormat.NOT_SET; }
Example 18
Source File: Util.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Returns whether {@code encoding} is one of the linear PCM encodings. * * @param encoding The encoding of the audio data. * @return Whether the encoding is one of the PCM encodings. */ public static boolean isEncodingLinearPcm(@C.Encoding int encoding) { return encoding == C.ENCODING_PCM_8BIT || encoding == C.ENCODING_PCM_16BIT || encoding == C.ENCODING_PCM_24BIT || encoding == C.ENCODING_PCM_32BIT || encoding == C.ENCODING_PCM_FLOAT; }
Example 19
Source File: ResamplingAudioProcessor.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void queueInput(ByteBuffer inputBuffer) { // Prepare the output buffer. int position = inputBuffer.position(); int limit = inputBuffer.limit(); int size = limit - position; int resampledSize; switch (encoding) { case C.ENCODING_PCM_8BIT: resampledSize = size * 2; break; case C.ENCODING_PCM_24BIT: resampledSize = (size / 3) * 2; break; case C.ENCODING_PCM_32BIT: resampledSize = size / 2; break; case C.ENCODING_PCM_16BIT: case C.ENCODING_PCM_FLOAT: case C.ENCODING_INVALID: case Format.NO_VALUE: default: throw new IllegalStateException(); } if (buffer.capacity() < resampledSize) { buffer = ByteBuffer.allocateDirect(resampledSize).order(ByteOrder.nativeOrder()); } else { buffer.clear(); } // Resample the little endian input and update the input/output buffers. switch (encoding) { case C.ENCODING_PCM_8BIT: // 8->16 bit resampling. Shift each byte from [0, 256) to [-128, 128) and scale up. for (int i = position; i < limit; i++) { buffer.put((byte) 0); buffer.put((byte) ((inputBuffer.get(i) & 0xFF) - 128)); } break; case C.ENCODING_PCM_24BIT: // 24->16 bit resampling. Drop the least significant byte. for (int i = position; i < limit; i += 3) { buffer.put(inputBuffer.get(i + 1)); buffer.put(inputBuffer.get(i + 2)); } break; case C.ENCODING_PCM_32BIT: // 32->16 bit resampling. Drop the two least significant bytes. for (int i = position; i < limit; i += 4) { buffer.put(inputBuffer.get(i + 2)); buffer.put(inputBuffer.get(i + 3)); } break; case C.ENCODING_PCM_16BIT: case C.ENCODING_PCM_FLOAT: case C.ENCODING_INVALID: case Format.NO_VALUE: default: // Never happens. throw new IllegalStateException(); } inputBuffer.position(inputBuffer.limit()); buffer.flip(); outputBuffer = buffer; }
Example 20
Source File: ResamplingAudioProcessor.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override public void queueInput(ByteBuffer inputBuffer) { // Prepare the output buffer. int position = inputBuffer.position(); int limit = inputBuffer.limit(); int size = limit - position; int resampledSize; switch (encoding) { case C.ENCODING_PCM_8BIT: resampledSize = size * 2; break; case C.ENCODING_PCM_24BIT: resampledSize = (size / 3) * 2; break; case C.ENCODING_PCM_32BIT: resampledSize = size / 2; break; case C.ENCODING_PCM_16BIT: case C.ENCODING_PCM_FLOAT: case C.ENCODING_PCM_A_LAW: case C.ENCODING_PCM_MU_LAW: case C.ENCODING_INVALID: case Format.NO_VALUE: default: throw new IllegalStateException(); } // Resample the little endian input and update the input/output buffers. ByteBuffer buffer = replaceOutputBuffer(resampledSize); switch (encoding) { case C.ENCODING_PCM_8BIT: // 8->16 bit resampling. Shift each byte from [0, 256) to [-128, 128) and scale up. for (int i = position; i < limit; i++) { buffer.put((byte) 0); buffer.put((byte) ((inputBuffer.get(i) & 0xFF) - 128)); } break; case C.ENCODING_PCM_24BIT: // 24->16 bit resampling. Drop the least significant byte. for (int i = position; i < limit; i += 3) { buffer.put(inputBuffer.get(i + 1)); buffer.put(inputBuffer.get(i + 2)); } break; case C.ENCODING_PCM_32BIT: // 32->16 bit resampling. Drop the two least significant bytes. for (int i = position; i < limit; i += 4) { buffer.put(inputBuffer.get(i + 2)); buffer.put(inputBuffer.get(i + 3)); } break; case C.ENCODING_PCM_16BIT: case C.ENCODING_PCM_FLOAT: case C.ENCODING_PCM_A_LAW: case C.ENCODING_PCM_MU_LAW: case C.ENCODING_INVALID: case Format.NO_VALUE: default: // Never happens. throw new IllegalStateException(); } inputBuffer.position(inputBuffer.limit()); buffer.flip(); }