当前位置: 首页>>代码示例>>Java>>正文


Java AudioFormat.CHANNEL_OUT_5POINT1属性代码示例

本文整理汇总了Java中android.media.AudioFormat.CHANNEL_OUT_5POINT1属性的典型用法代码示例。如果您正苦于以下问题:Java AudioFormat.CHANNEL_OUT_5POINT1属性的具体用法?Java AudioFormat.CHANNEL_OUT_5POINT1怎么用?Java AudioFormat.CHANNEL_OUT_5POINT1使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.media.AudioFormat的用法示例。


在下文中一共展示了AudioFormat.CHANNEL_OUT_5POINT1属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reconfigure

/**
 * Reconfigures the audio track to play back media in {@code format}.
 *
 * @param format Specifies the channel count and sample rate to play back.
 * @param specifiedBufferSize A specific size for the playback buffer in bytes, or 0 to use a
 *          size inferred from the format.
 */
public void reconfigure(MediaFormat format, int specifiedBufferSize) {
  int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
  int channelConfig;
  switch (channelCount) {
    case 1:
      channelConfig = AudioFormat.CHANNEL_OUT_MONO;
      break;
    case 2:
      channelConfig = AudioFormat.CHANNEL_OUT_STEREO;
      break;
    case 6:
      channelConfig = AudioFormat.CHANNEL_OUT_5POINT1;
      break;
    case 8:
      channelConfig = AudioFormat.CHANNEL_OUT_7POINT1;
      break;
    default:
      throw new IllegalArgumentException("Unsupported channel count: " + channelCount);
  }

  int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
  String mimeType = format.getString(MediaFormat.KEY_MIME);

  // TODO: Does channelConfig determine channelCount?
  int encoding = MimeTypes.getEncodingForMimeType(mimeType);
  boolean isAc3 = encoding == C.ENCODING_AC3 || encoding == C.ENCODING_E_AC3;
  if (isInitialized() && this.sampleRate == sampleRate && this.channelConfig == channelConfig
      && !this.isAc3 && !isAc3) {
    // We already have an existing audio track with the correct sample rate and channel config.
    return;
  }

  reset();

  this.encoding = encoding;
  this.sampleRate = sampleRate;
  this.channelConfig = channelConfig;
  this.isAc3 = isAc3;
  ac3Bitrate = UNKNOWN_AC3_BITRATE; // Calculated on receiving the first buffer if isAc3 is true.
  frameSize = 2 * channelCount; // 2 bytes per 16 bit sample * number of channels.
  minBufferSize = android.media.AudioTrack.getMinBufferSize(sampleRate, channelConfig, encoding);
  Assertions.checkState(minBufferSize != android.media.AudioTrack.ERROR_BAD_VALUE);

  if (specifiedBufferSize != 0) {
    bufferSize = specifiedBufferSize;
  } else {
    int multipliedBufferSize = minBufferSize * BUFFER_MULTIPLICATION_FACTOR;
    int minAppBufferSize = (int) durationUsToFrames(MIN_BUFFER_DURATION_US) * frameSize;
    int maxAppBufferSize = (int) Math.max(minBufferSize,
        durationUsToFrames(MAX_BUFFER_DURATION_US) * frameSize);
    bufferSize = multipliedBufferSize < minAppBufferSize
        ? minAppBufferSize
        : multipliedBufferSize > maxAppBufferSize
            ? maxAppBufferSize
            : multipliedBufferSize;
  }
}
 
开发者ID:XueyanLiu,项目名称:miku,代码行数:64,代码来源:AudioTrack.java


注:本文中的android.media.AudioFormat.CHANNEL_OUT_5POINT1属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。