Java Code Examples for com.google.android.exoplayer2.C#ENCODING_PCM_MU_LAW

The following examples show how to use com.google.android.exoplayer2.C#ENCODING_PCM_MU_LAW . 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: Util.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 2
Source File: WavUtil.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/** 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 3
Source File: Util.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 4
Source File: WavUtil.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/** Returns the PCM encoding for the given WAVE {@code type} value. */
public static @C.PcmEncoding int getEncodingForType(int type, int bitsPerSample) {
  switch (type) {
    case TYPE_PCM:
    case TYPE_WAVE_FORMAT_EXTENSIBLE:
      return Util.getPcmEncoding(bitsPerSample);
    case TYPE_FLOAT:
      return bitsPerSample == 32 ? C.ENCODING_PCM_FLOAT : C.ENCODING_INVALID;
    case TYPE_A_LAW:
      return C.ENCODING_PCM_A_LAW;
    case TYPE_MU_LAW:
      return C.ENCODING_PCM_MU_LAW;
    default:
      return C.ENCODING_INVALID;
  }
}
 
Example 5
Source File: WavUtil.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/** 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 MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * 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 7
Source File: WavUtil.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/** Returns the PCM encoding for the given WAVE {@code type} value. */
public static @C.PcmEncoding int getEncodingForType(int type, int bitsPerSample) {
  switch (type) {
    case TYPE_PCM:
    case TYPE_WAVE_FORMAT_EXTENSIBLE:
      return Util.getPcmEncoding(bitsPerSample);
    case TYPE_FLOAT:
      return bitsPerSample == 32 ? C.ENCODING_PCM_FLOAT : C.ENCODING_INVALID;
    case TYPE_A_LAW:
      return C.ENCODING_PCM_A_LAW;
    case TYPE_MU_LAW:
      return C.ENCODING_PCM_MU_LAW;
    default:
      return C.ENCODING_INVALID;
  }
}
 
Example 8
Source File: WavUtil.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/** 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 9
Source File: DefaultAudioSink.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
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 10
Source File: DefaultAudioSink.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
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 11
Source File: DefaultAudioSink.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
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 12
Source File: WavHeaderReader.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Peeks and returns a {@code WavHeader}.
 *
 * @param input Input stream to peek the WAV header from.
 * @throws ParserException If the input file is an incorrect RIFF WAV.
 * @throws IOException If peeking from the input fails.
 * @throws InterruptedException If interrupted while peeking from input.
 * @return A new {@code WavHeader} peeked from {@code input}, or null if the input is not a
 *     supported WAV format.
 */
