Support 32-bit WAV.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=122157513
This commit is contained in:
parent
7301b53829
commit
9bfe62a5a5
@ -79,6 +79,11 @@ public final class C {
|
||||
*/
|
||||
public static final int ENCODING_PCM_24BIT = 0x80000000;
|
||||
|
||||
/**
|
||||
* PCM encoding with 32 bits per sample.
|
||||
*/
|
||||
public static final int ENCODING_PCM_32BIT = 0x40000000;
|
||||
|
||||
/**
|
||||
* @see AudioFormat#ENCODING_AC3
|
||||
*/
|
||||
|
@ -134,8 +134,9 @@ public final class Format {
|
||||
public final int sampleRate;
|
||||
/**
|
||||
* The encoding for PCM audio streams. If {@link #sampleMimeType} is {@link MimeTypes#AUDIO_RAW}
|
||||
* then one of {@link C#ENCODING_PCM_8BIT}, {@link C#ENCODING_PCM_16BIT} and
|
||||
* {@link C#ENCODING_PCM_24BIT}. Set to {@link #NO_VALUE} for other media types.
|
||||
* then one of {@link C#ENCODING_PCM_8BIT}, {@link C#ENCODING_PCM_16BIT},
|
||||
* {@link C#ENCODING_PCM_24BIT} and {@link C#ENCODING_PCM_32BIT}. Set to {@link #NO_VALUE} for
|
||||
* other media types.
|
||||
*/
|
||||
public final int pcmEncoding;
|
||||
/**
|
||||
|
@ -341,7 +341,8 @@ public final class AudioTrack {
|
||||
* @param channelCount The number of channels.
|
||||
* @param sampleRate The sample rate in Hz.
|
||||
* @param pcmEncoding For PCM formats, the encoding used. One of {@link C#ENCODING_PCM_16BIT},
|
||||
* {@link C#ENCODING_PCM_16BIT} and {@link C#ENCODING_PCM_24BIT}.
|
||||
* {@link C#ENCODING_PCM_16BIT}, {@link C#ENCODING_PCM_24BIT} and
|
||||
* {@link C#ENCODING_PCM_32BIT}.
|
||||
*/
|
||||
public void configure(String mimeType, int channelCount, int sampleRate, int pcmEncoding) {
|
||||
configure(mimeType, channelCount, sampleRate, pcmEncoding, 0);
|
||||
@ -354,7 +355,8 @@ public final class AudioTrack {
|
||||
* @param channelCount The number of channels.
|
||||
* @param sampleRate The sample rate in Hz.
|
||||
* @param pcmEncoding For PCM formats, the encoding used. One of {@link C#ENCODING_PCM_16BIT},
|
||||
* {@link C#ENCODING_PCM_16BIT} and {@link C#ENCODING_PCM_24BIT}.
|
||||
* {@link C#ENCODING_PCM_16BIT}, {@link C#ENCODING_PCM_24BIT} and
|
||||
* {@link C#ENCODING_PCM_32BIT}.
|
||||
* @param specifiedBufferSize A specific size for the playback buffer in bytes, or 0 to infer a
|
||||
* suitable buffer size automatically.
|
||||
*/
|
||||
@ -395,7 +397,7 @@ public final class AudioTrack {
|
||||
if (passthrough) {
|
||||
sourceEncoding = getEncodingForMimeType(mimeType);
|
||||
} else if (pcmEncoding == C.ENCODING_PCM_8BIT || pcmEncoding == C.ENCODING_PCM_16BIT
|
||||
|| pcmEncoding == C.ENCODING_PCM_24BIT) {
|
||||
|| pcmEncoding == C.ENCODING_PCM_24BIT || pcmEncoding == C.ENCODING_PCM_32BIT) {
|
||||
sourceEncoding = pcmEncoding;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported PCM encoding: " + pcmEncoding);
|
||||
@ -711,7 +713,6 @@ public final class AudioTrack {
|
||||
audioTrackUtil.setPlaybackParameters(playbackParams);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the playback volume.
|
||||
*/
|
||||
@ -991,6 +992,9 @@ public final class AudioTrack {
|
||||
case C.ENCODING_PCM_24BIT:
|
||||
resampledSize = (size / 3) * 2;
|
||||
break;
|
||||
case C.ENCODING_PCM_32BIT:
|
||||
resampledSize = size / 2;
|
||||
break;
|
||||
default:
|
||||
// Never happens.
|
||||
throw new IllegalStateException();
|
||||
@ -1019,6 +1023,13 @@ public final class AudioTrack {
|
||||
resampledBuffer.put(buffer.get(i + 2));
|
||||
}
|
||||
break;
|
||||
case C.ENCODING_PCM_32BIT:
|
||||
// 32->16 bit resampling. Drop the two least significant bytes.
|
||||
for (int i = offset; i < limit; i += 4) {
|
||||
resampledBuffer.put(buffer.get(i + 2));
|
||||
resampledBuffer.put(buffer.get(i + 3));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Never happens.
|
||||
throw new IllegalStateException();
|
||||
|
@ -780,10 +780,11 @@ public final class Util {
|
||||
/**
|
||||
* Converts a sample bit depth to a corresponding PCM encoding constant.
|
||||
*
|
||||
* @param bitDepth The bit depth. Supported values are 8, 16 and 24.
|
||||
* @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} and {@link C#ENCODING_PCM_24BIT}. If the bit depth is
|
||||
* unsupported then {@link C#ENCODING_INVALID} is returned.
|
||||
* {@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.
|
||||
*/
|
||||
public static int getPcmEncoding(int bitDepth) {
|
||||
switch (bitDepth) {
|
||||
@ -793,6 +794,8 @@ public final class Util {
|
||||
return C.ENCODING_PCM_16BIT;
|
||||
case 24:
|
||||
return C.ENCODING_PCM_24BIT;
|
||||
case 32:
|
||||
return C.ENCODING_PCM_32BIT;
|
||||
default:
|
||||
return C.ENCODING_INVALID;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user