當前位置: 首頁>>代碼示例>>Java>>正文


Java AudioFormat.ENCODING_PCM_FLOAT屬性代碼示例

本文整理匯總了Java中android.media.AudioFormat.ENCODING_PCM_FLOAT屬性的典型用法代碼示例。如果您正苦於以下問題:Java AudioFormat.ENCODING_PCM_FLOAT屬性的具體用法?Java AudioFormat.ENCODING_PCM_FLOAT怎麽用?Java AudioFormat.ENCODING_PCM_FLOAT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.media.AudioFormat的用法示例。


在下文中一共展示了AudioFormat.ENCODING_PCM_FLOAT屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createAudioTrack

public AudioTrack createAudioTrack(int frameRate) {
    int minBufferSizeBytes = AudioTrack.getMinBufferSize(frameRate,
            AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_FLOAT);
    Log.i(TAG, "AudioTrack.minBufferSize = " + minBufferSizeBytes
            + " bytes = " + (minBufferSizeBytes / BYTES_PER_FRAME)
            + " frames");
    int bufferSize = 8 * minBufferSizeBytes / 8;
    int outputBufferSizeFrames = bufferSize / BYTES_PER_FRAME;
    Log.i(TAG, "actual bufferSize = " + bufferSize + " bytes = "
            + outputBufferSizeFrames + " frames");

    AudioTrack player = new AudioTrack(AudioManager.STREAM_MUSIC,
            mFrameRate, AudioFormat.CHANNEL_OUT_STEREO,
            AudioFormat.ENCODING_PCM_FLOAT, bufferSize,
            AudioTrack.MODE_STREAM);
    Log.i(TAG, "created AudioTrack");
    return player;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:18,代碼來源:SimpleAudioOutput.java

示例2: audioFormatSampleBytes

public static int audioFormatSampleBytes(int f)
{
    switch (f)
    {
        case AudioFormat.ENCODING_PCM_8BIT:
            return 1;
        case AudioFormat.ENCODING_PCM_16BIT:
        case AudioFormat.ENCODING_DEFAULT:
            return 2;
        case AudioFormat.ENCODING_PCM_FLOAT:
            return 4;
        case AudioFormat.ENCODING_INVALID:
        default:
            return 0;
    }
}
 
開發者ID:hcmlab,項目名稱:ssj,代碼行數:16,代碼來源:Microphone.java

示例3: audioFormatSampleType

public static Cons.Type audioFormatSampleType(int f)
{
    switch (f)
    {
        case AudioFormat.ENCODING_PCM_8BIT:
            return Cons.Type.CHAR;
        case AudioFormat.ENCODING_PCM_16BIT:
        case AudioFormat.ENCODING_DEFAULT:
            return Cons.Type.SHORT;
        case AudioFormat.ENCODING_PCM_FLOAT:
            return Cons.Type.FLOAT;
        case AudioFormat.ENCODING_INVALID:
        default:
            return Cons.Type.UNDEF;
    }
}
 
開發者ID:hcmlab,項目名稱:ssj,代碼行數:16,代碼來源:Microphone.java

示例4: writeWavHeader

/**
 * Writes the proper 44-byte RIFF/WAVE header to/for the given stream
 * Two size fields are left empty/null since we do not yet know the final stream size
 *
 * @param out The stream to write the header to
 * @param channelMask An AudioFormat.CHANNEL_* mask
 * @param sampleRate The sample rate in hertz
 * @param encoding An AudioFormat.ENCODING_PCM_* value
 * @throws IOException
 */
private void writeWavHeader(OutputStream out, int channelMask, int sampleRate, int encoding)
    throws IOException {
  short channels;
  switch (channelMask) {
    case AudioFormat.CHANNEL_IN_MONO:
      channels = 1;
      break;
    case AudioFormat.CHANNEL_IN_STEREO:
      channels = 2;
      break;
    default:
      throw new IllegalArgumentException("Unacceptable channel mask");
  }

  short bitDepth;
  switch (encoding) {
    case AudioFormat.ENCODING_PCM_8BIT:
      bitDepth = 8;
      break;
    case AudioFormat.ENCODING_PCM_16BIT:
      bitDepth = 16;
      break;
    case AudioFormat.ENCODING_PCM_FLOAT:
      bitDepth = 32;
      break;
    default:
      throw new IllegalArgumentException("Unacceptable encoding");
  }

  writeWavHeader(out, channels, sampleRate, bitDepth);
}
 
開發者ID:Arjun-sna,項目名稱:Android-AudioRecorder-App,代碼行數:41,代碼來源:AudioSaveHelper.java


注:本文中的android.media.AudioFormat.ENCODING_PCM_FLOAT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。