public static WavHeader peek(ExtractorInput input) throws IOException, InterruptedException {
  Assertions.checkNotNull(input);

  // Allocate a scratch buffer large enough to store the format chunk.
  ParsableByteArray scratch = new ParsableByteArray(16);

  // Attempt to read the RIFF chunk.
  ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
  if (chunkHeader.id != Util.getIntegerCodeForString("RIFF")) {
    return null;
  }

  input.peekFully(scratch.data, 0, 4);
  scratch.setPosition(0);
  int riffFormat = scratch.readInt();
  if (riffFormat != Util.getIntegerCodeForString("WAVE")) {
    Log.e(TAG, "Unsupported RIFF format: " + riffFormat);
    return null;
  }

  // Skip chunks until we find the format chunk.
  chunkHeader = ChunkHeader.peek(input, scratch);
  while (chunkHeader.id != Util.getIntegerCodeForString("fmt ")) {
    input.advancePeekPosition((int) chunkHeader.size);
    chunkHeader = ChunkHeader.peek(input, scratch);
  }

  Assertions.checkState(chunkHeader.size >= 16);
  input.peekFully(scratch.data, 0, 16);
  scratch.setPosition(0);
  int type = scratch.readLittleEndianUnsignedShort();
  int numChannels = scratch.readLittleEndianUnsignedShort();
  int sampleRateHz = scratch.readLittleEndianUnsignedIntToInt();
  int averageBytesPerSecond = scratch.readLittleEndianUnsignedIntToInt();
  int blockAlignment = scratch.readLittleEndianUnsignedShort();
  int bitsPerSample = scratch.readLittleEndianUnsignedShort();

  int expectedBlockAlignment = numChannels * bitsPerSample / 8;
  if (blockAlignment != expectedBlockAlignment) {
    throw new ParserException("Expected block alignment: " + expectedBlockAlignment + "; got: "
        + blockAlignment);
  }

  @C.PcmEncoding int encoding;
  switch (type) {
    case TYPE_PCM:
    case TYPE_WAVE_FORMAT_EXTENSIBLE:
      encoding = Util.getPcmEncoding(bitsPerSample);
      break;
    case TYPE_FLOAT:
      encoding = bitsPerSample == 32 ? C.ENCODING_PCM_FLOAT : C.ENCODING_INVALID;
      break;
    case TYPE_A_LAW:
      encoding = C.ENCODING_PCM_A_LAW;
      break;
    case TYPE_MU_LAW:
      encoding = C.ENCODING_PCM_MU_LAW;
      break;
    default:
      Log.e(TAG, "Unsupported WAV format type: " + type);
      return null;
  }

  if (encoding == C.ENCODING_INVALID) {
    Log.e(TAG, "Unsupported WAV bit depth " + bitsPerSample + " for type " + type);
    return null;
  }

  // If present, skip extensionSize, validBitsPerSample, channelMask, subFormatGuid, ...
  input.advancePeekPosition((int) chunkHeader.size - 16);

  return new WavHeader(numChannels, sampleRateHz, averageBytesPerSecond, blockAlignment,
      bitsPerSample, encoding);
}
 
Example 13
Source File: FfmpegLibrary.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the name of the FFmpeg decoder that could be used to decode the format, or {@code null}
 * if it's unsupported.
 */
/* package */ static @Nullable String getCodecName(String mimeType, @C.PcmEncoding int encoding) {
  switch (mimeType) {
    case MimeTypes.AUDIO_AAC:
      return "aac";
    case MimeTypes.AUDIO_MPEG:
    case MimeTypes.AUDIO_MPEG_L1:
    case MimeTypes.AUDIO_MPEG_L2:
      return "mp3";
    case MimeTypes.AUDIO_AC3:
      return "ac3";
    case MimeTypes.AUDIO_E_AC3:
      return "eac3";
    case MimeTypes.AUDIO_TRUEHD:
      return "truehd";
    case MimeTypes.AUDIO_DTS:
    case MimeTypes.AUDIO_DTS_HD:
      return "dca";
    case MimeTypes.AUDIO_VORBIS:
      return "vorbis";
    case MimeTypes.AUDIO_OPUS:
      return "opus";
    case MimeTypes.AUDIO_AMR_NB:
      return "amrnb";
    case MimeTypes.AUDIO_AMR_WB:
      return "amrwb";
    case MimeTypes.AUDIO_FLAC:
      return "flac";
    case MimeTypes.AUDIO_ALAC:
      return "alac";
    case MimeTypes.AUDIO_RAW:
      if (encoding == C.ENCODING_PCM_MU_LAW) {
        return "pcm_mulaw";
      } else if (encoding == C.ENCODING_PCM_A_LAW) {
        return "pcm_alaw";
      } else {
        return null;
      }
    default:
      return null;
  }
}
 
Example 14
Source File: AudioDecoder.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
/**
  * Returns the name of the FFmpeg decoder that could be used to decode the format, or {@code null}
  * if it's unsupported.
  */
private static @Nullable
String getCodecName(String mimeType, @C.PcmEncoding int encoding) {
   switch (mimeType) {
     case MimeTypes.AUDIO_AAC:
       return "aac";
     case MimeTypes.AUDIO_MPEG:
     case MimeTypes.AUDIO_MPEG_L1:
     case MimeTypes.AUDIO_MPEG_L2:
       return "mp3";
     case MimeTypes.AUDIO_AC3:
       return "ac3";
     case MimeTypes.AUDIO_E_AC3:
     case MimeTypes.AUDIO_E_AC3_JOC:
       return "eac3";
     case MimeTypes.AUDIO_TRUEHD:
       return "truehd";
     case MimeTypes.AUDIO_DTS:
     case MimeTypes.AUDIO_DTS_HD:
       return "dca";
     case MimeTypes.AUDIO_VORBIS:
       return "vorbis";
     case MimeTypes.AUDIO_OPUS:
       return "opus";
     case MimeTypes.AUDIO_AMR_NB:
       return "amrnb";
     case MimeTypes.AUDIO_AMR_WB:
       return "amrwb";
     case MimeTypes.AUDIO_FLAC:
       return "flac";
     case MimeTypes.AUDIO_ALAC:
       return "alac";
     case MimeTypes.AUDIO_RAW:
       if (encoding == C.ENCODING_PCM_MU_LAW) {
         return "pcm_mulaw";
       } else if (encoding == C.ENCODING_PCM_A_LAW) {
         return "pcm_alaw";
       } else {
         return null;
       }
     default:
       return null;
   }
 }
 
Example 15
Source File: WavHeaderReader.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Peeks and returns a {@code WavHeader}.
 *
 * @param input Input stream to peek the WAV header from.
 * @throws ParserException If the input file is an incorrect RIFF WAV.
 * @throws IOException If peeking from the input fails.
 * @throws InterruptedException If interrupted while peeking from input.
 * @return A new {@code WavHeader} peeked from {@code input}, or null if the input is not a
 *     supported WAV format.
 */
public static WavHeader peek(ExtractorInput input) throws IOException, InterruptedException {
  Assertions.checkNotNull(input);

  // Allocate a scratch buffer large enough to store the format chunk.
  ParsableByteArray scratch = new ParsableByteArray(16);

  // Attempt to read the RIFF chunk.
  ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
  if (chunkHeader.id != Util.getIntegerCodeForString("RIFF")) {
    return null;
  }

  input.peekFully(scratch.data, 0, 4);
  scratch.setPosition(0);
  int riffFormat = scratch.readInt();
  if (riffFormat != Util.getIntegerCodeForString("WAVE")) {
    Log.e(TAG, "Unsupported RIFF format: " + riffFormat);
    return null;
  }

  // Skip chunks until we find the format chunk.
  chunkHeader = ChunkHeader.peek(input, scratch);
  while (chunkHeader.id != Util.getIntegerCodeForString("fmt ")) {
    input.advancePeekPosition((int) chunkHeader.size);
    chunkHeader = ChunkHeader.peek(input, scratch);
  }

  Assertions.checkState(chunkHeader.size >= 16);
  input.peekFully(scratch.data, 0, 16);
  scratch.setPosition(0);
  int type = scratch.readLittleEndianUnsignedShort();
  int numChannels = scratch.readLittleEndianUnsignedShort();
  int sampleRateHz = scratch.readLittleEndianUnsignedIntToInt();
  int averageBytesPerSecond = scratch.readLittleEndianUnsignedIntToInt();
  int blockAlignment = scratch.readLittleEndianUnsignedShort();
  int bitsPerSample = scratch.readLittleEndianUnsignedShort();

  int expectedBlockAlignment = numChannels * bitsPerSample / 8;
  if (blockAlignment != expectedBlockAlignment) {
    throw new ParserException("Expected block alignment: " + expectedBlockAlignment + "; got: "
        + blockAlignment);
  }

  @C.PcmEncoding int encoding;
  switch (type) {
    case TYPE_PCM:
    case TYPE_WAVE_FORMAT_EXTENSIBLE:
      encoding = Util.getPcmEncoding(bitsPerSample);
      break;
    case TYPE_FLOAT:
      encoding = bitsPerSample == 32 ? C.ENCODING_PCM_FLOAT : C.ENCODING_INVALID;
      break;
    case TYPE_A_LAW:
      encoding = C.ENCODING_PCM_A_LAW;
      break;
    case TYPE_MU_LAW:
      encoding = C.ENCODING_PCM_MU_LAW;
      break;
    default:
      Log.e(TAG, "Unsupported WAV format type: " + type);
      return null;
  }

  if (encoding == C.ENCODING_INVALID) {
    Log.e(TAG, "Unsupported WAV bit depth " + bitsPerSample + " for type " + type);
    return null;
  }

  // If present, skip extensionSize, validBitsPerSample, channelMask, subFormatGuid, ...
  input.advancePeekPosition((int) chunkHeader.size - 16);

  return new WavHeader(numChannels, sampleRateHz, averageBytesPerSecond, blockAlignment,
      bitsPerSample, encoding);
}
 
