Support 32-bit WAV.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=122157513
This commit is contained in:
olly 2016-05-12 08:02:27 -07:00 committed by Oliver Woodman
parent 7301b53829
commit 9bfe62a5a5
4 changed files with 29 additions and 9 deletions

View File

@ -79,6 +79,11 @@ public final class C {
*/ */
public static final int ENCODING_PCM_24BIT = 0x80000000; 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 * @see AudioFormat#ENCODING_AC3
*/ */

View File

@ -134,8 +134,9 @@ public final class Format {
public final int sampleRate; public final int sampleRate;
/** /**
* The encoding for PCM audio streams. If {@link #sampleMimeType} is {@link MimeTypes#AUDIO_RAW} * 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 * then one of {@link C#ENCODING_PCM_8BIT}, {@link C#ENCODING_PCM_16BIT},
* {@link C#ENCODING_PCM_24BIT}. Set to {@link #NO_VALUE} for other media types. * {@link C#ENCODING_PCM_24BIT} and {@link C#ENCODING_PCM_32BIT}. Set to {@link #NO_VALUE} for
* other media types.
*/ */
public final int pcmEncoding; public final int pcmEncoding;
/** /**

View File

@ -341,7 +341,8 @@ public final class AudioTrack {
* @param channelCount The number of channels. * @param channelCount The number of channels.
* @param sampleRate The sample rate in Hz. * @param sampleRate The sample rate in Hz.
* @param pcmEncoding For PCM formats, the encoding used. One of {@link C#ENCODING_PCM_16BIT}, * @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) { public void configure(String mimeType, int channelCount, int sampleRate, int pcmEncoding) {
configure(mimeType, channelCount, sampleRate, pcmEncoding, 0); configure(mimeType, channelCount, sampleRate, pcmEncoding, 0);
@ -354,7 +355,8 @@ public final class AudioTrack {
* @param channelCount The number of channels. * @param channelCount The number of channels.
* @param sampleRate The sample rate in Hz. * @param sampleRate The sample rate in Hz.
* @param pcmEncoding For PCM formats, the encoding used. One of {@link C#ENCODING_PCM_16BIT}, * @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 * @param specifiedBufferSize A specific size for the playback buffer in bytes, or 0 to infer a
* suitable buffer size automatically. * suitable buffer size automatically.
*/ */
@ -395,7 +397,7 @@ public final class AudioTrack {
if (passthrough) { if (passthrough) {
sourceEncoding = getEncodingForMimeType(mimeType); sourceEncoding = getEncodingForMimeType(mimeType);
} else if (pcmEncoding == C.ENCODING_PCM_8BIT || pcmEncoding == C.ENCODING_PCM_16BIT } 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; sourceEncoding = pcmEncoding;
} else { } else {
throw new IllegalArgumentException("Unsupported PCM encoding: " + pcmEncoding); throw new IllegalArgumentException("Unsupported PCM encoding: " + pcmEncoding);
@ -711,7 +713,6 @@ public final class AudioTrack {
audioTrackUtil.setPlaybackParameters(playbackParams); audioTrackUtil.setPlaybackParameters(playbackParams);
} }
/** /**
* Sets the playback volume. * Sets the playback volume.
*/ */
@ -991,6 +992,9 @@ public final class AudioTrack {
case C.ENCODING_PCM_24BIT: case C.ENCODING_PCM_24BIT:
resampledSize = (size / 3) * 2; resampledSize = (size / 3) * 2;
break; break;
case C.ENCODING_PCM_32BIT:
resampledSize = size / 2;
break;
default: default:
// Never happens. // Never happens.
throw new IllegalStateException(); throw new IllegalStateException();
@ -1019,6 +1023,13 @@ public final class AudioTrack {
resampledBuffer.put(buffer.get(i + 2)); resampledBuffer.put(buffer.get(i + 2));
} }
break; 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: default:
// Never happens. // Never happens.
throw new IllegalStateException(); throw new IllegalStateException();

View File

@ -780,10 +780,11 @@ public final class Util {
/** /**
* Converts a sample bit depth to a corresponding PCM encoding constant. * 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}, * @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 * {@link C#ENCODING_PCM_16BIT}, {@link C#ENCODING_PCM_24BIT} and
* unsupported then {@link C#ENCODING_INVALID} is returned. * {@link C#ENCODING_PCM_32BIT}. If the bit depth is unsupported then
* {@link C#ENCODING_INVALID} is returned.
*/ */
public static int getPcmEncoding(int bitDepth) { public static int getPcmEncoding(int bitDepth) {
switch (bitDepth) { switch (bitDepth) {
@ -793,6 +794,8 @@ public final class Util {
return C.ENCODING_PCM_16BIT; return C.ENCODING_PCM_16BIT;
case 24: case 24:
return C.ENCODING_PCM_24BIT; return C.ENCODING_PCM_24BIT;
case 32:
return C.ENCODING_PCM_32BIT;
default: default:
return C.ENCODING_INVALID; return C.ENCODING_INVALID;
} }