Explicitly check that AudioGraph input is PCM 16
AudioGraph implicitly assumes that input will be PCM 16 bit, and not float. Make the check explicit. PiperOrigin-RevId: 616149131
This commit is contained in:
parent
b9843af6a0
commit
415d779c62
@ -57,7 +57,9 @@ import java.util.Objects;
|
|||||||
|
|
||||||
/** Returns whether an {@link AudioFormat} is valid as an input format. */
|
/** Returns whether an {@link AudioFormat} is valid as an input format. */
|
||||||
public static boolean isInputAudioFormatValid(AudioFormat format) {
|
public static boolean isInputAudioFormatValid(AudioFormat format) {
|
||||||
if (format.encoding == Format.NO_VALUE) {
|
// AudioGraphInput assumes PCM_16BIT -- see, for example, the automatic format conversions
|
||||||
|
// in AudioGraphInput.configureProcessing.
|
||||||
|
if (format.encoding != C.ENCODING_PCM_16BIT) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (format.sampleRate == Format.NO_VALUE) {
|
if (format.sampleRate == Format.NO_VALUE) {
|
||||||
|
@ -48,6 +48,15 @@ public class AudioGraphTest {
|
|||||||
private static final AudioFormat SURROUND_50000 =
|
private static final AudioFormat SURROUND_50000 =
|
||||||
new AudioFormat(/* sampleRate= */ 50_000, /* channelCount= */ 6, C.ENCODING_PCM_16BIT);
|
new AudioFormat(/* sampleRate= */ 50_000, /* channelCount= */ 6, C.ENCODING_PCM_16BIT);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void floatPcmFormat_isNotValidInputFormat() {
|
||||||
|
assertThat(
|
||||||
|
AudioGraph.isInputAudioFormatValid(
|
||||||
|
new AudioFormat(
|
||||||
|
/* sampleRate= */ 44_100, /* channelCount= */ 1, C.ENCODING_PCM_FLOAT)))
|
||||||
|
.isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void silentItem_outputsCorrectAmountOfBytes() throws Exception {
|
public void silentItem_outputsCorrectAmountOfBytes() throws Exception {
|
||||||
AudioGraph audioGraph = new AudioGraph(new DefaultAudioMixer.Factory());
|
AudioGraph audioGraph = new AudioGraph(new DefaultAudioMixer.Factory());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user