Example 16
Source File: ResamplingAudioProcessor.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@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();
}
 
Example 17
Source File: FfmpegLibrary.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the name of the FFmpeg decoder that could be used to decode the format, or {@code null}
 * if it's unsupported.
 */
/* package */ static @Nullable String getCodecName(String mimeType, @C.PcmEncoding int encoding) {
  switch (mimeType) {
    case MimeTypes.AUDIO_AAC:
      return "aac";
    case MimeTypes.AUDIO_MPEG:
    case MimeTypes.AUDIO_MPEG_L1:
    case MimeTypes.AUDIO_MPEG_L2:
      return "mp3";
    case MimeTypes.AUDIO_AC3:
      return "ac3";
    case MimeTypes.AUDIO_E_AC3:
    case MimeTypes.AUDIO_E_AC3_JOC:
      return "eac3";
    case MimeTypes.AUDIO_TRUEHD:
      return "truehd";
    case MimeTypes.AUDIO_DTS:
    case MimeTypes.AUDIO_DTS_HD:
      return "dca";
    case MimeTypes.AUDIO_VORBIS:
      return "vorbis";
    case MimeTypes.AUDIO_OPUS:
      return "opus";
    case MimeTypes.AUDIO_AMR_NB:
      return "amrnb";
    case MimeTypes.AUDIO_AMR_WB:
      return "amrwb";
    case MimeTypes.AUDIO_FLAC:
      return "flac";
    case MimeTypes.AUDIO_ALAC:
      return "alac";
    case MimeTypes.AUDIO_RAW:
      if (encoding == C.ENCODING_PCM_MU_LAW) {
        return "pcm_mulaw";
      } else if (encoding == C.ENCODING_PCM_A_LAW) {
        return "pcm_alaw";
      } else {
        return null;
      }
    default:
      return null;
  }
}
 
Example 18
Source File: FfmpegLibrary.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the name of the FFmpeg decoder that could be used to decode the format, or {@code null}
 * if it's unsupported.
 */
/* package */ static @Nullable String getCodecName(String mimeType, @C.PcmEncoding int encoding) {
  switch (mimeType) {
    case MimeTypes.AUDIO_AAC:
      return "aac";
    case MimeTypes.AUDIO_MPEG:
    case MimeTypes.AUDIO_MPEG_L1:
    case MimeTypes.AUDIO_MPEG_L2:
      return "mp3";
    case MimeTypes.AUDIO_AC3:
      return "ac3";
    case MimeTypes.AUDIO_E_AC3:
    case MimeTypes.AUDIO_E_AC3_JOC:
      return "eac3";
    case MimeTypes.AUDIO_TRUEHD:
      return "truehd";
    case MimeTypes.AUDIO_DTS:
    case MimeTypes.AUDIO_DTS_HD:
      return "dca";
    case MimeTypes.AUDIO_VORBIS:
      return "vorbis";
    case MimeTypes.AUDIO_OPUS:
      return "opus";
    case MimeTypes.AUDIO_AMR_NB:
      return "amrnb";
    case MimeTypes.AUDIO_AMR_WB:
      return "amrwb";
    case MimeTypes.AUDIO_FLAC:
      return "flac";
    case MimeTypes.AUDIO_ALAC:
      return "alac";
    case MimeTypes.AUDIO_RAW:
      if (encoding == C.ENCODING_PCM_MU_LAW) {
        return "pcm_mulaw";
      } else if (encoding == C.ENCODING_PCM_A_LAW) {
        return "pcm_alaw";
      } else {
        return null;
      }
    default:
      return null;
  }
}
 
Example 19
Source File: ResamplingAudioProcessor.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@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 (inputAudioFormat.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 (inputAudioFormat.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();
}
 
Example 20
Source File: ResamplingAudioProcessor.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@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();
}