Commit 6ea79c8a by andrewlewis Committed by Oliver Woodman

Fix usage of 'samples' vs 'frames' for gapless

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191704629
parent e3eddc4d
...@@ -145,12 +145,12 @@ public final class Format implements Parcelable { ...@@ -145,12 +145,12 @@ public final class Format implements Parcelable {
@C.PcmEncoding @C.PcmEncoding
public final int pcmEncoding; public final int pcmEncoding;
/** /**
* The number of samples to trim from the start of the decoded audio stream, or 0 if not * The number of frames to trim from the start of the decoded audio stream, or 0 if not
* applicable. * applicable.
*/ */
public final int encoderDelay; public final int encoderDelay;
/** /**
* The number of samples to trim from the end of the decoded audio stream, or 0 if not applicable. * The number of frames to trim from the end of the decoded audio stream, or 0 if not applicable.
*/ */
public final int encoderPadding; public final int encoderPadding;
......
...@@ -192,17 +192,23 @@ public interface AudioSink { ...@@ -192,17 +192,23 @@ public interface AudioSink {
* @param outputChannels A mapping from input to output channels that is applied to this sink's * @param outputChannels A mapping from input to output channels that is applied to this sink's
* input as a preprocessing step, if handling PCM input. Specify {@code null} to leave the * input as a preprocessing step, if handling PCM input. Specify {@code null} to leave the
* input unchanged. Otherwise, the element at index {@code i} specifies index of the input * input unchanged. Otherwise, the element at index {@code i} specifies index of the input
* channel to map to output channel {@code i} when preprocessing input buffers. After the * channel to map to output channel {@code i} when preprocessing input buffers. After the map
* map is applied the audio data will have {@code outputChannels.length} channels. * is applied the audio data will have {@code outputChannels.length} channels.
* @param trimStartSamples The number of audio samples to trim from the start of data written to * @param trimStartFrames The number of audio frames to trim from the start of data written to the
* the sink after this call. * sink after this call.
* @param trimEndSamples The number of audio samples to trim from data written to the sink * @param trimEndFrames The number of audio frames to trim from data written to the sink
* immediately preceding the next call to {@link #reset()} or this method. * immediately preceding the next call to {@link #reset()} or this method.
* @throws ConfigurationException If an error occurs configuring the sink. * @throws ConfigurationException If an error occurs configuring the sink.
*/ */
void configure(@C.Encoding int inputEncoding, int inputChannelCount, int inputSampleRate, void configure(
int specifiedBufferSize, @Nullable int[] outputChannels, int trimStartSamples, @C.Encoding int inputEncoding,
int trimEndSamples) throws ConfigurationException; int inputChannelCount,
int inputSampleRate,
int specifiedBufferSize,
@Nullable int[] outputChannels,
int trimStartFrames,
int trimEndFrames)
throws ConfigurationException;
/** /**
* Starts or resumes consuming audio if initialized. * Starts or resumes consuming audio if initialized.
......
...@@ -278,9 +278,15 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -278,9 +278,15 @@ public final class DefaultAudioSink implements AudioSink {
} }
@Override @Override
public void configure(@C.Encoding int inputEncoding, int inputChannelCount, int inputSampleRate, public void configure(
int specifiedBufferSize, @Nullable int[] outputChannels, int trimStartSamples, @C.Encoding int inputEncoding,
int trimEndSamples) throws ConfigurationException { int inputChannelCount,
int inputSampleRate,
int specifiedBufferSize,
@Nullable int[] outputChannels,
int trimStartFrames,
int trimEndFrames)
throws ConfigurationException {
boolean flush = false; boolean flush = false;
this.inputSampleRate = inputSampleRate; this.inputSampleRate = inputSampleRate;
int channelCount = inputChannelCount; int channelCount = inputChannelCount;
...@@ -297,7 +303,7 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -297,7 +303,7 @@ public final class DefaultAudioSink implements AudioSink {
boolean processingEnabled = isInputPcm && inputEncoding != C.ENCODING_PCM_FLOAT; boolean processingEnabled = isInputPcm && inputEncoding != C.ENCODING_PCM_FLOAT;
canApplyPlaybackParameters = processingEnabled && !shouldConvertHighResIntPcmToFloat; canApplyPlaybackParameters = processingEnabled && !shouldConvertHighResIntPcmToFloat;
if (processingEnabled) { if (processingEnabled) {
trimmingAudioProcessor.setTrimSampleCount(trimStartSamples, trimEndSamples); trimmingAudioProcessor.setTrimFrameCount(trimStartFrames, trimEndFrames);
channelMappingAudioProcessor.setChannelMap(outputChannels); channelMappingAudioProcessor.setChannelMap(outputChannels);
for (AudioProcessor audioProcessor : getAvailableAudioProcessors()) { for (AudioProcessor audioProcessor : getAvailableAudioProcessors()) {
try { try {
......
...@@ -26,8 +26,8 @@ import java.nio.ByteOrder; ...@@ -26,8 +26,8 @@ import java.nio.ByteOrder;
/* package */ final class TrimmingAudioProcessor implements AudioProcessor { /* package */ final class TrimmingAudioProcessor implements AudioProcessor {
private boolean isActive; private boolean isActive;
private int trimStartSamples; private int trimStartFrames;
private int trimEndSamples; private int trimEndFrames;
private int channelCount; private int channelCount;
private int sampleRateHz; private int sampleRateHz;
...@@ -48,17 +48,17 @@ import java.nio.ByteOrder; ...@@ -48,17 +48,17 @@ import java.nio.ByteOrder;
} }
/** /**
* Sets the number of audio samples to trim from the start and end of audio passed to this * Sets the number of audio frames to trim from the start and end of audio passed to this
* processor. After calling this method, call {@link #configure(int, int, int)} to apply the new * processor. After calling this method, call {@link #configure(int, int, int)} to apply the new
* trimming sample counts. * trimming frame counts.
* *
* @param trimStartSamples The number of audio samples to trim from the start of audio. * @param trimStartFrames The number of audio frames to trim from the start of audio.
* @param trimEndSamples The number of audio samples to trim from the end of audio. * @param trimEndFrames The number of audio frames to trim from the end of audio.
* @see AudioSink#configure(int, int, int, int, int[], int, int) * @see AudioSink#configure(int, int, int, int, int[], int, int)
*/ */
public void setTrimSampleCount(int trimStartSamples, int trimEndSamples) { public void setTrimFrameCount(int trimStartFrames, int trimEndFrames) {
this.trimStartSamples = trimStartSamples; this.trimStartFrames = trimStartFrames;
this.trimEndSamples = trimEndSamples; this.trimEndFrames = trimEndFrames;
} }
@Override @Override
...@@ -69,11 +69,11 @@ import java.nio.ByteOrder; ...@@ -69,11 +69,11 @@ import java.nio.ByteOrder;
} }
this.channelCount = channelCount; this.channelCount = channelCount;
this.sampleRateHz = sampleRateHz; this.sampleRateHz = sampleRateHz;
endBuffer = new byte[trimEndSamples * channelCount * 2]; endBuffer = new byte[trimEndFrames * channelCount * 2];
endBufferSize = 0; endBufferSize = 0;
pendingTrimStartBytes = trimStartSamples * channelCount * 2; pendingTrimStartBytes = trimStartFrames * channelCount * 2;
boolean wasActive = isActive; boolean wasActive = isActive;
isActive = trimStartSamples != 0 || trimEndSamples != 0; isActive = trimStartFrames != 0 || trimEndFrames != 0;
return wasActive != isActive; return wasActive != isActive;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment